metomi / fab

Flexible build system for scientific software
https://metomi.github.io/fab/
Other
19 stars 11 forks source link

Handling of OMP Sentinels #297

Open hiker opened 3 months ago

hiker commented 3 months ago

Some UM files contains OMP sentinels for use statements, e.g. control/grids/p_to_t_vol.F90:

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

Since fparser does not support this, FAB misses this dependency (and compilation fails). While I have a patch more or less ready to go (https://github.com/hiker/fab/tree/13_omp_sentinels), I have discussed this in our telco, and we agreed that this would be a useful feature for fparser to support, see https://github.com/stfc/fparser/issues/443. So I'll add this support to fparser, and once this has been released, we just need to enable this feature in FAB (it will be disabled by default in order not to break compatibility).

hiker commented 2 months ago

I have just submitted https://github.com/stfc/fparser/pull/444 to get support for omp conditional sentinels into fparser. I have confirmed that fab now detects the dependencies in the original case when setting the fparser flag to handle them:

diff --git a/source/fab/parse/fortran_common.py b/source/fab/parse/fortran_common.py
index 0ed4f3f..8b987d8 100644
--- a/source/fab/parse/fortran_common.py
+++ b/source/fab/parse/fortran_common.py
@@ -142,7 +142,8 @@ class FortranAnalyserBase(ABC):

     def _parse_file(self, fpath):
         """Get a node tree from a fortran file."""
-        reader = FortranFileReader(str(fpath), ignore_comments=False)
+        reader = FortranFileReader(str(fpath), ignore_comments=False,
+                                   omp_sentinel=True)
         reader.exit_on_error = False  # don't call sys.exit, it messes up the multi-processing

         try:

This obviously needs a new fparser release

hiker commented 2 months ago

https://github.com/stfc/fparser/pull/444. has been merged, so once we do the next fparser release we can support these statements. As part of the improved compiler support I am also improving the handling of openmp, so FAB will 'know' whether openmp is enabled or not.