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