Skip to content

Commit

Permalink
Improved MPI/OpenMP support (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker authored Nov 19, 2024
1 parent d0a92e8 commit 4cebd42
Show file tree
Hide file tree
Showing 36 changed files with 927 additions and 343 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ __pycache__/
*$py.class

# Build directory for documentation
docs/build
docs/source/api
docs/source/apidoc
Documentation/build
Documentation/source/api
Documentation/source/apidoc

# C extensions
*.so
Expand Down
12 changes: 12 additions & 0 deletions Documentation/source/site-specific-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ rsync, ar, ...).
tool_box = ToolBox()
default_c_compiler = tool_box.get_tool(Category.C_COMPILER)
There is special handling for compilers and linkers: the build
configuration stores the information if an MPI and/or OpenMP build
is requested. So when a default tool is requested by the ToolBox
from the ToolRepository (i.e. when the user has not added specific
compilers or linkers), this information is taken into account, and
only a compiler that will fulfil the requirements is returned. For
example, if you have `gfortran` and `mpif90-gfortran` defined in this
order in the ToolRepository, and request the default compiler for an
MPI build, the `mpif90-gfortran` instance is returned, not `gfortran`.
On the other hand, if no MPI is requested, an MPI-enabled compiler
might be returned, which does not affect the final result, since
an MPI compiler just adds include- and library-paths.

TODO
====
Expand Down
2 changes: 1 addition & 1 deletion run_configs/gcom/build_gcom_ar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
if __name__ == '__main__':

with BuildConfig(project_label='gcom object archive $compiler',
tool_box=ToolBox()) as state:
mpi=True, openmp=False, tool_box=ToolBox()) as state:
common_build_steps(state)
archive_objects(state, output_fpath='$output/libgcom.a')
cleanup_prebuilds(state, all_unused=True)
4 changes: 2 additions & 2 deletions run_configs/gcom/build_gcom_so.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
parsed_args = arg_parser.parse_args()

with BuildConfig(project_label='gcom shared library $compiler',
tool_box=ToolBox()) as state:
mpi=True, openmp=False, tool_box=ToolBox()) as state:
common_build_steps(state, fpic=True)
link_shared_object(state, output_fpath='$output/libgcom.so'),
link_shared_object(state, output_fpath='$output/libgcom.so')
cleanup_prebuilds(state, all_unused=True)
19 changes: 12 additions & 7 deletions run_configs/jules/build_jules.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ def __init__(self):
tool_box.add_tool(Linker(compiler=fc))

with BuildConfig(project_label=f'jules {revision} $compiler',
tool_box=tool_box) as state:
# grab the source. todo: use some checkouts instead of exports in these configs.
fcm_export(state, src='fcm:jules.xm_tr/src', revision=revision, dst_label='src')
fcm_export(state, src='fcm:jules.xm_tr/utils', revision=revision, dst_label='utils')
mpi=False, openmp=False, tool_box=tool_box) as state:
# grab the source. todo: use some checkouts instead of exports
# in these configs.
fcm_export(state, src='fcm:jules.xm_tr/src', revision=revision,
dst_label='src')
fcm_export(state, src='fcm:jules.xm_tr/utils', revision=revision,
dst_label='utils')

grab_pre_build(state, path='/not/a/real/folder', allow_fail=True),
grab_pre_build(state, path='/not/a/real/folder', allow_fail=True)

# find the source files
find_source_files(state, path_filters=[
Expand All @@ -61,9 +64,11 @@ def __init__(self):
# move inc files to the root for easy tool use
root_inc_files(state)

preprocess_fortran(state, common_flags=['-P', '-DMPI_DUMMY', '-DNCDF_DUMMY', '-I$output'])
preprocess_fortran(state, common_flags=['-P', '-DMPI_DUMMY',
'-DNCDF_DUMMY', '-I$output'])

analyse(state, root_symbol='jules', unreferenced_deps=['imogen_update_carb'])
analyse(state, root_symbol='jules',
unreferenced_deps=['imogen_update_carb'])

compile_fortran(state)

Expand Down
2 changes: 1 addition & 1 deletion run_configs/lfric/atm.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def file_filtering(config):
gpl_utils_source = gpl_utils_source_config.source_root / 'gpl_utils'

with BuildConfig(project_label='atm $compiler $two_stage',
tool_box=ToolBox()) as state:
mpi=False, openmp=False, tool_box=ToolBox()) as state:

# todo: use different dst_labels because they all go into the same folder,
# making it hard to see what came from where?
Expand Down
10 changes: 6 additions & 4 deletions run_configs/lfric/grab_lfric.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
# these configs are interrogated by the build scripts
# todo: doesn't need two separate configs, they use the same project workspace
tool_box = ToolBox()
lfric_source_config = BuildConfig(project_label=f'lfric source {LFRIC_REVISION}',
tool_box=tool_box)
gpl_utils_source_config = BuildConfig(project_label=f'lfric source {LFRIC_REVISION}',
tool_box=tool_box)
lfric_source_config = BuildConfig(
project_label=f'lfric source {LFRIC_REVISION}',
tool_box=tool_box)
gpl_utils_source_config = BuildConfig(
project_label=f'lfric source {LFRIC_REVISION}',
tool_box=tool_box)


if __name__ == '__main__':
Expand Down
6 changes: 2 additions & 4 deletions run_configs/lfric/gungho.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
gpl_utils_source = gpl_utils_source_config.source_root / 'gpl_utils'

with BuildConfig(project_label='gungho $compiler $two_stage',
tool_box=ToolBox()) as state:
mpi=True, openmp=True, tool_box=ToolBox()) as state:
grab_folder(state, src=lfric_source / 'infrastructure/source/', dst_label='')
grab_folder(state, src=lfric_source / 'components/driver/source/', dst_label='')
grab_folder(state, src=lfric_source / 'components' / 'inventory' / 'source', dst_label='')
Expand Down Expand Up @@ -87,7 +87,7 @@
state,
common_flags=[
'-c',
'-ffree-line-length-none', '-fopenmp',
'-ffree-line-length-none',
'-g',
'-std=f2008',

Expand All @@ -104,8 +104,6 @@
link_exe(
state,
flags=[
'-fopenmp',

'-lyaxt', '-lyaxt_c', '-lnetcdff', '-lnetcdf', '-lhdf5', # EXTERNAL_DYNAMIC_LIBRARIES
'-lxios', # EXTERNAL_STATIC_LIBRARIES
'-lstdc++',
Expand Down
2 changes: 1 addition & 1 deletion run_configs/lfric/mesh_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
psyclone_overrides = Path(__file__).parent / 'mesh_tools_overrides'

with BuildConfig(project_label='mesh tools $compiler $two_stage',
tool_box=ToolBox()) as state:
mpi=True, openmp=False, tool_box=ToolBox()) as state:
grab_folder(state, src=lfric_source / 'infrastructure/source/', dst_label='')
grab_folder(state, src=lfric_source / 'mesh_tools/source/', dst_label='')
grab_folder(state, src=lfric_source / 'components/science/source/', dst_label='')
Expand Down
12 changes: 6 additions & 6 deletions run_configs/tiny_fortran/build_tiny_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def __init__(self):
with BuildConfig(project_label='tiny_fortran $compiler',
tool_box=tool_box) as state:
git_checkout(state, src='https://github.com/metomi/fab-test-data.git',
revision='main', dst_label='src'),
revision='main', dst_label='src')

find_source_files(state),
find_source_files(state)

preprocess_fortran(state),
preprocess_fortran(state)

analyse(state, root_symbol='my_prog'),
analyse(state, root_symbol='my_prog')

compile_fortran(state),
link_exe(state),
compile_fortran(state)
link_exe(state)
7 changes: 5 additions & 2 deletions run_configs/um/build_um.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ def replace_in_file(inpath, outpath, find, replace):
revision = 'vn12.1'
um_revision = revision.replace('vn', 'um')

state = BuildConfig(project_label=f'um atmos safe {revision} $compiler $two_stage',
tool_box=ToolBox())
# The original build script disabled openmp, so for now
# we keep this disabled.
state = BuildConfig(
project_label=f'um atmos safe {revision} $compiler $two_stage',
mpi=True, openmp=False, tool_box=ToolBox())

# compiler-specific flags
compiler = state.tool_box[Category.FORTRAN_COMPILER]
Expand Down
Loading

0 comments on commit 4cebd42

Please sign in to comment.