Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ cmake-build-*/
/build

# Documentation is generated by the build system
/documentation
/documentation

# Build Artifact
*.dylib
*.a
*.mod
*.o
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ include_directories("${CMAKE_SOURCE_DIR}/src")
set(SOURCE_CODE
src/mpilib20.F90
src/routines/mpilib20_init_finalise.F90
src/routines/mpilib20_reduce.F90
src/bindings/mpi_bindings.F90
src/errors_warnings/asserts.F90
src/utilities/internal_utils.F90
PARENT_SCOPE
)
12 changes: 8 additions & 4 deletions src/bindings/mpi_bindings.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ module mpi_bindings
MPI_COMM_SIZE, &
MPI_GROUP_SIZE, &
MPI_INITIALIZED, &
MPI_REDUCE, &

! Data types
MPI_COMM_WORLD, &
MPI_THREAD_SINGLE, &
MPI_THREAD_FUNNELED, &
MPI_THREAD_SERIALIZED, &
MPI_THREAD_MULTIPLE, &
MPI_INTEGER, &

! Derived types
MPI_Comm, &
Expand Down Expand Up @@ -59,13 +61,15 @@ module mpi_bindings
MPI_COMM_SIZE, &
MPI_GROUP_SIZE, &
MPI_INITIALIZED, &
MPI_REDUCE, &

! Data types
MPI_COMM_WORLD, &
MPI_THREAD_SINGLE, &
MPI_THREAD_FUNNELED, &
MPI_COMM_WORLD, &
MPI_THREAD_SINGLE, &
MPI_THREAD_FUNNELED, &
MPI_THREAD_SERIALIZED, &
MPI_THREAD_MULTIPLE
MPI_THREAD_MULTIPLE, &
MPI_INTEGER

implicit none
public
Expand Down
94 changes: 94 additions & 0 deletions src/routines/mpilib20_reduce.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
!> Wrapping of the MPI_REDUCE methods
!> TODOs
!> Up to rank 3 arrays
!> Remaining types (parametized derived types for precisions?)
!> real(sp), real(dp), real(qp)
!> complex
!> Overload for MPI_IN_PLACE - optional logical could work
!> Testing
!> Refactor when root_id moved to mpi_env_type
module mpilib20_reduce_m

use mpilib20_init_finalise, only : mpi_env_type, root_id
use mpi_bindings, only : MPI_REDUCE, MPI_Op, &
MPI_INTEGER

implicit none

private

interface mpilib20_reduce
module procedure mpilib20_reduce_int_scalar
module procedure mpilib20_reduce_int_vec
end interface

public :: mpilib20_reduce

contains


!> Reduces values on all processes to a single value
!> on process defined by process_id
!> TODO usage examples
subroutine mpilib20_reduce_int_scalar(sendbuf, recvbuf, &
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we want to line-split (to keep lines below 90 characters(?)). Here I've split after argument 2 because otherwise one goes over 90, but then operation (potentially being removed soon anyway) and mpi_env are grouped. I've put optional arguments on their own line

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not going over 90 (unless a comment) sounds sensible. I often like to put inputs and outputs on different lines but if we retain a consistent arg ordering with MPI commands, then clearly we can't. In which case do whatever looks neat. Not a fan of putting optionals on their own line.

More broadly we should introduce fprettify and set it up how we like, then we can just run it to apply consistent formatting

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 90 characters sounds good. Do what you think looks readable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep it neat without putting optional arguments on their own line.

Sounds good re fprettify. We should get a config file written for it relatively soon. Once I commit these PR changes I'll have a good and see what get produced.

operation, mpi_env, &
process_id)
!> Variable containing set to be sent
type(MPI_INTEGER), intent(in) :: sendbuf
!> Variable to receive reduced set
type(MPI_INTEGER), intent(out) :: recvbuf
!> MPI Operation
type(MPI_Op), intent(in) :: operation
!> Instance of the MPI environment
type(mpi_env_type), intent(out) :: mpi_env
!> Rank of the process to receive the reduced set (override default)
integer, optional, intent(in) :: process_id
integer :: process

!> Overide root process if passed
if (present(process_id)) then
process = process_id
else
process = root_id
end if

call MPI_REDUCE(sendbuf, recvbuf, 1, MPI_INTEGER, operation, process, &
mpi_env%comm, mpi_env%ierror)

end subroutine mpilib20_reduce_int_scalar


!> Reduces values on all processes to a single value
!> on process defined by process_id
!> TODO usage examples
subroutine mpilib20_reduce_int_vec(sendbuf, recvbuf, &
operation, mpi_env, &
process_id)
!> Variable containing set to be sent
type(MPI_INTEGER), intent(in) :: sendbuf(:)
!> Variable to receive reduced set
type(MPI_INTEGER), 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) :: process_id
integer :: process

!> Overide root process if passed
if (present(process_id)) then
process = process_id
else
process = root_id
end if

call assert(size(sendbuf) == size(recvbuf), "size(sendbuf) /= size(recvbuf)")

call MPI_REDUCE(sendbuf, recvbuf, size(recvbuf), MPI_INTEGER, operation, process, &
mpi_env%comm, mpi_env%ierror)

end subroutine mpilib20_reduce_int_vec


end module mpilib20_reduce_m