conditional module definition file

conditional module definition file

Hi,

I have a module-definition (.def) file that is used to export the name of the modules and subroutines, FILE_A.def:

EXPORTS

MODULENAMEA_SUBROUTINENAMEA

MODULENAMEB_SUBROUTINENAMEB

etc...

I also have parallel routines that get compiled only if the parrallel option was enabled, so we currently handle this by having another file that  has the same content as FILE_A.def but with the extra parallel subroutines added (and this file is used instead of FILE_A.def). I would like get rid of these duplicate lines between files, so I was wondering if it is possible to include #ifdef *like* conditional statements in the .def file. If not, then can two .def be used instead, say FILE_A.def and FILE_B.def that contains the parallel routines and is included only if the parallel routines are compiled. Or is there a better way in general to do this. Any pointers to documentation or examples would be helpful.

Thanks.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

The Fortran compiler has a Fortran Preprocessor, fpp, which works in a similar manor to the c preprocessor, cpp. It understands #ifdef and other common directives. To run the fpp, use the compiler option /fpp.

For more information see Using the FPP Preprocessor.

Regards,
Annalee
Intel Developer Support

Another alternative, is to use Directive Enhanced Compilation ---i.e., lines that start with !DEC$, for example:

module somemodule
contains
subroutine mysub()
!DEC$ IF DEFINED (RUN_PARALLEL)
!DEC$ ATTRIBUTES DLLEXPORT :: MYSUB
!DEC$ ENDIF
end subroutine
end module

Although the !DEC$ lines can serve the same purpose as the Fortran preprocessor, I'd recommend you to stick to the Fortran preprocessor for the #if blocks, and use the !DEC$ lines only for some specific attributes. For example:

module somemodule
contains
subroutine mysub()
#ifdef RUN_PARALLEL
!DEC$ ATTRIBUTES DLLEXPORT :: MYSUB
#endif
end subroutine
end module

The !$ATTRIBUTES directive is supported by at least four different compilers under Windows, so the issue of portability (at least within the same operating system), is somewhat less of a concern.

Leave a Comment

Please sign in to add a comment. Not a member? Join today