1 C -*- Mode: Fortran; -*-
3 C (C) 2003 by Argonne National Laboratory.
4 C See COPYRIGHT in top-level directory.
9 integer inbuf(2), outbuf(2)
10 integer ans, rank, size, comm
17 call mtest_init( ierr )
19 C A simple test of exscan
22 call mpi_comm_rank( comm, rank, ierr )
23 call mpi_comm_size( comm, size, ierr )
27 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, MPI_SUM, comm,
29 C this process has the sum of i from 0 to rank-1, which is
30 C (rank)(rank-1)/2 and -i
31 ans = (rank * (rank - 1))/2
33 if (outbuf(1) .ne. ans) then
35 print *, rank, ' Expected ', ans, ' got ', outbuf(1)
37 if (outbuf(2) .ne. -ans) then
39 print *, rank, ' Expected ', -ans, ' got ', outbuf(1)
43 C Try a user-defined operation
45 call mpi_op_create( uop, .true., sumop, ierr )
48 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm,
50 C this process has the sum of i from 0 to rank-1, which is
51 C (rank)(rank-1)/2 and -i
52 ans = (rank * (rank - 1))/2
54 if (outbuf(1) .ne. ans) then
56 print *, rank, ' sumop: Expected ', ans, ' got ', outbuf(1)
58 if (outbuf(2) .ne. -ans) then
60 print *, rank, ' sumop: Expected ', -ans, ' got ', outbuf(1)
63 call mpi_op_free( sumop, ierr )
66 C Try a user-defined operation (and don't claim it is commutative)
68 call mpi_op_create( uop, .false., sumop, ierr )
71 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm,
73 C this process has the sum of i from 0 to rank-1, which is
74 C (rank)(rank-1)/2 and -i
75 ans = (rank * (rank - 1))/2
77 if (outbuf(1) .ne. ans) then
79 print *, rank, ' sumop2: Expected ', ans, ' got ', outbuf(1)
81 if (outbuf(2) .ne. -ans) then
83 print *, rank, ' sumop2: Expected ', -ans, ' got ',outbuf(1)
86 call mpi_op_free( sumop, ierr )
88 call mtest_finalize( errs )
89 call mpi_finalize( ierr )
92 subroutine uop( cin, cout, count, datatype )
95 integer cin(*), cout(*)
96 integer count, datatype
100 if (datatype .ne. MPI_INTEGER) then
101 write(6,*) 'Invalid datatype passed to user_op()'
107 cout(i) = cin(i) + cout(i)