Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill trailing whitespaces in teshsuite/smpi/{isp,mpich3-test}.
[simgrid.git] / teshsuite / smpi / mpich3-test / f77 / attr / typeattrf.f
1 C -*- Mode: Fortran; -*-
2 C
3 C  (C) 2003 by Argonne National Laboratory.
4 C      See COPYRIGHT in top-level directory.
5 C
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 C
108 C Avoid memory leak
109       ierr = -1
110       call mpi_type_delete_attr( type1, keyval, ierr )
111       if (ierr .ne. MPI_SUCCESS) then
112          errs = errs + 1
113          call mtestprinterror( ierr )
114       endif
115 C
116       ierr = -1
117       call mpi_type_free_keyval( keyval, ierr )
118       if (ierr .ne. MPI_SUCCESS) then
119          errs = errs + 1
120          call mtestprinterror( ierr )
121       endif
122
123       call mtest_finalize( errs )
124       call mpi_finalize( ierr )
125       end
126 C
127       subroutine mycopyfn( oldtype, keyval, extrastate, valin, valout,
128      &                     flag, ierr )
129       implicit none
130       include 'mpif.h'
131       integer oldtype, keyval, ierr
132       include 'attraints.h'
133       logical flag
134       integer callcount, delcount
135       common /myattr/ callcount, delcount
136 C increment the attribute by 2
137       valout = valin + 2
138       callcount = callcount + 1
139       if (extrastate .eq. 1001) then
140          flag = .true.
141          ierr = MPI_SUCCESS
142       else
143          print *, ' Unexpected value of extrastate = ', extrastate
144          flag = .false.
145          ierr = MPI_ERR_OTHER
146       endif
147       end
148 C
149       subroutine mydelfn( type, keyval, val, extrastate, ierr )
150       implicit none
151       include 'mpif.h'
152       integer type, keyval, ierr
153       include 'attraints.h'
154       integer callcount, delcount
155       common /myattr/ callcount, delcount
156       delcount = delcount + 1
157       if (extrastate .eq. 1001) then
158          ierr = MPI_SUCCESS
159       else
160          print *, ' Unexpected value of extrastate = ', extrastate
161          ierr = MPI_ERR_OTHER
162       endif
163       end