If you are willing to use pre-processed FORTRAN source file, you can always rely on the macro _OPENMP
to be defined when using OpenMP. The simplest example is:
program pippo
#ifdef _OPENMP
print *, "OpenMP program"
#else
print *, "Non-OpenMP program"
#endif
end program pippo
Compiled with:
gfortran -fopenmp main.F90
the program will give the following output:
OpenMP program
If you are unwilling to use pre-processed source files, then you can set a variable using FORTRAN conditional compilation sentinel:
program pippo
implicit none
logical :: use_openmp = .false.
!$ use_openmp = .true.
!$ print *, "OpenMP program"
if( .not. use_openmp) then
print *, "Non-OpenMP program"
end if
end program pippo