1 C -*- Mode: Fortran; -*-
3 C (C) 2011 by Argonne National Laboratory.
4 C See COPYRIGHT in top-level directory.
6 subroutine uop( cin, cout, count, datatype )
9 integer cin(*), cout(*)
10 integer count, datatype
13 ! if (datatype .ne. MPI_INTEGER) then
14 ! write(6,*) 'Invalid datatype ',datatype,' passed to user_op()'
19 cout(i) = cin(i) + cout(i)
23 C Test of reduce scatter.
25 C Each processor contributes its rank + the index to the reduction,
26 C then receives the ith sum
28 C Can be called with any number of processors.
34 integer errs, ierr, toterr
36 parameter (maxsize=1024)
37 integer sendbuf(maxsize), recvbuf, recvcounts(maxsize)
38 integer size, rank, i, sumval
44 call mtest_init( ierr )
48 call mpi_comm_size( comm, size, ierr )
49 call mpi_comm_rank( comm, rank, ierr )
51 if (size .gt. maxsize) then
54 sendbuf(i) = rank + i - 1
58 call mpi_reduce_scatter( sendbuf, recvbuf, recvcounts,
59 & MPI_INTEGER, MPI_SUM, comm, ierr )
61 sumval = size * rank + ((size - 1) * size)/2
62 C recvbuf should be size * (rank + i)
63 if (recvbuf .ne. sumval) then
65 print *, "Did not get expected value for reduce scatter"
66 print *, rank, " Got ", recvbuf, " expected ", sumval
69 call mpi_op_create( uop, .true., sumop, ierr )
70 call mpi_reduce_scatter( sendbuf, recvbuf, recvcounts,
71 & MPI_INTEGER, sumop, comm, ierr )
73 sumval = size * rank + ((size - 1) * size)/2
74 C recvbuf should be size * (rank + i)
75 if (recvbuf .ne. sumval) then
77 print *, "sumop: Did not get expected value for reduce scatter"
78 print *, rank, " Got ", recvbuf, " expected ", sumval
80 call mpi_op_free( sumop, ierr )
82 call mtest_finalize( errs )
83 call mpi_finalize( ierr )