| 1 |
C |
| 2 |
C Copyright (C) by Argonne National Laboratory |
| 3 |
C See COPYRIGHT in top-level directory |
| 4 |
C |
| 5 |
|
| 6 |
program main |
| 7 |
implicit none |
| 8 |
include 'mpif.h' |
| 9 |
integer errs, ierr |
| 10 |
include 'attraints.h' |
| 11 |
integer comm1, comm2 |
| 12 |
integer curcount, keyval |
| 13 |
logical flag |
| 14 |
external mycopyfn, mydelfn |
| 15 |
integer callcount, delcount |
| 16 |
common /myattr/ callcount, delcount |
| 17 |
C |
| 18 |
C The only difference between the MPI-2 and MPI-1 attribute caching |
| 19 |
C routines in Fortran is that the take an address-sized integer |
| 20 |
C instead of a simple integer. These still are not pointers, |
| 21 |
C so the values are still just integers. |
| 22 |
C |
| 23 |
errs = 0 |
| 24 |
callcount = 0 |
| 25 |
delcount = 0 |
| 26 |
call mtest_init( ierr ) |
| 27 |
call mpi_comm_dup( MPI_COMM_WORLD, comm1, ierr ) |
| 28 |
C |
| 29 |
extrastate = 1001 |
| 30 |
call mpi_comm_create_keyval( mycopyfn, mydelfn, keyval, |
| 31 |
& extrastate, ierr ) |
| 32 |
flag = .true. |
| 33 |
call mpi_comm_get_attr( comm1, keyval, valout, flag, ierr ) |
| 34 |
if (flag) then |
| 35 |
errs = errs + 1 |
| 36 |
print *, ' get attr returned true when no attr set' |
| 37 |
endif |
| 38 |
|
| 39 |
valin = 2003 |
| 40 |
call mpi_comm_set_attr( comm1, keyval, valin, ierr ) |
| 41 |
flag = .false. |
| 42 |
valout = -1 |
| 43 |
call mpi_comm_get_attr( comm1, keyval, valout, flag, ierr ) |
| 44 |
if (valout .ne. 2003) then |
| 45 |
errs = errs + 1 |
| 46 |
print *, 'Unexpected value (should be 2003)', valout, |
| 47 |
& ' from attr' |
| 48 |
endif |
| 49 |
|
| 50 |
valin = 2001 |
| 51 |
call mpi_comm_set_attr( comm1, keyval, valin, ierr ) |
| 52 |
flag = .false. |
| 53 |
valout = -1 |
| 54 |
call mpi_comm_get_attr( comm1, keyval, valout, flag, ierr ) |
| 55 |
if (valout .ne. 2001) then |
| 56 |
errs = errs + 1 |
| 57 |
print *, 'Unexpected value (should be 2001)', valout, |
| 58 |
& ' from attr' |
| 59 |
endif |
| 60 |
|
| 61 |
C |
| 62 |
C Test the copy function |
| 63 |
valin = 5001 |
| 64 |
call mpi_comm_set_attr( comm1, keyval, valin, ierr ) |
| 65 |
call mpi_comm_dup( comm1, comm2, ierr ) |
| 66 |
flag = .false. |
| 67 |
call mpi_comm_get_attr( comm1, keyval, valout, flag, ierr ) |
| 68 |
if (valout .ne. 5001) then |
| 69 |
errs = errs + 1 |
| 70 |
print *, 'Unexpected output value in comm ', valout |
| 71 |
endif |
| 72 |
flag = .false. |
| 73 |
call mpi_comm_get_attr( comm2, keyval, valout, flag, ierr ) |
| 74 |
if (valout .ne. 5003) then |
| 75 |
errs = errs + 1 |
| 76 |
print *, 'Unexpected output value in comm2 ', valout |
| 77 |
endif |
| 78 |
C Test the delete function |
| 79 |
curcount = delcount |
| 80 |
call mpi_comm_free( comm2, ierr ) |
| 81 |
if (delcount .ne. curcount + 1) then |
| 82 |
errs = errs + 1 |
| 83 |
print *, ' did not get expected value of delcount ', |
| 84 |
& delcount, curcount + 1 |
| 85 |
endif |
| 86 |
C |
| 87 |
C Test the attr delete function |
| 88 |
call mpi_comm_dup( comm1, comm2, ierr ) |
| 89 |
valin = 6001 |
| 90 |
extrastate = 1001 |
| 91 |
call mpi_comm_set_attr( comm2, keyval, valin, ierr ) |
| 92 |
delcount = 0 |
| 93 |
call mpi_comm_delete_attr( comm2, keyval, ierr ) |
| 94 |
if (delcount .ne. 1) then |
| 95 |
errs = errs + 1 |
| 96 |
print *, ' Delete_attr did not call delete function' |
| 97 |
endif |
| 98 |
flag = .true. |
| 99 |
call mpi_comm_get_attr( comm2, keyval, valout, flag, ierr ) |
| 100 |
if (flag) then |
| 101 |
errs = errs + 1 |
| 102 |
print *, ' Delete_attr did not delete attribute' |
| 103 |
endif |
| 104 |
call mpi_comm_free( comm2, ierr ) |
| 105 |
C |
| 106 |
ierr = -1 |
| 107 |
call mpi_comm_free_keyval( keyval, ierr ) |
| 108 |
if (ierr .ne. MPI_SUCCESS) then |
| 109 |
errs = errs + 1 |
| 110 |
call mtestprinterror( ierr ) |
| 111 |
endif |
| 112 |
call mpi_comm_free( comm1, ierr ) |
| 113 |
|
| 114 |
call mtest_finalize( errs ) |
| 115 |
end |
| 116 |
C |
| 117 |
subroutine mycopyfn( oldcomm, keyval, extrastate, valin, valout, |
| 118 |
& flag, ierr ) |
| 119 |
implicit none |
| 120 |
include 'mpif.h' |
| 121 |
integer oldcomm, keyval, ierr |
| 122 |
include 'attraints.h' |
| 123 |
logical flag |
| 124 |
integer callcount, delcount |
| 125 |
common /myattr/ callcount, delcount |
| 126 |
C increment the attribute by 2 |
| 127 |
valout = valin + 2 |
| 128 |
callcount = callcount + 1 |
| 129 |
if (extrastate .eq. 1001) then |
| 130 |
flag = .true. |
| 131 |
ierr = MPI_SUCCESS |
| 132 |
else |
| 133 |
print *, ' Unexpected value of extrastate = ', extrastate |
| 134 |
flag = .false. |
| 135 |
ierr = MPI_ERR_OTHER |
| 136 |
endif |
| 137 |
end |
| 138 |
C |
| 139 |
subroutine mydelfn( comm, keyval, val, extrastate, ierr ) |
| 140 |
implicit none |
| 141 |
include 'mpif.h' |
| 142 |
integer comm, keyval, ierr |
| 143 |
include 'attraints.h' |
| 144 |
integer callcount, delcount |
| 145 |
common /myattr/ callcount, delcount |
| 146 |
delcount = delcount + 1 |
| 147 |
if (extrastate .eq. 1001) then |
| 148 |
ierr = MPI_SUCCESS |
| 149 |
else |
| 150 |
print *, ' Unexpected value of extrastate = ', extrastate |
| 151 |
ierr = MPI_ERR_OTHER |
| 152 |
endif |
| 153 |
end |