Reduce integer data to root node
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(inout) | :: | array | |||
| integer, | intent(in) | :: | size | |||
| character(len=*), | intent(in) | :: | op | |||
| type(w90_error_type), | intent(out), | allocatable | :: | error | ||
| type(w90_comm_type), | intent(in) | :: | comm |
subroutine comms_no_sync_reduce_int(array, size, op, error, comm) !! Reduce integer data to root node implicit none integer, intent(inout) :: array integer, intent(in) :: size character(len=*), intent(in) :: op type(w90_comm_type), intent(in) :: comm type(w90_error_type), allocatable, intent(out) :: error #ifdef W90_MPI integer :: ierr integer :: rank rank = mpirank(comm) ! note, JJ 23/2/2021 ! previously this routine alloc'd/used/dealloc'd a temp array ! to be used as receive buffer for MPI_reduce ! this temp array was then copied to argument "array" ! but: "array" needs to be of scalar type for the polymorphism to work ! so: need to copy array into a (fake) scalar ! previously: a subroutine my_icopy was used to help to do this. ! probably just reducing in place is better? select case (op) case ('SUM') if (rank == root_id) then call mpi_reduce(MPI_IN_PLACE, array, size, MPI_INTEGER, MPI_SUM, root_id, comm%comm, & ierr) else call mpi_reduce(array, array, size, MPI_INTEGER, MPI_SUM, root_id, comm%comm, ierr) end if case ('PRD') if (rank == root_id) then call mpi_reduce(MPI_IN_PLACE, array, size, MPI_INTEGER, MPI_PROD, root_id, comm%comm, & ierr) else call mpi_reduce(array, array, size, MPI_INTEGER, MPI_PROD, root_id, comm%comm, ierr) end if case default call set_base_error(error, 'Unknown operation in comms_reduce_int', code_mpi) return end select if (ierr .ne. MPI_SUCCESS) then call set_base_error(error, 'Error in comms_reduce_int', code_mpi) return end if #endif end subroutine comms_no_sync_reduce_int