1 C -*- Mode: Fortran; -*-
3 C (C) 2003 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
14 if (datatype .ne. MPI_INTEGER) then
15 write(6,*) 'Invalid datatype passed to user_op()'
21 cout(i) = cin(i) + cout(i)
28 integer inbuf(2), outbuf(2)
29 integer ans, rank, size, comm
36 call mtest_init( ierr )
38 C A simple test of exscan
41 call mpi_comm_rank( comm, rank, ierr )
42 call mpi_comm_size( comm, size, ierr )
46 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, MPI_SUM, comm,
48 C this process has the sum of i from 0 to rank-1, which is
49 C (rank)(rank-1)/2 and -i
50 ans = (rank * (rank - 1))/2
52 if (outbuf(1) .ne. ans) then
54 print *, rank, ' Expected ', ans, ' got ', outbuf(1)
56 if (outbuf(2) .ne. -ans) then
58 print *, rank, ' Expected ', -ans, ' got ', outbuf(1)
62 C Try a user-defined operation
64 call mpi_op_create( uop, .true., sumop, ierr )
67 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm,
69 C this process has the sum of i from 0 to rank-1, which is
70 C (rank)(rank-1)/2 and -i
71 ans = (rank * (rank - 1))/2
73 if (outbuf(1) .ne. ans) then
75 print *, rank, ' sumop: Expected ', ans, ' got ', outbuf(1)
77 if (outbuf(2) .ne. -ans) then
79 print *, rank, ' sumop: Expected ', -ans, ' got ', outbuf(1)
82 call mpi_op_free( sumop, ierr )
85 C Try a user-defined operation (and don't claim it is commutative)
87 call mpi_op_create( uop, .false., sumop, ierr )
90 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm,
92 C this process has the sum of i from 0 to rank-1, which is
93 C (rank)(rank-1)/2 and -i
94 ans = (rank * (rank - 1))/2
96 if (outbuf(1) .ne. ans) then
98 print *, rank, ' sumop2: Expected ', ans, ' got ', outbuf(1)
100 if (outbuf(2) .ne. -ans) then
102 print *, rank, ' sumop2: Expected ', -ans, ' got ',outbuf(1)
105 call mpi_op_free( sumop, ierr )
107 call mtest_finalize( errs )
108 call mpi_finalize( ierr )