1program test_reduce 2 use libmpifx_module 3 implicit none 4 5 integer, parameter :: dp = kind(1.0d0) 6 7 type(mpifx_comm) :: mycomm 8 integer :: vali0, resvali0 9 real(dp) :: valr(3), resvalr(3) 10 11 call mpifx_init() 12 call mycomm%init() 13 14 ! Reduction of a scalarw 15 vali0 = mycomm%rank * 2 16 write(*, "(I2.2,'-',I3.3,'|',1X,A,I0)") 1, mycomm%rank, & 17 & "Value to be operated on:", vali0 18 call mpifx_reduce(mycomm, vali0, resvali0, MPI_SUM) 19 write(*, "(I2.2,'-',I3.3,'|',1X,A,I0)") 2, mycomm%rank, & 20 & "Obtained result (sum):", resvali0 21 22 ! Reduction of an array 23 valr(:) = [ real(mycomm%rank + 1, dp) * 1.2, & 24 & real(mycomm%rank + 1, dp) * 4.3, real(mycomm%rank + 1, dp) * 3.8 ] 25 resvalr(:) = 0.0_dp 26 write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 3, mycomm%rank, & 27 & "Value to be operated on:", valr(:) 28 call mpifx_reduce(mycomm, valr, resvalr, MPI_PROD) 29 write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 4, mycomm%rank, & 30 & "Obtained result (prod):", resvalr(:) 31 32 ! In place summation 33 resvalr(:) = [ real(mycomm%rank + 1, dp) * 1.2, & 34 & real(mycomm%rank + 1, dp) * 4.3, real(mycomm%rank + 1, dp) * 3.8 ] 35 write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 5, mycomm%rank, & 36 & "Value to be operated on:", resvalr(:) 37 call mpifx_reduceip(mycomm, resvalr, MPI_SUM) 38 write(*, "(I2.2,'-',I3.3,'|',1X,A,3F8.2)") 6, mycomm%rank, & 39 & "Obtained result (sum):", resvalr(:) 40 41 call mpifx_finalize() 42 43end program test_reduce 44