A common programming practice is to pass files through the C preprocessor (cpp). cpp can include or omit lines from the output file based on user-specified conditions ("conditional compilation"). It can also perform string substitution ("macro expansion").
XL Fortran can use cpp to preprocess a file before compiling it.
To call cpp for a particular file, use a file suffix of .F, .F77, .F90, .F95, .F03, or .F08. Each .F* file filename.F* is preprocessed into an intermediate file. You can save the intermediate file by specifying the -d compiler option; otherwise, the file is deleted. If you specify the -d option, the intermediate file name is Ffilename.f*. Otherwise, the intermediate file name is /tmpdir/F8xxxxxx, where x is an alphanumeric character and tmpdir is the contents of the TMPDIR environment variable or, if you have not specified a value for TMPDIR, /tmp. If you only want to preprocess and do not want to produce object or executable files, specify the -qnoobject option also.
When XL Fortran uses cpp for a file, the preprocessor will emit #line directives unless you also specify the -d option. The #line directive associates code that is created by cpp or any other Fortran source code generator with input code that you create. The preprocessor may cause lines of code to be inserted or deleted. Therefore, the #line directives that it emits can be useful in error reporting and debugging, because they identify the source statements found in the preprocessed code by listing the line numbers that were used in the original source.
program par_mat_mul
implicit none
integer(kind=8) ::i,j,nthreads
integer(kind=8),parameter ::N=60
integer(kind=8),dimension(N,N) ::Ai,Bi,Ci
integer(kind=8) ::Sumi
#ifdef _OPENMP
integer omp_get_num_threads
#endif
common/data/ Ai,Bi,Ci
!$OMP threadprivate (/data/)
!$omp parallel
forall(i=1:N,j=1:N) Ai(i,j) = (i-N/2)**2+(j+N/2)
forall(i=1:N,j=1:N) Bi(i,j) = 3-((i/2)+(j-N/2)**2)
!$omp master
#ifdef _OPENMP
nthreads=omp_get_num_threads()
#else
nthreads=8
#endif
!$omp end master
!$omp end parallel
!$OMP parallel default(private),copyin(Ai,Bi),shared(nthreads)
!$omp do
do i=1,nthreads
call imat_mul(Sumi)
enddo
!$omp end do
!$omp end parallel
end
See Conditional compilation in the Language Elements section for
more information on conditional compilation.To customize cpp preprocessing, the configuration file accepts the attributes cpp, cppsuffix, and cppoptions.
The letter F denotes the C preprocessor with the -t and -W options.