1 ! This file created from test/mpi/f77/coll/exscanf.f with f77tof90
2 ! -*- Mode: Fortran; -*-
4 ! (C) 2003 by Argonne National Laboratory.
5 ! See COPYRIGHT in top-level directory.
9 integer, dimension(:), allocatable :: inbuf, outbuf
10 integer ans, rank, size, comm
14 allocate(inbuf(2), STAT=status)
15 allocate(outbuf(2), STAT=status)
18 call mtest_init( ierr )
20 ! A simple test of exscan
23 call mpi_comm_rank( comm, rank, ierr )
24 call mpi_comm_size( comm, size, ierr )
28 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, MPI_SUM, comm, &
30 ! this process has the sum of i from 0 to rank-1, which is
31 ! (rank)(rank-1)/2 and -i
32 ans = (rank * (rank - 1))/2
34 if (outbuf(1) .ne. ans) then
36 print *, rank, ' Expected ', ans, ' got ', outbuf(1)
38 if (outbuf(2) .ne. -ans) then
40 print *, rank, ' Expected ', -ans, ' got ', outbuf(1)
44 ! Try a user-defined operation
46 call mpi_op_create( uop, .true., sumop, ierr )
49 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm, &
51 ! this process has the sum of i from 0 to rank-1, which is
52 ! (rank)(rank-1)/2 and -i
53 ans = (rank * (rank - 1))/2
55 if (outbuf(1) .ne. ans) then
57 print *, rank, ' sumop: Expected ', ans, ' got ', outbuf(1)
59 if (outbuf(2) .ne. -ans) then
61 print *, rank, ' sumop: Expected ', -ans, ' got ', outbuf(1)
64 call mpi_op_free( sumop, ierr )
67 ! Try a user-defined operation (and don't claim it is commutative)
69 call mpi_op_create( uop, .false., sumop, ierr )
72 call mpi_exscan( inbuf, outbuf, 2, MPI_INTEGER, sumop, comm, &
74 ! this process has the sum of i from 0 to rank-1, which is
75 ! (rank)(rank-1)/2 and -i
76 ans = (rank * (rank - 1))/2
78 if (outbuf(1) .ne. ans) then
80 print *, rank, ' sumop2: Expected ', ans, ' got ', outbuf(1)
82 if (outbuf(2) .ne. -ans) then
84 print *, rank, ' sumop2: Expected ', -ans, ' got ',outbuf(1)
87 call mpi_op_free( sumop, ierr )
90 call mtest_finalize( errs )
91 call mpi_finalize( ierr )
94 subroutine uop( cin, cout, count, datatype )
96 integer cin(*), cout(*)
97 integer count, datatype
101 if (datatype .ne. MPI_INTEGER) then
102 write(6,*) 'Invalid datatype passed to user_op()'
108 cout(i) = cin(i) + cout(i)