1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
!
! Copyright (C) by Argonne National Laboratory
! See COPYRIGHT in top-level directory
!
! This file created from test/mpi/f77/coll/reducelocalf.f with f77tof90
!
! Test Fortran MPI_Reduce_local with MPI_OP_SUM and with user-defined operation.
!
subroutine user_op( invec, outvec, count, datatype )
use mpi_f08
integer invec(*), outvec(*)
integer count
TYPE(MPI_Datatype) datatype
integer ii
if (datatype .ne. MPI_INTEGER) then
write(6,*) 'Invalid datatype passed to user_op()'
return
endif
do ii=1, count
outvec(ii) = invec(ii) * 2 + outvec(ii)
enddo
end
program main
use mpi_f08
integer max_buf_size
parameter (max_buf_size=65000)
integer vin(max_buf_size), vout(max_buf_size)
external user_op
integer ierr, errs
integer count
TYPE(MPI_Op) myop
integer ii
errs = 0
call mtest_init(ierr)
count = 0
do while (count .le. max_buf_size )
do ii = 1,count
vin(ii) = ii
vout(ii) = ii
enddo
call mpi_reduce_local( vin, vout, count, &
& MPI_INTEGER, MPI_SUM, ierr )
! Check if the result is correct
do ii = 1,count
if ( vin(ii) .ne. ii ) then
errs = errs + 1
endif
if ( vout(ii) .ne. 2*ii ) then
errs = errs + 1
endif
enddo
if ( count .gt. 0 ) then
count = count + count
else
count = 1
endif
enddo
call mpi_op_create( user_op, .false., myop, ierr )
count = 0
do while (count .le. max_buf_size)
do ii = 1, count
vin(ii) = ii
vout(ii) = ii
enddo
call mpi_reduce_local( vin, vout, count, &
& MPI_INTEGER, myop, ierr )
! Check if the result is correct
do ii = 1, count
if ( vin(ii) .ne. ii ) then
errs = errs + 1
endif
if ( vout(ii) .ne. 3*ii ) then
errs = errs + 1
endif
enddo
if ( count .gt. 0 ) then
count = count + count
else
count = 1
endif
enddo
call mpi_op_free( myop, ierr )
call mtest_finalize(errs)
end
|