1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2001 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
8 * This file contains the C routines used in testing the c2f and f2c
9 * handle conversion functions, except for MPI_File and MPI_Win (to
10 * allow working with MPI implementations that do not include those
13 * The tests follow this pattern:
15 * Fortran main program
16 * calls c routine with each handle type, with a prepared
17 * and valid handle (often requires constructing an object)
19 * C routine uses xxx_f2c routine to get C handle, checks some
20 * properties (i.e., size and rank of communicator, contents of datatype)
22 * Then the Fortran main program calls a C routine that provides
23 * a handle, and the Fortran program performs similar checks.
25 * We also assume that a C int is a Fortran integer. If this is not the
26 * case, these tests must be modified.
29 /* style: allow:fprintf:10 sig:0 */
32 #include "../../include/mpitestconf.h"
36 Name mapping. All routines are created with names that are lower case
37 with a single trailing underscore. This matches many compilers.
38 We use #define to change the name for Fortran compilers that do
39 not use the lowercase/underscore pattern
43 #define c2fcomm_ C2FCOMM
44 #define c2fgroup_ C2FGROUP
45 #define c2ftype_ C2FTYPE
46 #define c2finfo_ C2FINFO
47 #define c2frequest_ C2FREQUEST
49 #define c2ferrhandler_ C2FERRHANDLER
51 #define f2ccomm_ F2CCOMM
52 #define f2cgroup_ F2CGROUP
53 #define f2ctype_ F2CTYPE
54 #define f2cinfo_ F2CINFO
55 #define f2crequest_ F2CREQUEST
57 #define f2cerrhandler_ F2CERRHANDLER
59 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
60 /* Mixed is ok because we use lowercase in all uses */
61 #define c2fcomm_ c2fcomm
62 #define c2fgroup_ c2fgroup
63 #define c2ftype_ c2ftype
64 #define c2finfo_ c2finfo
65 #define c2frequest_ c2frequest
67 #define c2ferrhandler_ c2ferrhandler
69 #define f2ccomm_ f2ccomm
70 #define f2cgroup_ f2cgroup
71 #define f2ctype_ f2ctype
72 #define f2cinfo_ f2cinfo
73 #define f2crequest_ f2crequest
75 #define f2cerrhandler_ f2cerrhandler
77 #elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE) || \
78 defined(F77_NAME_MIXED_USCORE)
79 /* Else leave name alone (routines have no underscore, so both
80 of these map to a lowercase, single underscore) */
82 #error 'Unrecognized Fortran name mapping'
85 /* Prototypes to keep compilers happy */
86 MPI_Fint c2fcomm_( MPI_Fint * );
87 MPI_Fint c2fgroup_( MPI_Fint * );
88 MPI_Fint c2finfo_( MPI_Fint * );
89 MPI_Fint c2frequest_( MPI_Fint * );
90 MPI_Fint c2ftype_( MPI_Fint * );
91 MPI_Fint c2fop_( MPI_Fint * );
92 MPI_Fint c2ferrhandler_( MPI_Fint * );
94 void f2ccomm_( MPI_Fint * );
95 void f2cgroup_( MPI_Fint * );
96 void f2cinfo_( MPI_Fint * );
97 void f2crequest_( MPI_Fint * );
98 void f2ctype_( MPI_Fint * );
99 void f2cop_( MPI_Fint * );
100 void f2cerrhandler_( MPI_Fint * );
103 MPI_Fint c2fcomm_ (MPI_Fint *comm)
105 MPI_Comm cComm = MPI_Comm_f2c(*comm);
106 int cSize, wSize, cRank, wRank;
108 MPI_Comm_size( MPI_COMM_WORLD, &wSize );
109 MPI_Comm_rank( MPI_COMM_WORLD, &wRank );
110 MPI_Comm_size( cComm, &cSize );
111 MPI_Comm_rank( cComm, &cRank );
113 if (wSize != cSize || wRank != cRank) {
114 fprintf( stderr, "Comm: Did not get expected size,rank (got %d,%d)",
121 MPI_Fint c2fgroup_ (MPI_Fint *group)
123 MPI_Group cGroup = MPI_Group_f2c(*group);
124 int cSize, wSize, cRank, wRank;
126 /* We pass in the group of comm world */
127 MPI_Comm_size( MPI_COMM_WORLD, &wSize );
128 MPI_Comm_rank( MPI_COMM_WORLD, &wRank );
129 MPI_Group_size( cGroup, &cSize );
130 MPI_Group_rank( cGroup, &cRank );
132 if (wSize != cSize || wRank != cRank) {
133 fprintf( stderr, "Group: Did not get expected size,rank (got %d,%d)",
140 MPI_Fint c2ftype_ ( MPI_Fint *type )
142 MPI_Datatype dtype = MPI_Type_f2c( *type );
144 if (dtype != MPI_INTEGER) {
145 fprintf( stderr, "Type: Did not get expected type\n" );
151 MPI_Fint c2finfo_ ( MPI_Fint *info )
153 MPI_Info cInfo = MPI_Info_f2c( *info );
158 MPI_Info_get( cInfo, (char*)"host", sizeof(value), value, &flag );
159 if (!flag || strcmp(value,"myname") != 0) {
160 fprintf( stderr, "Info: Wrong value or no value for host\n" );
163 MPI_Info_get( cInfo, (char*)"wdir", sizeof(value), value, &flag );
164 if (!flag || strcmp( value, "/rdir/foo" ) != 0) {
165 fprintf( stderr, "Info: Wrong value of no value for wdir\n" );
172 MPI_Fint c2frequest_ ( MPI_Fint *request )
174 MPI_Request req = MPI_Request_f2c( *request );
177 MPI_Test( &req, &flag, &status );
178 MPI_Test_cancelled( &status, &flag );
180 fprintf( stderr, "Request: Wrong value for flag\n" );
184 *request = MPI_Request_c2f( req );
189 MPI_Fint c2fop_ ( MPI_Fint *op )
191 MPI_Op cOp = MPI_Op_f2c( *op );
193 if (cOp != MPI_SUM) {
194 fprintf( stderr, "Op: did not get sum\n" );
200 MPI_Fint c2ferrhandler_ ( MPI_Fint *errh )
202 MPI_Errhandler errhand = MPI_Errhandler_f2c( *errh );
204 if (errhand != MPI_ERRORS_RETURN) {
205 fprintf( stderr, "Errhandler: did not get errors return\n" );
213 * The following routines provide handles to the calling Fortran program
215 void f2ccomm_( MPI_Fint * comm )
217 *comm = MPI_Comm_c2f( MPI_COMM_WORLD );
220 void f2cgroup_( MPI_Fint * group )
223 MPI_Comm_group( MPI_COMM_WORLD, &wgroup );
224 *group = MPI_Group_c2f( wgroup );
227 void f2ctype_( MPI_Fint * type )
229 *type = MPI_Type_c2f( MPI_INTEGER );
232 void f2cinfo_( MPI_Fint * info )
236 MPI_Info_create( &cinfo );
237 MPI_Info_set( cinfo, (char*)"host", (char*)"myname" );
238 MPI_Info_set( cinfo, (char*)"wdir", (char*)"/rdir/foo" );
240 *info = MPI_Info_c2f( cinfo );
243 void f2crequest_( MPI_Fint * req )
247 MPI_Irecv( NULL, 0, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG,
248 MPI_COMM_WORLD, &cReq );
250 *req = MPI_Request_c2f( cReq );
254 void f2cop_( MPI_Fint * op )
256 *op = MPI_Op_c2f( MPI_SUM );
259 void f2cerrhandler_( MPI_Fint *errh )
261 *errh = MPI_Errhandler_c2f( MPI_ERRORS_RETURN );