User Tools

Site Tools


dev:fypp

Fortran metaprogramming using Fypp

Fypp (official repository) is a Fortran preprocessor based on Python expressions. Fypp directives can be used in all CP2K Fortran source files. For simple metaprogramming tasks (such as conditional compilation and include statements), the default Fortran preprocessor (cpp or fpp) can still be used. However cpp is very limited and if more advanced metaprogramming capability is needed (loop unrolling, templates, code generation), usage of Fypp is highly encouraged. In particular code generators should be written using Fypp instead of custom scripts (if feasible).

For getting started with Fypp, read the official documentation.

Debugging Fypp directives

Compiler and runtime messages always refer to the original (not preprocessed) .F file such that Fypp-preprocessed files can usually be ignored. Only for debugging Fypp directives, it is sometimes necessary to consider preprocessed Fortran sources. After compiling CP2K, all Fypp-preprocessed sources are stored in cp2k/obj with .F90 extension. In order to find a specific line in a preprocessed file, consider the line numbering markers.

By default, CP2K invokes Fypp with -n option. To invoke Fypp with other options, put FYPPFLAGS=<options> in your arch file. To learn about all Fypp options, invoke cp2k/tools/build_utils/fypp -h.

dev/fypp.txt · Last modified: 2020/08/21 10:15 by 127.0.0.1