1 C -*- Mode: Fortran; -*-
3 C (C) 2011 by Argonne National Laboratory.
4 C See COPYRIGHT in top-level directory.
6 C Test of reduce scatter.
8 C Each processor contributes its rank + the index to the reduction,
9 C then receives the ith sum
11 C Can be called with any number of processors.
17 integer errs, ierr, toterr
19 parameter (maxsize=1024)
20 integer sendbuf(maxsize), recvbuf, recvcounts(maxsize)
21 integer size, rank, i, sumval
27 call mtest_init( ierr )
31 call mpi_comm_size( comm, size, ierr )
32 call mpi_comm_rank( comm, rank, ierr )
34 if (size .gt. maxsize) then
37 sendbuf(i) = rank + i - 1
41 call mpi_reduce_scatter( sendbuf, recvbuf, recvcounts,
42 & MPI_INTEGER, MPI_SUM, comm, ierr )
44 sumval = size * rank + ((size - 1) * size)/2
45 C recvbuf should be size * (rank + i)
46 if (recvbuf .ne. sumval) then
48 print *, "Did not get expected value for reduce scatter"
49 print *, rank, " Got ", recvbuf, " expected ", sumval
52 call mpi_op_create( uop, .true., sumop, ierr )
53 call mpi_reduce_scatter( sendbuf, recvbuf, recvcounts,
54 & MPI_INTEGER, sumop, comm, ierr )
56 sumval = size * rank + ((size - 1) * size)/2
57 C recvbuf should be size * (rank + i)
58 if (recvbuf .ne. sumval) then
60 print *, "sumop: Did not get expected value for reduce scatter"
61 print *, rank, " Got ", recvbuf, " expected ", sumval
63 call mpi_op_free( sumop, ierr )
65 call mtest_finalize( errs )
66 call mpi_finalize( ierr )
70 subroutine uop( cin, cout, count, datatype )
73 integer cin(*), cout(*)
74 integer count, datatype
78 if (datatype .ne. MPI_INTEGER) then
79 write(6,*) 'Invalid datatype ',datatype,
80 & ' passed to user_op()'
86 cout(i) = cin(i) + cout(i)