stfc / fparser

This project maintains and develops a Fortran parser called fparser2 written purely in Python which supports Fortran 2003 and some Fortran 2008. A legacy parser fparser1 is also available but is not supported. The parsers were originally part of the f2py project by Pearu Peterson.
https://fparser.readthedocs.io
Other
64 stars 29 forks source link

Supporting OpenMP Sentinels #443

Closed hiker closed 7 months ago

hiker commented 8 months ago

Some UM code contains declarations in OpenMP sentinels, e.g.:

!$ USE compute_chunk_size_mod, ONLY: compute_chunk_size  ! Note OpenMP sentinel

Fparser skips these lines as comment lines, and as a result, FAB misses dependencies if compilation is done with OpenMP enabled.

While I have a FAB patch that fixes it (if a comment is found, check if it starts with !$, and then try Use_Stmt.match(...), and that works fine for me), I think it could be useful if fparser could be instructed to handle !$. That should be easier than pre-processing directive (since the string following !$ must be valid Fortran - I believe we could simply pass a flag to the reader to delete the first two characters if they are !$?

If you don't think that this could be useful for fparser, let me know, and I'll get my current FAB workaround merged in.

hiker commented 8 months ago

As discussed in the telco, this is considered useful. It will be implemented using an optional flag to enable this. And it is expected to be handled in the reader - detect the sentinels and remove them. We just need to take care not to remove !$ for real openmp statements. According to the standard, an OpenMP directive may not have a whitespace between !$ and omp, while a sentinel must have a whitespace after !$.