-
Notifications
You must be signed in to change notification settings - Fork 8
Restructure offline drivers #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| ! CSIRO Open Source Software License Agreement (variation of the BSD / MIT License) | ||
| ! Copyright (c) 2015, Commonwealth Scientific and Industrial Research Organisation | ||
| ! (CSIRO) ABN 41 687 119 230. | ||
|
|
||
| MODULE cable_mpi_mod | ||
micaeljtoliveira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| !! Module for handling some common MPI operations and MPI groups | ||
| #ifdef __MPI__ | ||
| USE mpi | ||
| #endif | ||
| USE iso_fortran_env, ONLY : error_unit | ||
| IMPLICIT NONE | ||
|
|
||
| PRIVATE | ||
| PUBLIC :: & | ||
| mpi_grp_t, & | ||
| mpi_mod_init, & | ||
| mpi_mod_end, & | ||
| mpi_check_error | ||
|
|
||
| INTEGER, PARAMETER :: MPI_COMM_UNDEFINED = -1 | ||
|
|
||
| INTEGER :: default_comm ! Default communicator to use when creating groups | ||
|
|
||
| TYPE mpi_grp_t | ||
| !* Class to handle MPI groups. | ||
| ! This class stores information about the group and | ||
| ! the current proccess. | ||
| INTEGER :: comm = MPI_COMM_UNDEFINED !! Communicator | ||
| INTEGER :: rank = -1 !! Rank of the current process | ||
| INTEGER :: size = -1 !! Size of the communicator | ||
| CONTAINS | ||
| PROCEDURE :: abort => mpi_grp_abort !! Send abort signal to processes in this group | ||
| END TYPE mpi_grp_t | ||
|
|
||
| INTERFACE mpi_grp_t | ||
| !* Overload the default construct for mpi_grp_t | ||
| PROCEDURE mpi_grp_constructor | ||
| END INTERFACE mpi_grp_t | ||
|
|
||
| CONTAINS | ||
|
|
||
| SUBROUTINE mpi_mod_init() | ||
| !* Initialise MPI and set default communicator. | ||
| ! | ||
| ! The default communicator is set to MPI_COMM_WORLD if MPI support is | ||
| ! available or to MPI_COMM_UNDEFINED if not. | ||
| #ifdef __MPI__ | ||
| INTEGER :: ierr | ||
|
|
||
| CALL MPI_Init(ierr) | ||
| CALL mpi_check_error(ierr) | ||
| default_comm = MPI_COMM_WORLD | ||
| #else | ||
| default_comm = MPI_COMM_UNDEFINED | ||
| #endif | ||
|
|
||
| END SUBROUTINE mpi_mod_init | ||
|
|
||
| SUBROUTINE mpi_mod_end() | ||
| !* Finalise MPI. | ||
| #ifdef __MPI__ | ||
| INTEGER :: ierr | ||
|
|
||
| IF (default_comm /= MPI_COMM_UNDEFINED) THEN | ||
| CALL MPI_Finalize(ierr) | ||
| CALL mpi_check_error(ierr) | ||
| END IF | ||
| #endif | ||
|
|
||
| END SUBROUTINE mpi_mod_end | ||
|
|
||
|
|
||
| FUNCTION mpi_grp_constructor(comm) RESULT(mpi_grp) | ||
| !* Contructor for mpi_grp_t class. | ||
| ! | ||
| ! This sets the communicator of the group and gets the size of the group and | ||
| ! rank of current process. If no communicator is provided, it will use | ||
| ! the default defined when calling mpi_mod_init. | ||
| ! | ||
| ! Note that when the undefined communicator is used, the group size is 1 and | ||
| ! the rank to 0, such that the code can work in serial mode. | ||
| INTEGER, INTENT(IN), OPTIONAL :: comm !! MPI communicator | ||
| TYPE(mpi_grp_t) :: mpi_grp | ||
|
|
||
| INTEGER :: ierr | ||
|
|
||
| IF (PRESENT(comm)) THEN | ||
| #ifdef __MPI__ | ||
| CALL MPI_Comm_dup(comm, mpi_grp%comm, ierr) | ||
| call mpi_check_error(ierr) | ||
| #else | ||
| mpi_grp%comm = comm | ||
| #endif | ||
| ELSE | ||
| #ifdef __MPI__ | ||
| CALL MPI_Comm_dup(default_comm, mpi_grp%comm, ierr) | ||
| call mpi_check_error(ierr) | ||
| #else | ||
| mpi_grp%comm = default_comm | ||
| #endif | ||
| END IF | ||
|
|
||
| IF (mpi_grp%comm /= MPI_COMM_UNDEFINED) THEN | ||
| #ifdef __MPI__ | ||
| call MPI_Comm_rank(mpi_grp%comm, mpi_grp%rank, ierr) | ||
| call mpi_check_error(ierr) | ||
|
|
||
| call MPI_Comm_size(mpi_grp%comm, mpi_grp%size, ierr) | ||
| call mpi_check_error(ierr) | ||
| #else | ||
| WRITE(error_unit,*) "Error initialising mpi group: CABLE was compiled without MPI support." | ||
| STOP | ||
| #endif | ||
| ELSE | ||
| mpi_grp%rank = 0 | ||
| mpi_grp%size = 1 | ||
| END IF | ||
|
|
||
| END FUNCTION mpi_grp_constructor | ||
|
|
||
| SUBROUTINE mpi_grp_abort(this) | ||
| !* Class method to abort execution of an MPI group. | ||
| CLASS(mpi_grp_t), INTENT(IN) :: this | ||
|
|
||
| INTEGER :: ierr | ||
|
|
||
| IF (this%comm /= MPI_COMM_UNDEFINED) THEN | ||
| ! Here we use an arbitrary error code | ||
| #ifdef __MPI__ | ||
| call MPI_Abort(this%comm, 999, ierr) | ||
| #endif | ||
| call mpi_check_error(ierr) | ||
| END IF | ||
|
|
||
| END SUBROUTINE mpi_grp_abort | ||
|
|
||
| SUBROUTINE mpi_check_error(ierr) | ||
| !* Check if an MPI return code signaled an error. If so, print the | ||
| ! corresponding message and abort the execution. | ||
| INTEGER, INTENT(IN) :: ierr !! Error code | ||
|
|
||
| #ifdef __MPI__ | ||
| CHARACTER(len=MPI_MAX_ERROR_STRING) :: msg | ||
| INTEGER :: length, tmp | ||
|
|
||
| IF (ierr /= MPI_SUCCESS ) THEN | ||
| CALL MPI_Error_String(ierr, msg, length, tmp) | ||
| WRITE(error_unit,*) msg(1:length) | ||
| CALL MPI_Abort(MPI_COMM_WORLD, 1 , tmp) | ||
| END if | ||
| #endif | ||
|
|
||
| END SUBROUTINE mpi_check_error | ||
|
|
||
| END MODULE cable_mpi_mod | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ! CSIRO Open Source Software License Agreement (variation of the BSD / MIT License) | ||
| ! Copyright (c) 2015, Commonwealth Scientific and Industrial Research Organisation | ||
| ! (CSIRO) ABN 41 687 119 230. | ||
|
|
||
| MODULE cable_mpimaster | ||
| !! Stub for the master driver when MPI is not available. | ||
| IMPLICIT NONE | ||
|
|
||
| PRIVATE | ||
| PUBLIC :: mpidrv_master | ||
|
|
||
| CONTAINS | ||
|
|
||
| SUBROUTINE mpidrv_master(comm) | ||
micaeljtoliveira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| !! Stub for when MPI is not available | ||
| INTEGER, INTENT(IN) :: comm | ||
|
|
||
| ! This should never be called! | ||
| STOP | ||
|
|
||
| END SUBROUTINE mpidrv_master | ||
|
|
||
| END MODULE cable_mpimaster | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, this will break benchcab for the case both
cableandcable-mpiexecutables are needed as benchcab will only invokecmakeonce to build both executables. However benchcab will still work with these changes for serial only (benchcab fluxsite) and mpi only (benchcab spatial) tests (FYI @ccarouge).It would be good to think about the proper CMake workflow for building different variants of the cable executable (e.g. MPI on/off, Debug, Release, compiler). From reading online, it seems the typical approach for doing this is to generate separate build trees for each variant unless we work with a multiconfig build system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's the usual strategy. CABLE is quite fast to compile, so this should not be an issue.
One thing you might want to explore to make this process easier is the use of CMake presets. These are really nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #485