User Tools

Site Tools


dev:fypp

This is an old revision of the document!


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 metaprogramming. For simple 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). CP2K's own template engine is deprecated and templates should be implemented using Fypp.

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 the Fypp-preprocessed files can usually be ignored. Only for debugging Fypp directives, it is useful to consider the preprocessed Fortran code. After compiling CP2K, all Fypp-preprocessed files are stored in cp2k/obj with .F90 extension. In order to find a specific line in a preprocessed file, consider the line numbering directives.

dev/fypp.1487853624.txt.gz · Last modified: 2020/08/21 10:14 (external edit)