Skip to content

Commit

Permalink
Update psyclone to support next release syntax (#354)
Browse files Browse the repository at this point in the history
* Made mpi and openmp default to False in the BuildConfig constructor.

* Removed white space.

* Support compilers that do not support OpenMP.

* Added documentation for openmp parameter.

* Mpi omp support (#343)

* #3 Introduce fixtures for Fortran compiler and tool_box.

* #3 Remove explicit compiler information from MpCommonArgs (since it's already part of the config toolbox).

* #3 Added linker as tool.

* #3 Added test for linking shared libraries.

* #3 Pass compiler flags to the linker if a compiler was specified.

* #3 Remove unused function.

* #3 Removed more unused code.

* #3 Automatically add a linker for each compiler.

* #3 Fixed typo.

* #3 Support vendor for compiler and linker.

* #3 Make linker having a vendor, too.

* #3 Add set_default_vendor method to tool repository.

* Ignore build directory for git.

* Updated test.

* # Fix some mypy errors and warnings.

* Avoid using get() for singleton, instead use __new__ which makes mypy happier.

* Changed the transformation_script parameter of function psyclone to accept a function that can return file-specific transformation scripts

* Make mypy happy by using patch.object.

* Remove more comments and confusion about mypy :)

* Try to make mypy happy on older python versions.

* Make flake8 happy.

* Sort imported name alphabetically.

* Try to fix failing hash test (and add some additional improvements in the test).

* Removed fpath= for input transformation_script function to pass mypy test for Python 3.7; Moved transformation_script_hash test to unit test from system test

* Fix mypy typing check errors for psyclone unit test

* Fix config typing issue with mypy in psyclone unit test

* Fix flake8 issues; Revert Config mypy typing fix

* Add comment to ignore typing check for fpath parameter of input transformation_script function

* Fix assert check after transformation_script function is changed from being called twice to once

* Filter out 'no transformation script' warning for psyclone system test

* Replace 'ignore' typing of fpath of transformation_script with removing keyword argument

* #3 Support proper tests to check if tools are available.

* 1. Updated transformation_script description; 2. Modified mock_transformation_script; 3.Removed redundant _analysis_for_prebuilds

* Updated lfric/atm.py and lfric/gungho.py examples to pass in transformation_script functions

* Added description for the psyclone step to instructions on writing a config

* #3 Added git as a tool.

* #3 Fix incorrect | usage in typing.

* #3 Added unit tests for git.

* #3 Renamed git.py to versioning.py, to avoid name clash with the corresponding test_git.py tests.

* #3 Converted svn and fcm to tools.

* #3 Fixed missing whitespace.

* Modified the documentation for writing a config with PSyclone

* Add config as a parameter for run_psyclone for the transformation_script to use;Updated the related functions and tests;
Changed the logic of the transformation_script examples

* #3 Replaced ar with tool object.

* #3 Added tests for ar.py.

* #3 Removed debug output.

* #3 Converted PSyclone to be a tool.

* #3 Removed debug print, fixed python 3.7 typing information.

* #3 Updated comments.

* Modified the get_optimisation_script function examples and updated the doc formatting

* #3 Add Rsync tool.

* #3 Removed now unused function.

* #3 Added test for rsync.

* #3 Fixed all mypy warnings about functions not checked.

* #3 Replace all mock-tests to use subprocess so the name of the executable is tested as well.

* #3 Remove duplicated flags.

* #3 Fixed changed order of linking.

* #3 Removed run_command function.

* #3 Fixed 3.8 typing error.

* #3 Fixed unused imports.

* #3 Move flags checksum into Flags, and remove now unused tools.py file.

* #3 Renamed newtools to tools.

* #3 Made custom function for all git functions called (instead of just calling run).

* #3 Updated and fixed comments.

* #3 Fixed errors in comments.

* Fixed minor errors in documentation.

* #3 Make it easier to create wrapper around standard compiler.

* #3 Added documentation for all tool related classes and their usage.

* #3 Added MISC category.

* Addressed reviewer's comments.

* Updated cli to properly use ToolBox etc, removing hard-coded gnu command linker option.

* Fixed mypy failures, including changes to import statement to avoid cyclic imports :(.

* #3 Fix circular import.

* Added #TODO so that this can be removed once fparser supports sentinels.

* Fix typing problems by ignoring fparser.

* Replaced more string names for artefacts with enums.

* Removed EXECUTABLES from constants.

* Moved Artefact class out of ArtefactStore and renamed it to ArtefactSet.

* Moved OBJECT_FILES from constants into ArtefactSet.

* Moved OBJECT_ARCHIVES from constants to ArtefactSet.

* Moved PRAGMAD_C from constants to ArtefactSet.

* Turned 'all_source' into an enum.

* Allow integer as revision.

* Fixed flake8 error.

* Removed specific functions to add/get fortran source files etc.

* Removed non-existing and unneccessary collections.

* Try to fix all run_configs.

* Fixed rebase issues.

* Added replace functionality to ArtefactStore, updated test_artefacts to cover all lines in that file.

* Started to replace artefacts when files are pre-processed.

* Removed linker argument from linking step in all examples.

* Try to get jules to link.

* Fixed build_jules.

* Fixed other issues raised in reviews.

* Try to get jules to link.

* Fixed other issues raised in reviews.

* Simplify handling of X90 files by replacing the X90 with x90, meaning only one artefact set is involved when running PSyclone.

* Make OBJECT_ARCHIVES also a dict, migrate more code to replace/add files to the default build artefact collections.

* Fixed some examples.

* Fix flake8 error.

* Fixed failing tests.

* Support empty comments.

* Fix preprocessor to not unnecessary remove and add files that are already in the output directory.

* Allow find_soure_files to be called more than once by adding files (not replacing artefact).

* Updated lfric_common so that files created by configurator are written in build (not source).

* Use c_build_files instead of pragmad_c.

* Removed unnecessary str.

* Documented the new artefact set handling.

* Fixed typo.

* Make the PSyclone API configurable.

* Fixed formatting of documentation, properly used ArtefactSet names.

* Support .f and .F Fortran files.

* Removed setter for tool.is_available, which was only used for testing.

* #3 Fix documentation and coding style issues from review.

* Renamed Categories into Category.

* Minor coding style cleanup.

* Removed more unnecessary ().

* Re-added (invalid) grab_pre_build call.

* Fixed typo.

* Renamed set_default_vendor to set_default_compiler_suite.

* Renamed VendorTool to CompilerSuiteTool.

* Also accept a Path as exec_name specification for a tool.

* Move the check_available function into the base class.

* Fixed some types and documentation.

* Fix typing error.

* Added explanation for meta-compiler.

* Improved error handling and documentation.

* Replace mpiifort with mpifort to be a tiny bit more portable.

* Use classes to group tests for git/svn/fcm together.

* Fixed issue in get_transformation script, and moved script into lfric_common to remove code duplication.

* Code improvement as suggested by review.

* Fixed run config

* Added reference to ticket.

* Updated type information.

* More typing fixes.

* Fixed typing warnings.

* As requested by reviewer removed is_working_copy functionality.

* Issue a warning (which can be silenced) when a tool in a toolbox is replaced.

* Fixed flake8.

* Fixed flake8.

* Fixed failing test.

* Addressed issues raised in review.

* Removed now unnecessary operations.

* Updated some type information.

* Fixed all references to APIs to be consistent with PSyclone 2.5.

* Added api to the checksum computation.

* Fixed type information.

* Added test to verify that changing the api changes the checksum.

* Make compiler version a tuple of integers

* Update some tests to use tuple versions

* Explicitly test handling of bad version format

* Fix formatting

* Tidying up

* Make compiler raise an error for any invalid version string

Assume these compilers don't need to be hashed.
Saves dealing with empty tuples.

* Check compiler version string for compiler name

* Fix formatting

* Add compiler.get_version_string() method

Includes other cleanup from PR comments

* Add mpi and openmp settings to BuildConfig, made compiler MPI aware.

* Looks like the circular dependency has been fixed.

* Revert "Looks like the circular dependency has been fixed." ...
while it works with the tests, a real application still triggered it.

This reverts commit 150dc37.

* Don't even try to find a C compiler if no C files are to be compiled.

* Updated gitignore to ignore (recently renamed) documentation.

* Fixed failing test.

* Return from compile Fortran early if there are no files to compiles. Fixed coding style.

* Add MPI enables wrapper for intel and gnu compiler.

* Fixed test.

* Automatically add openmp flag to compiler and linker based on BuildConfig.

* Removed enforcement of keyword parameters, which is not supported in python 3.7.

* Fixed failing test.

* Support more than one tool of a given suite by sorting them.

* Use different version checkout for each compiler vendor with mixins

* Refactoring, remove unittest compiler class

* Fix some mypy errors

* Use 'Union' type hint to fix build checks

* Return run_version_command to base Compiler class

Provides default version command that can be overridden for other compilers.
Also fix some incorrect tests
Other tidying

* Add a missing type hint

* Remove inheritance from mixins and use protocol

* Simplify compiler inheritance

Mixins have static methods with unique names,
overrides only happen in concrete classes

* Simplify usage of compiler-specific parsing mixins.

* Test for missing mixin.

* Fixed test.

* Added more tests for invalid version numbers.

* Added more test cases for invalid version number, improved regex to work as expected.

* Fixed typo in test.

* Fixed test.

* Split tests into smaller individual ones, fixed missing asssert in test.

* Parameterised compiler version tests to also test wrapper.

* Added missing MPI parameter when getting the compiler.

* Fixed comments.

* Order parameters to be in same order for various compiler classes.

* Remove stray character

* Made mpi and openmp default to False in the BuildConfig constructor.

* Removed white space.

* Support compilers that do not support OpenMP.

* Added documentation for openmp parameter.

---------

Co-authored-by: Junwei Lyu <jl8309@gadi-login-01.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-09.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-08.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-02.gadi.nci.org.au>
Co-authored-by: jasonjunweilyu <161689601+jasonjunweilyu@users.noreply.github.com>
Co-authored-by: Luke Hoffmann <luke.hoffmann@bom.gov.au>
Co-authored-by: Luke Hoffmann <992315+lukehoffmann@users.noreply.github.com>

* Mpi omp support (#346)

* #3 Introduce fixtures for Fortran compiler and tool_box.

* #3 Remove explicit compiler information from MpCommonArgs (since it's already part of the config toolbox).

* #3 Added linker as tool.

* #3 Added test for linking shared libraries.

* #3 Pass compiler flags to the linker if a compiler was specified.

* #3 Remove unused function.

* #3 Removed more unused code.

* #3 Automatically add a linker for each compiler.

* #3 Fixed typo.

* #3 Support vendor for compiler and linker.

* #3 Make linker having a vendor, too.

* #3 Add set_default_vendor method to tool repository.

* Ignore build directory for git.

* Updated test.

* # Fix some mypy errors and warnings.

* Avoid using get() for singleton, instead use __new__ which makes mypy happier.

* Changed the transformation_script parameter of function psyclone to accept a function that can return file-specific transformation scripts

* Make mypy happy by using patch.object.

* Remove more comments and confusion about mypy :)

* Try to make mypy happy on older python versions.

* Make flake8 happy.

* Sort imported name alphabetically.

* Try to fix failing hash test (and add some additional improvements in the test).

* Removed fpath= for input transformation_script function to pass mypy test for Python 3.7; Moved transformation_script_hash test to unit test from system test

* Fix mypy typing check errors for psyclone unit test

* Fix config typing issue with mypy in psyclone unit test

* Fix flake8 issues; Revert Config mypy typing fix

* Add comment to ignore typing check for fpath parameter of input transformation_script function

* Fix assert check after transformation_script function is changed from being called twice to once

* Filter out 'no transformation script' warning for psyclone system test

* Replace 'ignore' typing of fpath of transformation_script with removing keyword argument

* #3 Support proper tests to check if tools are available.

* 1. Updated transformation_script description; 2. Modified mock_transformation_script; 3.Removed redundant _analysis_for_prebuilds

* Updated lfric/atm.py and lfric/gungho.py examples to pass in transformation_script functions

* Added description for the psyclone step to instructions on writing a config

* #3 Added git as a tool.

* #3 Fix incorrect | usage in typing.

* #3 Added unit tests for git.

* #3 Renamed git.py to versioning.py, to avoid name clash with the corresponding test_git.py tests.

* #3 Converted svn and fcm to tools.

* #3 Fixed missing whitespace.

* Modified the documentation for writing a config with PSyclone

* Add config as a parameter for run_psyclone for the transformation_script to use;Updated the related functions and tests;
Changed the logic of the transformation_script examples

* #3 Replaced ar with tool object.

* #3 Added tests for ar.py.

* #3 Removed debug output.

* #3 Converted PSyclone to be a tool.

* #3 Removed debug print, fixed python 3.7 typing information.

* #3 Updated comments.

* Modified the get_optimisation_script function examples and updated the doc formatting

* #3 Add Rsync tool.

* #3 Removed now unused function.

* #3 Added test for rsync.

* #3 Fixed all mypy warnings about functions not checked.

* #3 Replace all mock-tests to use subprocess so the name of the executable is tested as well.

* #3 Remove duplicated flags.

* #3 Fixed changed order of linking.

* #3 Removed run_command function.

* #3 Fixed 3.8 typing error.

* #3 Fixed unused imports.

* #3 Move flags checksum into Flags, and remove now unused tools.py file.

* #3 Renamed newtools to tools.

* #3 Made custom function for all git functions called (instead of just calling run).

* #3 Updated and fixed comments.

* #3 Fixed errors in comments.

* Fixed minor errors in documentation.

* #3 Make it easier to create wrapper around standard compiler.

* #3 Added documentation for all tool related classes and their usage.

* #3 Added MISC category.

* Addressed reviewer's comments.

* Updated cli to properly use ToolBox etc, removing hard-coded gnu command linker option.

* Fixed mypy failures, including changes to import statement to avoid cyclic imports :(.

* #3 Fix circular import.

* Added #TODO so that this can be removed once fparser supports sentinels.

* Fix typing problems by ignoring fparser.

* Replaced more string names for artefacts with enums.

* Removed EXECUTABLES from constants.

* Moved Artefact class out of ArtefactStore and renamed it to ArtefactSet.

* Moved OBJECT_FILES from constants into ArtefactSet.

* Moved OBJECT_ARCHIVES from constants to ArtefactSet.

* Moved PRAGMAD_C from constants to ArtefactSet.

* Turned 'all_source' into an enum.

* Allow integer as revision.

* Fixed flake8 error.

* Removed specific functions to add/get fortran source files etc.

* Removed non-existing and unneccessary collections.

* Try to fix all run_configs.

* Fixed rebase issues.

* Added replace functionality to ArtefactStore, updated test_artefacts to cover all lines in that file.

* Started to replace artefacts when files are pre-processed.

* Removed linker argument from linking step in all examples.

* Try to get jules to link.

* Fixed build_jules.

* Fixed other issues raised in reviews.

* Try to get jules to link.

* Fixed other issues raised in reviews.

* Simplify handling of X90 files by replacing the X90 with x90, meaning only one artefact set is involved when running PSyclone.

* Make OBJECT_ARCHIVES also a dict, migrate more code to replace/add files to the default build artefact collections.

* Fixed some examples.

* Fix flake8 error.

* Fixed failing tests.

* Support empty comments.

* Fix preprocessor to not unnecessary remove and add files that are already in the output directory.

* Allow find_soure_files to be called more than once by adding files (not replacing artefact).

* Updated lfric_common so that files created by configurator are written in build (not source).

* Use c_build_files instead of pragmad_c.

* Removed unnecessary str.

* Documented the new artefact set handling.

* Fixed typo.

* Make the PSyclone API configurable.

* Fixed formatting of documentation, properly used ArtefactSet names.

* Support .f and .F Fortran files.

* Removed setter for tool.is_available, which was only used for testing.

* #3 Fix documentation and coding style issues from review.

* Renamed Categories into Category.

* Minor coding style cleanup.

* Removed more unnecessary ().

* Re-added (invalid) grab_pre_build call.

* Fixed typo.

* Renamed set_default_vendor to set_default_compiler_suite.

* Renamed VendorTool to CompilerSuiteTool.

* Also accept a Path as exec_name specification for a tool.

* Move the check_available function into the base class.

* Fixed some types and documentation.

* Fix typing error.

* Added explanation for meta-compiler.

* Improved error handling and documentation.

* Replace mpiifort with mpifort to be a tiny bit more portable.

* Use classes to group tests for git/svn/fcm together.

* Fixed issue in get_transformation script, and moved script into lfric_common to remove code duplication.

* Code improvement as suggested by review.

* Fixed run config

* Added reference to ticket.

* Updated type information.

* More typing fixes.

* Fixed typing warnings.

* As requested by reviewer removed is_working_copy functionality.

* Issue a warning (which can be silenced) when a tool in a toolbox is replaced.

* Fixed flake8.

* Fixed flake8.

* Fixed failing test.

* Addressed issues raised in review.

* Removed now unnecessary operations.

* Updated some type information.

* Fixed all references to APIs to be consistent with PSyclone 2.5.

* Added api to the checksum computation.

* Fixed type information.

* Added test to verify that changing the api changes the checksum.

* Make compiler version a tuple of integers

* Update some tests to use tuple versions

* Explicitly test handling of bad version format

* Fix formatting

* Tidying up

* Make compiler raise an error for any invalid version string

Assume these compilers don't need to be hashed.
Saves dealing with empty tuples.

* Check compiler version string for compiler name

* Fix formatting

* Add compiler.get_version_string() method

Includes other cleanup from PR comments

* Add mpi and openmp settings to BuildConfig, made compiler MPI aware.

* Looks like the circular dependency has been fixed.

* Revert "Looks like the circular dependency has been fixed." ...
while it works with the tests, a real application still triggered it.

This reverts commit 150dc37.

* Don't even try to find a C compiler if no C files are to be compiled.

* Updated gitignore to ignore (recently renamed) documentation.

* Fixed failing test.

* Return from compile Fortran early if there are no files to compiles. Fixed coding style.

* Add MPI enables wrapper for intel and gnu compiler.

* Fixed test.

* Automatically add openmp flag to compiler and linker based on BuildConfig.

* Removed enforcement of keyword parameters, which is not supported in python 3.7.

* Fixed failing test.

* Support more than one tool of a given suite by sorting them.

* Use different version checkout for each compiler vendor with mixins

* Refactoring, remove unittest compiler class

* Fix some mypy errors

* Use 'Union' type hint to fix build checks

* Return run_version_command to base Compiler class

Provides default version command that can be overridden for other compilers.
Also fix some incorrect tests
Other tidying

* Add a missing type hint

* Remove inheritance from mixins and use protocol

* Simplify compiler inheritance

Mixins have static methods with unique names,
overrides only happen in concrete classes

* Simplify usage of compiler-specific parsing mixins.

* Test for missing mixin.

* Fixed test.

* Added more tests for invalid version numbers.

* Added more test cases for invalid version number, improved regex to work as expected.

* Fixed typo in test.

* Fixed test.

* Split tests into smaller individual ones, fixed missing asssert in test.

* Parameterised compiler version tests to also test wrapper.

* Added missing MPI parameter when getting the compiler.

* Fixed comments.

* Order parameters to be in same order for various compiler classes.

* Remove stray character

* Made mpi and openmp default to False in the BuildConfig constructor.

* Removed white space.

* Support compilers that do not support OpenMP.

* Added documentation for openmp parameter.

---------

Co-authored-by: Junwei Lyu <jl8309@gadi-login-01.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-09.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-08.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-02.gadi.nci.org.au>
Co-authored-by: jasonjunweilyu <161689601+jasonjunweilyu@users.noreply.github.com>
Co-authored-by: Luke Hoffmann <luke.hoffmann@bom.gov.au>
Co-authored-by: Luke Hoffmann <992315+lukehoffmann@users.noreply.github.com>

* Compiler wrapper (#347)

* #3 Converted svn and fcm to tools.

* #3 Fixed missing whitespace.

* Modified the documentation for writing a config with PSyclone

* Add config as a parameter for run_psyclone for the transformation_script to use;Updated the related functions and tests;
Changed the logic of the transformation_script examples

* #3 Replaced ar with tool object.

* #3 Added tests for ar.py.

* #3 Removed debug output.

* #3 Converted PSyclone to be a tool.

* #3 Removed debug print, fixed python 3.7 typing information.

* #3 Updated comments.

* Modified the get_optimisation_script function examples and updated the doc formatting

* #3 Add Rsync tool.

* #3 Removed now unused function.

* #3 Added test for rsync.

* #3 Fixed all mypy warnings about functions not checked.

* #3 Replace all mock-tests to use subprocess so the name of the executable is tested as well.

* #3 Remove duplicated flags.

* #3 Fixed changed order of linking.

* #3 Removed run_command function.

* #3 Fixed 3.8 typing error.

* #3 Fixed unused imports.

* #3 Move flags checksum into Flags, and remove now unused tools.py file.

* #3 Renamed newtools to tools.

* #3 Made custom function for all git functions called (instead of just calling run).

* #3 Updated and fixed comments.

* #3 Fixed errors in comments.

* Fixed minor errors in documentation.

* #3 Make it easier to create wrapper around standard compiler.

* #3 Added documentation for all tool related classes and their usage.

* #3 Added MISC category.

* Addressed reviewer's comments.

* Updated cli to properly use ToolBox etc, removing hard-coded gnu command linker option.

* Fixed mypy failures, including changes to import statement to avoid cyclic imports :(.

* #3 Fix circular import.

* Added #TODO so that this can be removed once fparser supports sentinels.

* Fix typing problems by ignoring fparser.

* Replaced more string names for artefacts with enums.

* Removed EXECUTABLES from constants.

* Moved Artefact class out of ArtefactStore and renamed it to ArtefactSet.

* Moved OBJECT_FILES from constants into ArtefactSet.

* Moved OBJECT_ARCHIVES from constants to ArtefactSet.

* Moved PRAGMAD_C from constants to ArtefactSet.

* Turned 'all_source' into an enum.

* Allow integer as revision.

* Fixed flake8 error.

* Removed specific functions to add/get fortran source files etc.

* Removed non-existing and unneccessary collections.

* Try to fix all run_configs.

* Fixed rebase issues.

* Added replace functionality to ArtefactStore, updated test_artefacts to cover all lines in that file.

* Started to replace artefacts when files are pre-processed.

* Removed linker argument from linking step in all examples.

* Try to get jules to link.

* Fixed build_jules.

* Fixed other issues raised in reviews.

* Try to get jules to link.

* Fixed other issues raised in reviews.

* Simplify handling of X90 files by replacing the X90 with x90, meaning only one artefact set is involved when running PSyclone.

* Make OBJECT_ARCHIVES also a dict, migrate more code to replace/add files to the default build artefact collections.

* Fixed some examples.

* Fix flake8 error.

* Fixed failing tests.

* Support empty comments.

* Fix preprocessor to not unnecessary remove and add files that are already in the output directory.

* Allow find_soure_files to be called more than once by adding files (not replacing artefact).

* Updated lfric_common so that files created by configurator are written in build (not source).

* Use c_build_files instead of pragmad_c.

* Removed unnecessary str.

* Documented the new artefact set handling.

* Fixed typo.

* Make the PSyclone API configurable.

* Fixed formatting of documentation, properly used ArtefactSet names.

* Support .f and .F Fortran files.

* Removed setter for tool.is_available, which was only used for testing.

* #3 Fix documentation and coding style issues from review.

* Renamed Categories into Category.

* Minor coding style cleanup.

* Removed more unnecessary ().

* Re-added (invalid) grab_pre_build call.

* Fixed typo.

* Renamed set_default_vendor to set_default_compiler_suite.

* Renamed VendorTool to CompilerSuiteTool.

* Also accept a Path as exec_name specification for a tool.

* Move the check_available function into the base class.

* Fixed some types and documentation.

* Fix typing error.

* Added explanation for meta-compiler.

* Improved error handling and documentation.

* Replace mpiifort with mpifort to be a tiny bit more portable.

* Use classes to group tests for git/svn/fcm together.

* Fixed issue in get_transformation script, and moved script into lfric_common to remove code duplication.

* Code improvement as suggested by review.

* Fixed run config

* Added reference to ticket.

* Updated type information.

* More typing fixes.

* Fixed typing warnings.

* As requested by reviewer removed is_working_copy functionality.

* Issue a warning (which can be silenced) when a tool in a toolbox is replaced.

* Fixed flake8.

* Fixed flake8.

* Fixed failing test.

* Addressed issues raised in review.

* Removed now unnecessary operations.

* Updated some type information.

* Fixed all references to APIs to be consistent with PSyclone 2.5.

* Added api to the checksum computation.

* Fixed type information.

* Added test to verify that changing the api changes the checksum.

* Make compiler version a tuple of integers

* Update some tests to use tuple versions

* Explicitly test handling of bad version format

* Fix formatting

* Tidying up

* Make compiler raise an error for any invalid version string

Assume these compilers don't need to be hashed.
Saves dealing with empty tuples.

* Check compiler version string for compiler name

* Fix formatting

* Add compiler.get_version_string() method

Includes other cleanup from PR comments

* Add mpi and openmp settings to BuildConfig, made compiler MPI aware.

* Looks like the circular dependency has been fixed.

* Revert "Looks like the circular dependency has been fixed." ...
while it works with the tests, a real application still triggered it.

This reverts commit 150dc37.

* Don't even try to find a C compiler if no C files are to be compiled.

* Updated gitignore to ignore (recently renamed) documentation.

* Fixed failing test.

* Return from compile Fortran early if there are no files to compiles. Fixed coding style.

* Add MPI enables wrapper for intel and gnu compiler.

* Fixed test.

* Automatically add openmp flag to compiler and linker based on BuildConfig.

* Removed enforcement of keyword parameters, which is not supported in python 3.7.

* Fixed failing test.

* Support more than one tool of a given suite by sorting them.

* Use different version checkout for each compiler vendor with mixins

* Refactoring, remove unittest compiler class

* Fix some mypy errors

* Use 'Union' type hint to fix build checks

* Added option to add flags to a tool.

* Introduce proper compiler wrapper, used this to implement properly wrapper MPI compiler.

* Fixed typo in types.

* Return run_version_command to base Compiler class

Provides default version command that can be overridden for other compilers.
Also fix some incorrect tests
Other tidying

* Add a missing type hint

* Added (somewhat stupid) 'test' to reach 100% coverage of PSyclone tool.

* Simplified MPI support in wrapper.

* More compiler wrapper coverage.

* Removed duplicated function.

* Removed debug print.

* Removed permanently changing compiler attributes, which can cause test failures later.

* More test for C compiler wrapper.

* More work on compiler wrapper tests.

* Fixed version and availability handling, added missing tests for 100% coverage.

* Fixed typing error.

* Try to fix python 3.7.

* Tried to fix failing tests.

* Remove inheritance from mixins and use protocol

* Simplify compiler inheritance

Mixins have static methods with unique names,
overrides only happen in concrete classes

* Updated wrapper and tests to handle error raised in get_version.

* Simplified regular expressions (now tests cover detection of version numbers with only a major version).

* Test for missing mixin.

* Use the parsing mixing from the compiler in a compiler wrapper.

* Use setattr instead of assignment to make mypy happy.

* Simplify usage of compiler-specific parsing mixins.

* Minor code cleanup.

* Updated documentation.

* Simplify usage of compiler-specific parsing mixins.

* Test for missing mixin.

* Fixed test.

* Added missing openmp_flag property to compiler wrapper.

* Don't use isinstance for consistency check, which does not work for CompilerWrappers.

* Fixed isinstance test for C compilation which doesn't work with a CompilerWrapper.

* Use a linker's compiler to determine MPI support. Removed mpi property from CompilerSuite.

* Added more tests for invalid version numbers.

* Added more test cases for invalid version number, improved regex to work as expected.

* Fixed typo in test.

* Fixed flake/mypy errors.

* Combine wrapper flags with flags from wrapped compiler.

* Made mypy happy.

* Fixed test.

* Split tests into smaller individual ones, fixed missing asssert in test.

* Parameterised compiler version tests to also test wrapper.

* Added missing MPI parameter when getting the compiler.

* Fixed comments.

* Order parameters to be in same order for various compiler classes.

* Remove stray character

* Added getter for wrapped compiler.

* Fixed small error that would prevent nested compiler wrappers from being used.

* Added a cast to make mypy happy.

* Fixed spelling mistake in option.

* Clarified documentation.

* Removed unnecessary functions in CompilerWrapper.

* Made mpi and openmp default to False in the BuildConfig constructor.

* Removed white space.

* Support compilers that do not support OpenMP.

* Added documentation for openmp parameter.

---------

Co-authored-by: Junwei Lyu <jl8309@gadi-login-08.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-02.gadi.nci.org.au>
Co-authored-by: jasonjunweilyu <161689601+jasonjunweilyu@users.noreply.github.com>
Co-authored-by: Luke Hoffmann <luke.hoffmann@bom.gov.au>
Co-authored-by: Luke Hoffmann <992315+lukehoffmann@users.noreply.github.com>

* Improved MPI/OpenMP support (#336)

* Recovering anything of value from the old tests (#339)

* Skip test dependent on clang module if it is not installed.

* Inherit slightly more extensive testing of C pragma injector.

* Migrated some real-life testing of Subversion interface.

* Updated comment.

* Just remove old tests.

* Reverted mistaken clean-up.

* Removed unused import.

---------

Co-authored-by: Junwei Lyu <jl8309@gadi-login-01.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-09.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-08.gadi.nci.org.au>
Co-authored-by: Junwei Lyu <jl8309@gadi-login-02.gadi.nci.org.au>
Co-authored-by: jasonjunweilyu <161689601+jasonjunweilyu@users.noreply.github.com>
Co-authored-by: Luke Hoffmann <luke.hoffmann@bom.gov.au>
Co-authored-by: Luke Hoffmann <992315+lukehoffmann@users.noreply.github.com>
Co-authored-by: Matthew Hambley <MatthewHambley@users.noreply.github.com>
  • Loading branch information
9 people authored Nov 21, 2024
1 parent ec4c0f6 commit d2be06c
Show file tree
Hide file tree
Showing 107 changed files with 419 additions and 2,593 deletions.
15 changes: 14 additions & 1 deletion Documentation/source/site-specific-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ 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.


Compiler Wrapper
================
Fab supports the concept of a compiler wrapper, which is typically
Expand Down Expand Up @@ -205,7 +219,6 @@ applied to the wrapper as well:
assert my_mpicc.flags == ["-a", "-b"]
TODO
====
At this stage compiler flags are still set in the corresponding Fab
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',
mpi=False, openmp=False, 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)
2 changes: 1 addition & 1 deletion 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',
mpi=False, openmp=False, 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')
cleanup_prebuilds(state, all_unused=True)
2 changes: 1 addition & 1 deletion run_configs/gcom/grab_gcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# we put this here so the two build configs can read its source_root
grab_config = BuildConfig(project_label=f'gcom_source {revision}',
mpi=False, openmp=False, tool_box=ToolBox())
tool_box=ToolBox())


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions run_configs/lfric/grab_lfric.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
tool_box = ToolBox()
lfric_source_config = BuildConfig(
project_label=f'lfric source {LFRIC_REVISION}',
mpi=False, openmp=False, tool_box=tool_box)
tool_box=tool_box)
gpl_utils_source_config = BuildConfig(
project_label=f'lfric source {LFRIC_REVISION}',
mpi=False, openmp=False, tool_box=tool_box)
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',
mpi=False, openmp=False, 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',
mpi=False, openmp=False, 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
2 changes: 1 addition & 1 deletion run_configs/tiny_fortran/build_tiny_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):
tool_box.add_tool(Linker(compiler=fc))

with BuildConfig(project_label='tiny_fortran $compiler',
mpi=False, openmp=False, tool_box=tool_box) as state:
tool_box=tool_box) as state:
git_checkout(state, src='https://github.com/metomi/fab-test-data.git',
revision='main', dst_label='src')

Expand Down
4 changes: 3 additions & 1 deletion run_configs/um/build_um.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ def replace_in_file(inpath, outpath, find, replace):
revision = 'vn12.1'
um_revision = revision.replace('vn', 'um')

# 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=False, openmp=False, tool_box=ToolBox())
mpi=True, openmp=False, tool_box=ToolBox())

# compiler-specific flags
compiler = state.tool_box[Category.FORTRAN_COMPILER]
Expand Down
17 changes: 11 additions & 6 deletions source/fab/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class BuildConfig():
"""
def __init__(self, project_label: str,
tool_box: ToolBox,
mpi: bool,
openmp: bool,
mpi: bool = False,
openmp: bool = False,
multiprocessing: bool = True,
n_procs: Optional[int] = None,
reuse_artefacts: bool = False,
Expand All @@ -56,9 +56,13 @@ def __init__(self, project_label: str,
created from this name, with spaces replaced by underscores.
:param tool_box: The ToolBox with all tools to use in the build.
:param mpi: whether the project uses MPI or not. This is used to
pick a default compiler (if not explicitly set in the ToolBox),
and controls PSyclone parameters.
:param openmp: whether the project should use OpenMP or not.
pick a default compiler (if none is explicitly set in the
ToolBox), and controls PSyclone parameters.
:param openmp: as with `mpi`, this controls whether the project is
using OpenMP or not. This is used to pick a default compiler
(if none is explicitly set in the ToolBox). The compiler-specific
flag to enable OpenMP will automatically be added when compiling
and linking.
:param multiprocessing:
An option to disable multiprocessing to aid debugging.
:param n_procs:
Expand All @@ -85,7 +89,8 @@ def __init__(self, project_label: str,
self._openmp = openmp
self.two_stage = two_stage
self.verbose = verbose
compiler = tool_box.get_tool(Category.FORTRAN_COMPILER, mpi=mpi)
compiler = tool_box.get_tool(Category.FORTRAN_COMPILER, mpi=mpi,
openmp=openmp)
project_label = Template(project_label).safe_substitute(
compiler=compiler.name,
two_stage=f'{int(two_stage)+1}stage')
Expand Down
2 changes: 1 addition & 1 deletion source/fab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _generic_build_config(folder: Path, kwargs=None) -> BuildConfig:
# Set the default Fortran compiler as linker (otherwise e.g. the
# C compiler might be used in linking, requiring additional flags)
tr = ToolRepository()
fc = tr.get_default(Category.FORTRAN_COMPILER, mpi=False)
fc = tr.get_default(Category.FORTRAN_COMPILER, mpi=False, openmp=False)
# TODO: This assumes a mapping of compiler name to the corresponding
# linker name (i.e. `linker-gfortran` or `linker-ifort`). Still, that's
# better than hard-coding gnu here.
Expand Down
5 changes: 3 additions & 2 deletions source/fab/steps/compile_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def compile_c(config, common_flags: Optional[List[str]] = None,
# No need to look for compiler etc if there is nothing to do
return

compiler = config.tool_box.get_tool(Category.C_COMPILER, config.mpi)
compiler = config.tool_box.get_tool(Category.C_COMPILER, mpi=config.mpi,
openmp=config.openmp)
logger.info(f'C compiler is {compiler}')

mp_payload = MpCommonArgs(config=config, flags=flags)
Expand Down Expand Up @@ -147,7 +148,7 @@ def _compile_file(arg: Tuple[AnalysedC, MpCommonArgs]):
compiler.compile_file(analysed_file.fpath, obj_file_prebuild,
openmp=config.openmp,
add_flags=flags)
except Exception as err:
except RuntimeError as err:
return FabException(f"error compiling "
f"{analysed_file.fpath}:\n{err}")

Expand Down
3 changes: 2 additions & 1 deletion source/fab/steps/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def link_exe(config,
output from compiler steps, which typically is the expected behaviour.
"""
linker = config.tool_box.get_tool(Category.LINKER, config.mpi)
linker = config.tool_box.get_tool(Category.LINKER, mpi=config.mpi,
openmp=config.openmp)
logger.info(f'Linker is {linker.name}')

libs = libs or []
Expand Down
15 changes: 13 additions & 2 deletions source/fab/tools/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ class Compiler(CompilerSuiteTool):
:param exec_name: name of the executable to start.
:param suite: name of the compiler suite this tool belongs to.
:param category: the Category (C_COMPILER or FORTRAN_COMPILER).
:param mpi: whether the compiler or linker support MPI.
:param compile_flag: the compilation flag to use when only requesting
compilation (not linking).
:param mpi: whether MPI is supported by this compiler or not.
:param output_flag: the compilation flag to use to indicate the name
of the output file
:param openmp_flag: the flag to use to enable OpenMP
:param openmp_flag: the flag to use to enable OpenMP. If no flag is
specified, it is assumed that the compiler does not support OpenMP.
:param availability_option: a command line option for the tool to test
if the tool is available on the current system. Defaults to
`--version`.
Expand Down Expand Up @@ -66,6 +67,12 @@ def mpi(self) -> bool:
'''Returns whether this compiler supports MPI or not.'''
return self._mpi

@property
def openmp(self) -> bool:
''':returns: if the compiler supports openmp or not
'''
return self._openmp_flag != ""

@property
def openmp_flag(self) -> str:
'''Returns the flag to enable OpenMP.'''
Expand Down Expand Up @@ -370,6 +377,7 @@ class Gcc(GnuVersionHandling, CCompiler):
:param name: name of this compiler.
:param exec_name: name of the executable.
:param mpi: whether the compiler supports MPI.
'''
def __init__(self,
name: str = "gcc",
Expand All @@ -385,6 +393,7 @@ class Gfortran(GnuVersionHandling, FortranCompiler):
:param name: name of this compiler.
:param exec_name: name of the executable.
:param mpi: whether the compiler supports MPI.
'''

def __init__(self, name: str = "gfortran",
Expand Down Expand Up @@ -435,6 +444,7 @@ class Icc(IntelVersionHandling, CCompiler):
:param name: name of this compiler.
:param exec_name: name of the executable.
:param mpi: whether the compiler supports MPI.
'''

def __init__(self, name: str = "icc", exec_name: str = "icc"):
Expand All @@ -448,6 +458,7 @@ class Ifort(IntelVersionHandling, FortranCompiler):
:param name: name of this compiler.
:param exec_name: name of the executable.
:param mpi: whether the compiler supports MPI.
'''

def __init__(self, name: str = "ifort", exec_name: str = "ifort"):
Expand Down
13 changes: 9 additions & 4 deletions source/fab/tools/tool_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ def add_tool(self, tool: Tool,
f"'{tool}'.")
self._all_tools[tool.category] = tool

def get_tool(self, category: Category, mpi: Optional[bool] = None) -> Tool:
def get_tool(self, category: Category, mpi: Optional[bool] = None,
openmp: Optional[bool] = None) -> Tool:
'''Returns the tool for the specified category.
:param category: the name of the category in which to look
for the tool.
:param mpi: if no compiler or linker is specified when requesting one,
use the MPI setting to find an appropriate default.
:param mpi: if no compiler or linker is explicitly specified in this
tool box, use the MPI and OpenMP setting to find an appropriate
default from the tool repository.
:param mpi: if no compiler or linker is explicitly specified in this
tool box, use the MPI and OpenMP setting to find an appropriate
default from the tool repository.
:raises KeyError: if the category is not known.
'''
Expand All @@ -69,6 +74,6 @@ def get_tool(self, category: Category, mpi: Optional[bool] = None) -> Tool:
# from the ToolRepository, and add it, so we don't need to look
# it up again later.
tr = ToolRepository()
tool = tr.get_default(category, mpi=mpi)
tool = tr.get_default(category, mpi=mpi, openmp=openmp)
self._all_tools[category] = tool
return tool
26 changes: 23 additions & 3 deletions source/fab/tools/tool_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def set_default_compiler_suite(self, suite: str):
f"in the suite '{suite}'.")

def get_default(self, category: Category,
mpi: Optional[bool] = None):
mpi: Optional[bool] = None,
openmp: Optional[bool] = None):
'''Returns the default tool for a given category. For most tools
that will be the first entry in the list of tools. The exception
are compilers and linker: in this case it must be specified if
Expand All @@ -147,6 +148,7 @@ def get_default(self, category: Category,
:param category: the category for which to return the default tool.
:param mpi: if a compiler or linker is required that supports MPI.
:param open: if a compiler or linker is required that supports OpenMP.
:raises KeyError: if the category does not exist.
:raises RuntimeError: if no compiler/linker is found with the
Expand All @@ -165,11 +167,29 @@ def get_default(self, category: Category,
raise RuntimeError(f"Invalid or missing mpi specification "
f"for '{category}'.")

if not isinstance(openmp, bool):
raise RuntimeError(f"Invalid or missing openmp specification "
f"for '{category}'.")

for tool in self[category]:
# If the tool supports/does not support MPI, return the first one
# If OpenMP is request, but the tool does not support openmp,
# ignore it.
if openmp and not tool.openmp:
continue
# If the tool supports/does not support MPI, return it.
if mpi == tool.mpi:
return tool

# Don't bother returning an MPI enabled tool if no-MPI is requested -
# that seems to be an unlikely scenario.
raise RuntimeError(f"Could not find '{category}' that supports MPI.")
if mpi:
if openmp:
raise RuntimeError(f"Could not find '{category}' that "
f"supports MPI and OpenMP.")
raise RuntimeError(f"Could not find '{category}' that "
f"supports MPI.")

if openmp:
raise RuntimeError(f"Could not find '{category}' that "
f"supports OpenMP.")
raise RuntimeError(f"Could not find any '{category}'.")
Loading

0 comments on commit d2be06c

Please sign in to comment.