-
Notifications
You must be signed in to change notification settings - Fork 1
api/reduce #7
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
base: fix_proposed_structure
Are you sure you want to change the base?
api/reduce #7
Changes from 4 commits
e1af931
542a80d
d62b742
e219006
ecd0bf7
80a6f66
ebf7145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,13 @@ | |
|
|
||
| # IntelliJ | ||
| .idea/ | ||
| cmake-build-*/ | ||
| cmake-build-*/ | ||
|
|
||
| # Build Dirs | ||
| build/ | ||
|
|
||
| # Build Artifact | ||
| *.dylib | ||
| *.a | ||
| *.mod | ||
| *.o | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Generic Subroutine Templates | ||
| Store templates for the most generic form of a subroutine to be overloaded. Allowing rapid replication. | ||
|
|
||
| ## MPI_REDUCE | ||
| ```fortran | ||
| !> MPI_REDUCE WRAPPER: INTEGER | ||
| subroutine mpilib20_reduce_type(sendbuf, recvbuf, op, root, mpi_env) | ||
| use mpi_bindings, only : MPI_REDUCE, MPI_Op, & | ||
| MPI_TYPE | ||
| !> Variable containing set to be sent | ||
| type(MPI_TYPE), intent(in) :: sendbuf | ||
| !> Variable to receive reduced set | ||
| type(MPI_TYPE), intent(inout) :: recvbuf | ||
| !> MPI Operation | ||
| type(MPI_Op), intent(in) :: op | ||
| !> Rank of the process to receive the reduced set | ||
| integer, intent(in) :: root | ||
| !> Instance of the MPI environment | ||
| type(mpi_env_type), intent(inout) :: mpi_env | ||
|
|
||
| call MPI_REDUCE(sendbuf, recvbuf, 1, MPI_TYPE, op, root, mpi_env%comm, mpi_env%ierror) | ||
| end subroutine mpilib20_reduce_type | ||
| ```` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| !> Wrapping of the MPI_REDUCE methods | ||
| !> TODOs | ||
| !> Unravel how MPI_Datatype operates | ||
| !> Overload for MPI_IN_PLACE? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not entirely sure how
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MPI_IN_PLACE is actually quite complicated to overload - https://stackoverflow.com/questions/17741574/in-place-mpi-reduce-crashes-with-openmpi
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, makes sense to ignore in the first instance and add an issue to address. I've never needed to use personally and only seen it recently
|
||
| !> Testing | ||
| module mpilib20_reduce_m | ||
|
|
||
| use mpilib20_init_finalise, only : mpi_env_type | ||
|
|
||
| implicit none | ||
|
|
||
| private | ||
|
|
||
| interface mpilib20_reduce | ||
| module procedure mpilib20_reduce_int_scalar | ||
| module procedure mpilib20_reduce_int_vec | ||
| end interface | ||
|
|
||
| public :: mpilib20_REDUCE | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
|
|
||
| contains | ||
|
|
||
| !> MPI_REDUCE WRAPPER: INTEGER | ||
| subroutine mpilib20_reduce_int_scalar(sendbuf, recvbuf, operation, mpi_env, root) | ||
| use mpi_bindings, only : MPI_REDUCE, MPI_Op, & | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
| MPI_Datatype, MPI_INTEGER | ||
| use mpilib20_init_finalise, only : root_id | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
| !> Variable containing set to be sent | ||
| type(MPI_Datatype), intent(in) :: sendbuf | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
| !> Variable to receive reduced set | ||
| type(MPI_Datatype), intent(inout) :: recvbuf | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing this wants to be intent(out) as it shouldn't come in with a value
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For arrays, I assume intent(inout) is required as this will have to be preallocated? |
||
| !> MPI Operation | ||
| type(MPI_Op), intent(in) :: operation | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to pass the operation. This should be inferable from the input data type.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would MPI_MAX and MPI_MIN be infered? Same with MPI_PRODUCT and MPI_SUM?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I think we could make operation optional and have default behaviour as sum. My feeling is the majority of use cases are sum. Would also be easy to change.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| !> Instance of the MPI environment | ||
| type(mpi_env_type), intent(inout) :: mpi_env | ||
| !> Rank of the process to receive the reduced set (override default) | ||
| integer, optional, intent(in) :: root | ||
| integer :: use_root | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
|
|
||
| !> Overide root process if passed | ||
| if (present(root)) then | ||
| use_root = root | ||
| else | ||
| use_root = root_id | ||
| end if | ||
|
|
||
| call MPI_REDUCE(sendbuf, recvbuf, 1, MPI_INTEGER, operation, use_root, mpi_env%comm, mpi_env%ierror) | ||
|
|
||
| end subroutine mpilib20_reduce_int_scalar | ||
|
|
||
| !> MPI_REDUCE WRAPPER: INTEGER(:) | ||
| !> Rank 1 arrays don't require flattening | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
| subroutine mpilib20_reduce_int_vec(sendbuf, recvbuf, operation, mpi_env, root) | ||
| use mpi_bindings, only : MPI_REDUCE, MPI_Op, & | ||
| MPI_Datatype, MPI_INTEGER | ||
| use mpilib20_init_finalise, only : root_id | ||
| !> Variable containing set to be sent | ||
| type(MPI_Datatype), intent(in) :: sendbuf(:) | ||
| !> Variable to receive reduced set | ||
| type(MPI_Datatype), intent(inout) :: recvbuf(:) | ||
| !> MPI Operation | ||
| type(MPI_Op), intent(in) :: operation | ||
| !> Instance of the MPI environment | ||
| type(mpi_env_type), intent(inout) :: mpi_env | ||
| !> Rank of the process to receive the reduced set (override default) | ||
| integer, optional, intent(in) :: root | ||
| integer :: count | ||
| integer :: use_root | ||
|
|
||
| !> Overide root process if passed | ||
| if (present(root)) then | ||
| use_root = root | ||
| else | ||
| use_root = root_id | ||
| end if | ||
| !> Element count based-on receiving buffer size | ||
| count = size(recvbuf) | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
|
|
||
| call MPI_REDUCE(sendbuf, recvbuf, count, MPI_INTEGER, operation, root, mpi_env%comm, mpi_env%ierror) | ||
|
maxwilliams94 marked this conversation as resolved.
Outdated
|
||
|
|
||
| end subroutine mpilib20_reduce_int_vec | ||
|
|
||
| end module mpilib20_reduce_m | ||
Uh oh!
There was an error while loading. Please reload this page.