Debian Codegraph @

src/binding/f77/buildiface

raw
1 #! /usr/bin/env perl
2 #
3 # This file builds candidate interface files from the descriptions in
4 # mpi.h
5 #
6 # Here are the steps:
7 # 1) Find the prototypes in mpi.h.in (Look for *Begin Prototypes*)
8 # 2) For each function, match the name and args:
9 # int MPI_xxxx( ... )
10 # 3) Create a new file with the name lc(xxxx)f.c (lowercase of name),
11 # containing
12 # Copyright
13 # Profiling block indicator
14 # Fortran name version of function, with MPI objects replaced by
15 # MPI_Fint etc. as appropriate
16 #
17 #
18
19 use warnings;
20
21 # Setup global variables
22 %CtoFName = ();
23 @ExtraRoutines = ();
24
25 $buildfiles = 0;
26 $build_prototypes = 1;
27 $buildMakefile = 1;
28 $prototype_header_file = "fproto.h";
29 $build_io = 1;
30 $print_line_len = 0;
31 $write_mpif = 1;
32 $is_MPI = 1;
33 $do_profiling = 1;
34 $routine_prefix = "MPI_";
35 $routine_pattern = "[A-Z][a-z0-9_]*";
36 $out_prefix="mpi_";
37 $malloc = "MPIU_Malloc";
38 $free = "MPIU_Free";
39 $header_file = "mpi_fortimpl.h";
40 $debug = 0;
41 $writeRoutineList = 0; # Set to 1 to get a list of MPI routines
42
43 @arg_addresses = ();
44 #
45 # Error return handling
46 $errparmtype = "MPI_Fint *";
47 $errparm = "MPI_Fint *ierr";
48 $errparmlval = "*ierr";
49 $errparmrval = "*ierr";
50 $returnErrval = 0;
51 $returnType = "void";
52
53 %altweak = (); # Alternate weak declarations
54 %altweakrtype = ();
55
56 #feature variables
57 $do_logical = 1;
58 $do_weak = 1;
59 $do_subdecls = 1;
60 $do_bufptr = 1;
61 $prototype_file = "../../include/mpi.h.in";
62
63 # Global hashes used for definitions and to record the locations of the
64 # defintions.
65 %mpidef = ();
66 %mpidefFile = ();
67 %mpiRoutinesFile = ();
68
69 # Handle special initializations
70 #
71 # Notes on this string. Some symbols need to be initialized at runtime.
72 # These are typically the addresses of the "special" Fortran symbols,
73 # such as MPIR_F_MPI_BOTTOM. Because MPI-2 requires that MPI_Init and
74 # MPI_Init_thread, called in *any* language, initalize MPI for *all*
75 # languages, we can't depend on having the Fortran versions of MPI_Init or
76 # MPI_Init_thread called before these values might be used in a Fortran
77 # wrapper function.
78 # We also cannot have the C version of MPI_Init and MPI_Init_thread call
79 # the initialization routine, because some Fortran compilers will require
80 # special routines from that particular vendors Fortran runtime library for
81 # any executable that uses routines that are compiled with the Fortran
82 # compiler, forcing user programs that are entirely C to link with the
83 # Fortran runtime. Thus, we must check whether the values are initialized
84 # before any use in any routine.
85 #
86 # Having said the above, however, if the environment (specifically, the
87 # C and Fortran compilers) makes it easy for the C init routines to initialize
88 # the Fortran environment, then we should make that easy. This is indicated
89 # by the CPP name HAVE_MPI_F_INIT_WORKS_WITH_C. If that is defined, then
90 # there is no lazy initialization of these values.
91 $specialInitAdded = 0;
92 $specialInitString = "\
93 #ifndef HAVE_MPI_F_INIT_WORKS_WITH_C
94 if (MPIR_F_NeedInit){ mpirinitf_(); MPIR_F_NeedInit = 0; }
95 #endif";
96
97 # Process arguments
98 #
99 # Args
100 # -feature={logical,fint,subdecls,weak,bufptr}, separated by :, value given
101 # by =on or =off, eg
102 # -feature=logical=on:fint=off
103 # The feature names mean:
104 # logical - Fortran logicals are converted to/from C
105 # fint - Fortran integers and C ints are different size (not implemented)
106 # subdecls - Declarations for PC-Fortran compilers added
107 # weak - Use weak symbols
108 # bufptr - Check for MPI_BOTTOM as a special address. This is
109 # not needed if a POINTER declaration is available.
110 foreach $_ (@ARGV) {
111 if (/-noprototypes/) { $build_prototypes = 0; }
112 elsif (/-infile=(.*)/) {
113 # Special arg to help with debugging
114 $prototype_file = $1;
115 $write_mpif = 0;
116 $build_prototypes = 0;
117 $do_weak = 0;
118 }
119 elsif (/-noromio/) { $build_io = 0; }
120 elsif (/-debug/) {
121 $debug = 1;
122 }
123 elsif (/-prefix=(.*)/) {
124 $routine_prefix = $1;
125 $is_MPI = 0;
126 }
127 elsif (/-pattern=(.*)/) {
128 $routine_pattern = $1;
129 }
130 elsif (/-feature=(.*)/) {
131 foreach $feature (split(/:/,$1)) {
132 print STDERR "Processing feature $feature\n" if $debug;
133 # Feature values are foo=on,off
134 ($name,$value) = split(/=/,$feature);
135 if ($value eq "on") { $value = 1; }
136 elsif ($value eq "off") { $value = 0; }
137 # Set the variable based on the string
138 $varname = "do_$name";
139 $$varname = $value;
140 }
141 }
142 elsif (/deffile=(.*)/) {
143 $definition_file = $1;
144 $is_MPI = 0;
145 }
146 else {
147 print STDERR "Unrecognized argument $_\n";
148 }
149 }
150
151 # Note that the code that looks up values strips blanks out of the type name
152 # No blanks should be used in the key.
153 %tof77 = ( 'MPI_Datatype' => 'MPI_Fint *',
154 'MPI_Comm' => 'MPI_Fint *',
155 #MPI_File must be handled specially, since ROMIO still uses pointers
156 'MPI_File' => 'MPI_Fint *',
157 'MPI_Win' => 'MPI_Fint *',
158 'MPI_Request' => 'MPI_Fint *',
159 'MPI_Group' => 'MPI_Fint *',
160 'MPI_Op' => 'MPI_Fint *',
161 'MPI_Info' => 'MPI_Fint *',
162 'MPI_Errhandler' => 'MPI_Fint *',
163 'MPI_Aint' => 'MPI_Fint *', # Should be MPIR_FAint
164 'MPI_FAintp' => 'MPI_Aint *', # Used to force an MPI_Aint*
165 'MPI_Offset' => 'MPI_Offset *', # Should be MPIR_FOint
166 'int' => 'MPI_Fint *',
167 'int[]' => 'MPI_Fint', # no * because we'll use array form
168 'int[][3]' => 'MPI_Fint', # no * because we'll use array form
169 'MPI_Datatype*' => 'MPI_Fint *',
170 'MPI_Datatype[]' => 'MPI_Fint', # no * because we'll use array form
171 'MPI_Comm*' => 'MPI_Fint *',
172 'MPI_File*' => 'MPI_Fint *',
173 'MPI_Win*' => 'MPI_Fint *',
174 'MPI_Group*' => 'MPI_Fint *',
175 'MPI_Request*' => 'MPI_Fint *',
176 'MPI_Aint*' => 'MPI_Fint *', # Should be MPIR_FAint
177 'int *' => 'MPI_Fint *',
178 'int*' => 'MPI_Fint *', # Catch missing space
179 'MPI_Op*' => 'MPI_Fint *',
180 'MPI_Status*' => 'MPI_Fint *',
181 'MPI_Info*' => 'MPI_Fint *',
182 'MPI_Errhandler*' => 'MPI_Fint *',
183 );
184
185 # declarg is special parameters for certain routines
186 %declarg = ( 'type_extent-2' => 'MPI_Fint *',
187 'type_lb-2' => 'MPI_Fint *',
188 'type_ub-2' => 'MPI_Fint *',
189 'type_struct-3' => 'MPI_Fint *', # Really [], but * is easier
190 'type_hindexed-3' => 'MPI_Fint *', # As above
191 'type_hvector-3' => 'MPI_Fint *',
192 # The following are MPI-2 routines with address args.
193 # For these, the user must pass in the correct arguments
194 'file_get_type_extent-3' => 'MPI_FAint *',
195 'pack_external-6' => 'MPI_Aint *', # Value in C call
196 'pack_external-7' => 'MPI_Aint *',
197 'pack_external_size-4' => 'MPI_Aint *',
198 'type_create_hvector-3' => 'MPI_Aint *', # Value in C call
199 'type_create_hindexed-3' => 'MPI_Aint *',
200 'type_create_struct-3' => 'MPI_Aint *',
201 'type_get_contents-6' => 'MPI_Aint *',
202 'type_get_extent-2' => 'MPI_Aint *',
203 'type_get_extent-3' => 'MPI_Aint *',
204 'type_get_true_extent-2' => 'MPI_Aint *',
205 'type_get_true_extent-3' => 'MPI_Aint *',
206 'type_create_resized-2' => 'MPI_Aint *', # Value in C call
207 'type_create_resized-3' => 'MPI_Aint *', # Value in C call
208 'unpack_external-3' => 'MPI_Aint *', # Value in C call
209 'unpack_external-4' => 'MPI_Aint *',
210 'win_create-2' => 'MPI_Aint *',
211 'accumulate-5' => 'MPI_Aint *',
212 'put-5' => 'MPI_Aint *',
213 'get-5' => 'MPI_Aint *',
214 'alloc_mem-1' => 'MPI_Aint *',
215 );
216
217 %argsneedcast = ( 'MPI_Request *' => '(MPI_Request *)(ARG)',
218 'MPI_Status *' => '(MPI_Status *)(ARG)',
219 'MPI_File' => 'MPI_File_f2c(ARG)',
220 'MPI_Comm' => '(MPI_Comm)(ARG)',
221 'MPI_Comm *' => '(MPI_Comm *)(ARG)',
222 'MPI_Datatype' => '(MPI_Datatype)(ARG)',
223 'MPI_Datatype *' => '(MPI_Datatype *)(ARG)',
224 'MPI_Info *' => '(MPI_Info *)(ARG)',
225 'MPI_Info' => '(MPI_Info)(ARG)',
226 'int [][3]' => '(int (*)[3])(ARG)'
227 );
228
229 ##
230 ## For implementations other than MPICH2, we'll need to consider using
231 ## MPI_C2f_<name> and MPI_F2c_<name>, as in
232 ## 'MPI_Info' => 'MPI_F2c_info(ARG)'
233 ##
234 # name_map maps the filenames. Most filenames are created automatically
235 # from the routine name, but some names have too many characters (15,
236 # including the extension(.o) is a limit for ar in some systems).
237 %name_map = ( 'add_error_class' => 'adderrclass',
238 'add_error_code' => 'adderrcode',
239 'add_error_string' => 'adderrstring',
240 'buffer_attach' => 'bufattach',
241 'buffer_detach' => 'bufdetach',
242 'comm_call_errhandler' => 'commcallerr',
243 'comm_create_errhandler' => 'commcreerr',
244 'comm_create_keyval' => 'commnewkey',
245 'comm_delete_attr' => 'commdelattr',
246 'comm_disconnect' => 'commdisc',
247 'comm_free_keyval' => 'commfreekey',
248 'comm_get_errhandler' => 'commgeterr',
249 'comm_get_name' => 'commgetnam',
250 'comm_get_parent' => 'commparent',
251 'comm_remote_group' => 'commrgroup',
252 'comm_remote_size' => 'commrsize',
253 'comm_set_errhandler' => 'commseterr',
254 'comm_spawn_multiple' => 'spawnmult',
255 'comm_test_inter' => 'commtestic',
256 'errhandler_create' => 'errhcreate',
257 'errhandler_free' => 'errhfree',
258 'errhandler_get' => 'errhget',
259 'errhandler_set' => 'errhset',
260 'file_call_errhandler' => 'filecallerr',
261 'file_create_errhandler' => 'filecreerr',
262 'file_get_errhandler' => 'filegeterr',
263 'file_set_errhandler' => 'fileseterr',
264 'get_processor_name' => 'getpname',
265 'graph_neighbors_count' => 'grfnbcount',
266 'graph_neighbors' => 'grfnbrs',
267 'grequest_complete' => 'greqcomplete',
268 'grequest_start' => 'greqstart',
269 'group_difference' => 'groupdiff',
270 'group_intersection' => 'groupinter',
271 'group_range_excl' => 'grouprexcl',
272 'group_range_incl' => 'grouprincl',
273 'group_translate_ranks' => 'grouptranks',
274 'info_get_nkeys' => 'infognk',
275 'info_get_nthkey' => 'infognthk',
276 'info_get_valuelen' => 'infovallen',
277 'intercomm_create' => 'iccreate',
278 'intercomm_merge' => 'icmerge',
279 'is_thread_main' => 'isthrmain',
280 'pack_external_size' => 'packesize',
281 'reduce_scatter' => 'redscat',
282 'request_get_status' => 'reqgetstat',
283 'sendrecv_replace' => 'sndrcvrpl',
284 'status_set_cancelled' => 'statgetcl',
285 'status_set_elements' => 'statsetel',
286 'test_cancelled' => 'testcancel',
287 'type_contiguous' => 'typecontig',
288 'type_create_darray' => 'typedarray',
289 'type_create_f90_integer' => 'typef90int',
290 'type_create_f90_real' => 'typef90real',
291 'type_create_f90_complex' => 'typef90cmplx',
292 'type_create_hindexed' => 'typechind',
293 'type_create_hvector' => 'typechvec',
294 'type_create_indexed_block' => 'typecindb',
295 'type_create_keyval' => 'typenewkey',
296 'type_create_resized' => 'typecresize',
297 'type_create_struct' => 'typecstruct',
298 'type_create_subarray' => 'typecsubarr',
299 'type_delete_attr' => 'typedelattr',
300 'type_free_keyval' => 'typefreekey',
301 'type_get_contents' => 'typegetcnts',
302 'type_get_envelope' => 'typegetenv',
303 'type_get_extent' => 'typegetextent', # there is already a type_extent
304 'type_get_name' => 'typegname',
305 'type_get_true_extent' => 'typegtext',
306 'type_set_attr' => 'typesetattr',
307 'type_set_name' => 'typesetname',
308 'unpack_external' => 'unpackext',
309 'unpublish_name' => 'unpubname',
310 'win_call_errhandler' => 'wincallerr',
311 'win_create_errhandler' => 'wincreerr',
312 'win_create_keyval' => 'winnewkey',
313 'win_delete_attr' => 'windelattr',
314 'win_free_keyval' => 'winfreekey',
315 'win_get_errhandler' => 'wingeterr',
316 'win_set_errhandler' => 'winseterr',
317 );
318
319 #
320 # Special routines have very different calling seqences in C and Fortran
321 # or different behavior.
322 # Init and Init thread have different arg lists (no argc, argv)
323 # Pcontrol has no varargs
324 # Address and Get_address require special integer types and
325 # possibly handling for MPI_BOTTOM
326 # Keyval routines require setting the language to Fortran (Attribute
327 # routines are handled with the special argument processing)
328 #
329 # The Type_create_f90_xxx routines are only available as part of the
330 # extended Fortran support, and are excluded from the f77 routines.
331 %special_routines = ( 'Init' => 1, 'Init_thread' => 1, 'Pcontrol' => '1',
332 'Address' => 1, 'Get_address' => 1,
333 'Keyval_create' => 1, 'Status_f2c' => 1,
334 'Status_c2f' => 1,
335 'Type_create_f90_integer' => 1,
336 'Type_create_f90_real' => 1,
337 'Type_create_f90_complex' => 1,
338 );
339
340 # Some routines have special needs and must call a different routine. For
341 # similicity, we make the requirement that the replacement routine take
342 # all of the arguments of the original routine, but all additional arguments
343 # at the end. This is used with the attribute routines which must
344 # pass an additional argument to a special attribute routine that handles
345 # the differences between C and Fortran attributes.
346 %ChangeCall = ( 'Comm_get_attr' => 'MPIR_CommGetAttr:!MPIR_ATTR_AINT' ,
347 'Type_get_attr' => 'MPIR_TypeGetAttr:!MPIR_ATTR_AINT',
348 'Win_get_attr' => 'MPIR_WinGetAttr:!MPIR_ATTR_AINT',
349 'Attr_get' => 'MPIR_CommGetAttr:!MPIR_ATTR_INT',
350 'Comm_set_attr' => 'MPIR_CommSetAttr:!MPIR_ATTR_AINT',
351 'Type_set_attr' => 'MPIR_TypeSetAttr:!MPIR_ATTR_AINT',
352 'Win_set_attr' => 'MPIR_WinSetAttr:!MPIR_ATTR_AINT',
353 'Attr_put' => 'MPIR_CommSetAttr:!MPIR_ATTR_INT',
354 );
355 #
356 # Note that wtime and wtick aren't found because they don't match the
357 # int MPI_xxx format. They're handled directly by the special routine
358 # code below
359
360 #
361 # Most routines can be processed automatically. However, some
362 # require some special processing. For example, those routines with
363 # LOGICAL arguments need some special handling. To detect this, there
364 # are two entries in a %special_args hash: the routine name, and the routine
365 # name -arg#. E.g., for MPI_Test, the hash has keys
366 # "Test" and "Test-2". The value for "Test-2" is "out:logical"; this
367 # indicates that the variable is an out variable with logical type.
368 # Processing types (the second field after the :) are
369 # logical: convert to/from Fortran and C representations of logical
370 # index: convert to/from Fortran (1-based) and C (0-based) origins
371 # array: handle arrays of items that may have different lengths
372 # in C and Fortran because the integer types have
373 # different sizes. The term has an additional :expression,
374 # the third term give the array size.
375 # addnull: Add a null character to a *copy* of the input string,
376 # after trimming any blanks.
377 # blankpad: Add blanks and remove nulls. Only used for out args;
378 # must use an allocated space to provide room for the null
379 # that the C routines may require
380 # bufptr: Detect MPI_BOTTOM. Note that a better alternative is to
381 # use MPI_Address and MPI_Get_address to make addresses
382 # relative to the Fortran MPI_BOTTOM. The lines that
383 # define this are commented out below.
384 # addrint: Given the address of an int, provide the int. Used
385 # for attr_put/set routines
386 # attrint: Convert an attribute value to an int.
387 # addraint: Given the address of an address-sized int, provide the
388 # value of that item. Used for the MPI-2 versions of the
389 # attribute caching routines
390 # bufaddr: Argument is *output* as a buffer address. Discarded before
391 # passing to Fortran.
392 # For MPI-2 routines that take MPI_Aints even in Fortran, we need a
393 # special mapping when the value is passed to c
394 # aintToVal: Given the address of an Aint, pass the value to the C routine
395 # (This should really be done by not applying the Aint->int mapping
396 # for MPI-2 routines. But for now, this hack will work)
397 %special_args = (
398 # 'Allreduce' => '1:2', 'Allreduce-1' => 'in:bufptr',
399 # 'Allreduce-2' => 'in:bufptr',
400 # 'Bcast' => '1', 'Bcast-1' => 'in:bufptr',
401 # 'Gather' => '1:4', 'Gather-1' => 'in:bufptr', 'Gather-4' => 'in:bufptr',
402 # 'Gatherv' => '1:4', 'Gatherv-1' => 'in:bufptr', 'Gatherv-4' => 'in:bufptr',
403 # 'Scatter' => '1:4', 'Scatter-1' => 'in:bufptr', 'Scatter-4' => 'in:bufptr',
404 # 'Scatterv' => '1:5', 'Scatterv-1' => 'in:bufptr', 'Scatterv-5' => 'in:bufptr',
405 # 'Allgather' => '1:4', 'Allgather-1' => 'in:bufptr', 'Allgather-4' => 'in:bufptr',
406 # 'Allgatherv' => '1:4', 'Allgatherv-1' => 'in:bufptr', 'Allgatherv-4' => 'in:bufptr',
407 # 'Alltoall' => '1:4', 'Alltoall-1' => 'in:bufptr', 'Alltoall-4' => 'in:bufptr',
408 # 'Alltoallv' => '1:5', 'Alltoallv-1' => 'in:bufptr', 'Alltoallv-5' => 'in:bufptr',
409 # 'Reduce' => '1:2', 'Reduce-1' => 'in:bufptr', 'Reduce-2' => 'in:bufptr',
410 # 'Reduce_scatter' => '1:2', 'Reduce_scatter-1' => 'in:bufptr',
411 # 'Reduce_scatter-2' => 'in:bufptr',
412 # 'Scan' => '1:2', 'Scan-1' => 'in:bufptr', 'Scan-2' => 'in:bufptr',
413 #
414 'Gather' => '1', 'Gather-1' => 'in:inplace',
415 'Gatherv' => '1', 'Gatherv-1' => 'in:inplace',
416 'Scatter' => '4', 'Scatter-4' => 'in:inplace',
417 'Scatterv' => '5', 'Scatterv-5' => 'in:inplace',
418 'Allgather' => '1', 'Allgather-1' => 'in:inplace',
419 'Allgatherv' => '1', 'Allgatherv-1' => 'in:inplace',
420 'Reduce' => '1', 'Reduce-1' => 'in:inplace',
421 'Allreduce' => '1', 'Allreduce-1' => 'in:inplace',
422 'Reduce_scatter' => '1', 'Reduce_scatter-1' => 'in:inplace',
423 'Scan' => '1', 'Scan-1' => 'in:inplace',
424
425
426 'Add_error_string' => '2', 'Add_error_string-2' => 'in:addnull',
427 'Attr_put' => '3', 'Attr_put-3' => 'in:addrint',
428 'Attr_get' => '3:4', 'Attr_get-4' => 'out:logical',
429 'Attr_get-3' => 'out:attrint:4',
430 'Comm_set_attr' => '3', 'Comm_set_attr-3' => 'in:addraint',
431 'Type_set_attr' => '3', 'Type_set_attr-3' => 'in:addraint',
432 'Win_set_attr' => '3', 'Win_set_attr-3' => 'in:addraint',
433 'Comm_get_attr' => '3:4', 'Comm_get_attr-4' => 'out:logical',
434 'Comm_get_attr-3' => 'out:attraint:4',
435 'Type_get_attr' => '3:4', 'Type_get_attr-4' => 'out:logical',
436 'Type_get_attr-3' => 'out:attraint:4',
437 'Win_get_attr' => '3:4', 'Win_get_attr-4' => 'out:logical',
438 'Win_get_attr-3' => 'out:attraint:4',
439 'Buffer_detach' => '1', 'Buffer_detach-1' => 'out:bufaddr',
440 'Cart_create' => '4:5', 'Cart_create-4' => 'in:logical_array:*v2',
441 'Cart_create-5' => 'in:logical',
442 'Cart_get' => '4', 'Cart_get-4' => 'out:logical_array:*v2',
443 'Comm_accept' => '1', 'Comm_accept-1' => 'in:addnull',
444 'Comm_connect' => '1', 'Comm_connect-1' => 'in:addnull',
445 'Comm_get_name' => '2', 'Comm_get_name-2' => 'out:blankpad',
446 'Comm_set_name' => '2', 'Comm_set_name-2' => 'in:addnull',
447 'Comm_spawn' => '1:2:8', 'Comm_spawn-1' => 'in:addnull',
448 'Comm_spawn-2' => 'in:chararray',
449 'Comm_spawn-8' => 'in:errcodesignore',
450 'Comm_test_inter' => '2', 'Comm_test_inter-2' => 'out:logical',
451 'Get_processor_name' => '1', 'Get_processor_name-1' => 'out:blankpad',
452 'Error_string' => '2', 'Error_string-2' => 'out:blankpad',
453 'Intercomm_merge' => '2', 'Intercomm_merge-2' => 'in:logical',
454 'Info_get' => '2:4:5', 'Info_get-2' => 'in:addnull',
455 'Info_get-4' => 'out:blankpadonflag:l5',
456 'Info_get-5' => 'out:logical',
457 'Info_set' => '2:3', 'Info_set-2' => 'in:addnullandtrim',
458 'Info_set-3' => 'in:addnullandtrim',
459 'Info_get_nthkey' => '3', 'Info_get_nthkey-3' => 'out:blankpad',
460 'Info_get_valuelen' => '2:4', 'Info_get_valuelen-2' => 'in:addnull',
461 'Info_get_valuelen-4' => 'out:logical',
462 'Info_delete' => '2', 'Info_delete-2' => 'in:addnull',
463 'Lookup_name' => '1:3', 'Lookup_name-1' => 'in:addnull',
464 'Lookup_name-3' => 'out:blankpad',
465 'Open_port' => '2', 'Open_port-2' => 'out:blankpad',
466 'Close_port' => '1', 'Close_port-1' => 'in:addnull',
467 'Pack_external' => '1:6', 'Pack_external-1' => 'in:addnull',
468 'Pack_external-6' => 'in:aintToVal',
469 'Pack_external_size' => '1', 'Pack_external_size-1' => 'in:addnull',
470 'Publish_name' => '1:3', 'Publish_name-1' => 'in:addnull',
471 'Publish_name-3' => 'in:addnull',
472 # comm spawn multiple needs slightly different routines
473 'Comm_spawn_multiple' => '2:3:9',
474 'Comm_spawn_multiple-2' => 'in:chararray:*v1',
475 'Comm_spawn_multiple-3' => 'in:chararray2:*v1',
476 'Comm_spawn_multiple-9' => 'in:errcodesignore',
477 'Initialized' => '1', 'Initialized-1' => 'out:logical',
478 'Iprobe' => '4:5', 'Iprobe-4' => 'out:logical',
479 'Iprobe-5' => 'in:status',
480 'Probe' => '4', 'Probe-4' => 'in:status',
481 'Recv' => '7', 'Recv-7' => 'in:status',
482 'Sendrecv' => '12', 'Sendrecv-12' => 'in:status',
483 'Sendrecv_replace' => '9', 'Sendrecv_replace-9' => 'in:status',
484 # 'Send' => '1', 'Send-1' => 'in:bufptr',
485 # 'Ssend' => '1', 'Ssend-1' => 'in:bufptr',
486 # 'Rsend' => '1', 'Rsend-1' => 'in:bufptr',
487 # 'Bsend' => '1', 'Bsend-1' => 'in:bufptr',
488 # 'Isend' => '1', 'Isend-1' => 'in:bufptr',
489 # 'Issend' => '1', 'Issend-1' => 'in:bufptr',
490 # 'Irsend' => '1', 'Irsend-1' => 'in:bufptr',
491 # 'Ibsend' => '1', 'Ibsend-1' => 'in:bufptr',
492 # 'Irecv' => '1', 'Irecv-1' => 'in:bufptr',
493 # 'Recv' => '1', 'Recv-1' => 'in:bufptr',
494 # 'Send_init' => '1', 'Send_init-1' => 'in:bufptr',
495 # 'Bsend_init' => '1', 'Bsend_init-1' => 'in:bufptr',
496 # 'Ssend_init' => '1', 'Ssend_init-1' => 'in:bufptr',
497 # 'Rsend_init' => '1', 'Rsend_init-1' => 'in:bufptr',
498 # 'Recv_init' => '1', 'Recv_init-1' => 'in:bufptr',
499 # 'Sendrecv' => '1:6', 'Sendrecv-1' => 'in:bufptr', 'Sendrecv-6' => 'in:bufptr',
500 # 'Sendrecv_replace' => '1', 'Sendrecv_replace-1' => 'in:bufptr',
501 'Test_cancelled' => '2', 'Test_cancelled-2' => 'out:logical',
502 'Test' => '2:3', 'Test-2' => 'out:logical',
503 'Test-3' => 'in:status',
504 'Testall' => '3:4', 'Testall-3' => 'out:logical',
505 'Testall-4' => 'in:status_array',
506 'Testany' => '3:4:5', 'Testany-4' => 'out:logical',
507 'Testany-3' => 'out:index',
508 'Testany-5' => 'in:status',
509 'Testsome' => '4:5', 'Testsome-4' => 'out:index_array:*v3',
510 'Testsome-5' => 'in:status_array',
511 'Type_create_hvector' => 3, 'Type_create_hvector-3' => 'in:aintToVal',
512 'Type_create_resized' => '2:3',
513 'Type_create_resized-2' => 'in:aintToVal',
514 'Type_create_resized-3' => 'in:aintToVal',
515 'Type_get_name' => '2', 'Type_get_name-2' => 'out:blankpad',
516 'Type_set_name' => '2', 'Type_set_name-2' => 'in:addnull',
517 'Type_extent' => '2', 'Type_extent-2' => 'out:aintToInt',
518 'Type_lb' => '2', 'Type_lb-2' => 'out:aintToInt',
519 'Type_ub' => '2', 'Type_ub-2' => 'out:aintToInt',
520 'Type_struct' => '3', 'Type_struct-3' => 'in:intToAintArr:*v1',
521 'Type_hindexed' => '3', 'Type_hindexed-3' => 'in:intToAintArr:*v1',
522 # also need
523 'Type_hvector' => '3', 'Type_hvector-3' => 'in:intToAint',
524 'Unpack_external' => '1:3', 'Unpack_external-1' => 'in:addnull',
525 'Unpack_external-3' => 'in:aintToVal',
526 'Unpublish_name' => '1:3', 'Unpublish_name-1' => 'in:addnull',
527 'Unpublish_name-3' => 'in:addnull',
528 'Win_create' => '2', 'Win_create-2' => 'in:aintToVal',
529 'Accumulate' => '5', 'Accumulate-5' => 'in:aintToVal',
530 'Put' => '5', 'Put-5' => 'in:aintToVal',
531 'Get' => '5', 'Get-5' => 'in:aintToVal',
532 'Alloc_mem' => '1', 'Alloc_mem-1' => 'in:aintToVal',
533 'Win_get_name' => '2', 'Win_get_name-2' => 'out:blankpad',
534 'Win_set_name' => '2', 'Win_set_name-2' => 'in:addnull',
535 'Wait' => '2', 'Wait-2' => 'in:status',
536 'Waitall' => '3', 'Waitall-3' => 'in:status_array',
537 'Waitany' => '3:4', 'Waitany-3' => 'out:index',
538 'Waitany-4' => 'in:status',
539 'Waitsome' => '4:5', 'Waitsome-4' => 'out:index_array:*v3',
540 'Waitsome-5' => 'in:status_array',
541 # File routines are separate
542 'File_open' => '2:5', 'File_open-2' => 'in:addnull',
543 'File_open-5' => 'out:FileToFint',
544 'File_close' => '1', 'File_close-1', 'inout:FileToFint',
545 'File_delete' => '1', 'File_delete-1' => 'in:addnull',
546 'File_set_view' => '5', 'File_set_view-5' => 'in:addnull',
547 'File_get_view' => '5', 'File_get_view-5' => 'out:blankpad',
548 'File_set_atomicity' => '2', 'File_set_atomicity-2' => 'in:logical',
549 'File_get_atomicity' => '2', 'File_get_atomicity-2' => 'out:logical',
550 'Register_datarep' => '1:2:3', 'Register_datarep-1' => 'in:addnull',
551 'Register_datarep-2' => 'in:checkdatarep',
552 'Register_datarep-3' => 'in:checkdatarep',
553 'Op_commutative' => '2', 'Op_commutative-2' => 'out:logical',
554 );
555
556 #
557 # These give special post processing after the MPI routine is called.
558 # The named routine is invoked with the argument number, e.g.,
559 # &"setF90keyval"( FD, 1 );
560 #
561 %specialPost = (
562 'Type_create_keyval' => 3,
563 'Type_create_keyval-3' => 'setF90Type_keyval',
564 'Comm_create_keyval' => 3,
565 'Comm_create_keyval-3' => 'setF90Comm_keyval',
566 'Win_create_keyval' => 3,
567 'Win_create_keyval-3' => 'setF90Win_keyval',
568 'Grequest_start' => 5,
569 'Grequest_start-5' => 'setF77greq',
570 );
571
572 #
573 # Load any definition file
574 if ($definition_file) {
575 require $definition_file;
576 }
577
578 $arg_string = join( ' ', @ARGV );
579 if ($build_prototypes) {
580 open( PROTOFD, ">$prototype_header_file.new" ) || die "Cannot open $prototype_header_file.new\n";
581 print PROTOFD "/* -*- Mode: C; c-basic-offset:4 ; -*- */\
582 /* \
583 * (C) 2003 by Argonne National Laboratory and Northwestern University.\
584 * See COPYRIGHT in top-level directory.\
585 *\
586 * This file is automatically generated by command:\
587 * ./buildiface $arg_string\
588 * DO NOT EDIT\
589 */\
590 /* Prototypes for Fortran Interface Functions */\
591 \n";
592 }
593
594 %skipBlocks = ();
595 &ReadAndProcessInterface( $prototype_file, 0 );
596
597 # if doing MPI2, we also need to read the MPI-2 protottypes
598 if ( -s "../../mpi/romio/include/mpio.h.in" && $build_io) {
599 %skipBlocks = ( 'HAVE_MPI_DARRAY_SUBARRAY' => 1,
600 'HAVE_MPI_INFO' => 1,
601 'MPICH2' => 1 );
602 &ReadAndProcessInterface( "../../mpi/romio/include/mpio.h.in", 1 );
603 %skipBlocks = ();
604 }
605
606 # Write a list of the routines that we've found.
607 if ($writeRoutineList) {
608 open LFD, ">mpi.dat" || die "Cannot open mpi.dat\n";
609 foreach my $name (sort(keys(%mpi_routines))) {
610 print LFD "$name\n";
611 }
612 close LFD;
613 }
614
615 if ($is_MPI) {
616 # Build the special routines
617 &build_specials;
618 }
619 else {
620 for ($i=0; $i<=$#ExtraRoutines; $i++) {
621 $r = $ExtraRoutines[$i];
622 &$r;
623 }
624 }
625
626 if ($build_prototypes) {
627 close PROTOFD;
628 &ReplaceIfDifferent( $prototype_header_file,
629 $prototype_header_file . ".new" );
630 }
631
632 #
633 # This block can be used to create the Makefile
634 if ("$buildMakefile") {
635 open ( MAKEFD, ">Makefile.sm.new" ) || die "Cannot create Makefile.sm.new";
636 print MAKEFD "# DO NOT EDIT\n# This file created by ./buildiface $arg_string\n";
637
638 # FIXME: Find out what happened to the code here and either restore/fix
639 # it or remove this block
640 # Check to see if autoconf works. Autoconf 2.13 has a bug in the Fortran
641 # language support that will break this module. Since some sites have
642 # corrected the bug in autoconf 2.13, CheckAutoconfs test for this bug.
643 if (&CheckAutoconf) {
644 # Autoconf does not work
645 # This isn't quite right, because any updates will be broken
646 # FIXME : but not sure how to do this.
647 ;
648 }
649 else {
650 # just use the regular autoconf
651 ;
652 }
653
654 #print MAKEFD "smvar_debug = 1\n";
655 print MAKEFD "smvar_do_dependencies = ignore\n";
656 &print_line( MAKEFD, "mpi_sources = ", 80, "\\\n\t", 8 );
657 for ($i=0; $i<=$#files; $i++) {
658 $name = $files[$i];
659 &print_line( MAKEFD, "$name ", 80, "\\\n\t", 8 );
660 }
661 &print_endline( MAKEFD );
662 print MAKEFD "MPIFLIBNAME = \@MPIFLIBNAME\@\n";
663 print MAKEFD "PMPIFLIBNAME = \@PMPIFLIBNAME\@\n";
664
665 # The definitions for the Fortran wrappers are special
666 &AddFwrapDefs;
667 print MAKEFD "\
668 lib\${MPIFLIBNAME}_a_DIR = ROOTDIR/lib\
669 lib\${MPIFLIBNAME}_a_SOURCES = \${mpi_sources} setbot.c setbotf.f\
670 \
671 HEADERS = fproto.h mpi_fortimpl.h\
672 profilelib_\${MPIFLIBNAME} = \${PMPIFLIBNAME}\
673 profilelib_\${MPIFLIBNAME}_SOURCES = \${mpi_sources}\
674 INCLUDES = -I../../include -I\${master_top_srcdir}/src/include -I\${master_top_srcdir}/src/binding/f77 \
675 maint-clean:\
676 \trm -f \${mpi_sources} $prototype_header_file\n";
677
678 print MAKEFD "install_INCLUDE = mpif.h\n";
679
680 # Add the documentation
681 print MAKEFD "# Documentation sources
682 doc_sources = mpif77.txt
683 DOCDESTDIRS = html:www/www1,man:man/man1,latex:doc/refman
684 doc_HTML_SOURCES = \${doc_sources}
685 doc_MAN_SOURCES = \${doc_sources}
686 doc_LATEX_SOURCES = \${doc_sources}
687 ";
688
689 # Since configure copies mpif.h to the include dir, we need to remove it
690 # in a distclean step. Ditto for mpif77; add the generated files.
691 print MAKEFD "distclean-local:\n";
692 print MAKEFD "\trm -f mpif_bottom.h\n";
693 print MAKEFD "\trm -f ../../../src/include/mpif.h\n";
694 print MAKEFD "\trm -f ../../../bin/mpif77\n";
695
696 # Add the generated files to the maintainer clean target
697 print MAKEFD "maintainerclean-local:\n";
698 &print_line( MAKEFD, "\trm -f ", 80, "\\\n\t", 8 );
699 for ($i=0; $i<=$#files; $i++) {
700 if ( (($i+1) % 20) == 0) {
701 # Avoid having a line that is too long
702 &print_endline( MAKEFD );
703 &print_line( MAKEFD, "\trm -f ", 80, "\\n\t", 8 );
704 }
705 $name = $files[$i];
706 &print_line( MAKEFD, "$name ", 80, "\\\n\t", 8 );
707 }
708 &print_endline( MAKEFD );
709 print MAKEFD "\trm -f Makefile.sm\n";
710
711 # Add the definitions for compiling the members of the wrap file
712 &AddFwrapBuild;
713
714 close( MAKEFD );
715 &ReplaceIfDifferent( "Makefile.sm", "Makefile.sm.new" );
716 }
717
718 #
719 # ------------------------------------------------------------------------
720 # Procedures
721 # print_line( FD, line, count, continue, continuelen )
722 # Print line to FD; if line size > count, output continue string and
723 # continue. Use print_endline to finish a line
724 sub print_line {
725 my $FD = $_[0];
726 my $line = $_[1];
727 my $count = $_[2];
728 my $continue = $_[3];
729 my $continue_len = $_[4];
730
731 $linelen = length( $line );
732 #print "linelen = $linelen, print_line_len = $print_line_len\n";
733 if ($print_line_len + $linelen > $count) {
734 print $FD $continue;
735 $print_line_len = $continue_len;
736 }
737 print $FD $line;
738 $print_line_len += $linelen;
739 }
740 sub print_endline {
741 my $FD = $_[0];
742 print $FD "\n";
743 $print_line_len = 0;
744 }
745
746 # Print the header of the file, containing the definitions etc.
747 sub print_header {
748 my $routine_name = $_[0];
749 my $lcname = $_[1];
750 my $args = $_[2];
751 my $extra = $_[3];
752
753 if ($OUTFD ne STDOUT) {
754 &print_copyright( );
755 &print_gcc_pragma( );
756 if ($build_prototypes) {
757 print $OUTFD "\
758 /* Prototypes for the Fortran interfaces */\
759 #include \"$prototype_header_file\"\
760 ";
761 }
762 }
763
764 if ($extra) {
765 print $OUTFD $extra;
766 }
767 &print_profiling_block( $routine_name, $lcname, $args );
768 &print_name_map_block( $routine_name, $lcname );
769
770 my $fn = "HelperFor" . $routine_name ;
771 if (defined(&$fn)) {
772 &$fn( $OUTFD );
773 }
774 }
775
776 sub print_gcc_pragma {
777 print $OUTFD "\
778 #ifdef __GNUC__\
779 #pragma GCC diagnostic ignored \"-Wunused-parameter\"\
780 #endif\
781 #include \"${header_file}\"\n\n";
782 }
783
784 sub print_copyright {
785 print $OUTFD "/* -*- Mode: C; c-basic-offset:4 ; -*- */\
786 /* \
787 * (C) 2003 by Argonne National Laboratory and Northwestern University.\
788 * See COPYRIGHT in top-level directory.\
789 *\
790 * This file is automatically generated by command:\
791 * ./buildiface $arg_string\
792 * DO NOT EDIT\
793 */";
794 }
795
796 #
797 # Print the (ugly) profiling name definition block.
798 # This is made more complex by the need, new with gcc 3.2, to
799 # generate an extern declaration of the routine *before* the pragma
800 #
801 sub print_profiling_block {
802 my $routine_name = $_[0];
803 my $lcname = $_[1];
804 my $args = $_[2];
805 my $ucname = uc($lcname);
806
807 if ($do_weak) {
808 print $OUTFD "\
809 /* Begin MPI profiling block */\
810 #if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES) \
811 #if defined(HAVE_MULTIPLE_PRAGMA_WEAK)\n";
812 &print_weak_decl( $OUTFD, "MPI_$ucname", $args, $lcname );
813 &print_weak_decl( $OUTFD, "mpi_${lcname}__", $args, $lcname );
814 &print_weak_decl( $OUTFD, "mpi_${lcname}", $args, $lcname );
815 &print_weak_decl( $OUTFD, "mpi_${lcname}_", $args, $lcname );
816 print $OUTFD "\
817 #if defined(F77_NAME_UPPER)
818 #pragma weak MPI_$ucname = PMPI_${ucname}
819 #pragma weak mpi_${lcname}__ = PMPI_${ucname}
820 #pragma weak mpi_${lcname}_ = PMPI_${ucname}
821 #pragma weak mpi_${lcname} = PMPI_${ucname}
822 #elif defined(F77_NAME_LOWER_2USCORE)
823 #pragma weak MPI_$ucname = pmpi_${lcname}__
824 #pragma weak mpi_${lcname}__ = pmpi_${lcname}__
825 #pragma weak mpi_${lcname}_ = pmpi_${lcname}__
826 #pragma weak mpi_${lcname} = pmpi_${lcname}__
827 #elif defined(F77_NAME_LOWER_USCORE)
828 #pragma weak MPI_$ucname = pmpi_${lcname}_
829 #pragma weak mpi_${lcname}__ = pmpi_${lcname}_
830 #pragma weak mpi_${lcname}_ = pmpi_${lcname}_
831 #pragma weak mpi_${lcname} = pmpi_${lcname}_
832 #else
833 #pragma weak MPI_$ucname = pmpi_${lcname}
834 #pragma weak mpi_${lcname}__ = pmpi_${lcname}
835 #pragma weak mpi_${lcname}_ = pmpi_${lcname}
836 #pragma weak mpi_${lcname} = pmpi_${lcname}
837 #endif
838 \n\n";
839
840 print $OUTFD "\
841 #elif defined(HAVE_PRAGMA_WEAK)\
842
843 #if defined(F77_NAME_UPPER)\n";
844 &print_weak_decl( $OUTFD, "MPI_$ucname", $args, $lcname );
845 print $OUTFD "\
846 #pragma weak MPI_$ucname = PMPI_$ucname\
847 #elif defined(F77_NAME_LOWER_2USCORE)\n";
848 &print_weak_decl( $OUTFD, "mpi_${lcname}__", $args, $lcname );
849 print $OUTFD "\
850 #pragma weak mpi_${lcname}__ = pmpi_${lcname}__\
851 #elif !defined(F77_NAME_LOWER_USCORE)\n";
852 &print_weak_decl( $OUTFD, "mpi_$lcname", $args, $lcname );
853 print $OUTFD "\
854 #pragma weak mpi_$lcname = pmpi_$lcname\
855 #else\n";
856 &print_weak_decl( $OUTFD, "mpi_${lcname}_", $args, $lcname );
857 print $OUTFD "\
858 #pragma weak mpi_${lcname}_ = pmpi_${lcname}_\
859 #endif\
860 \
861 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)\
862 #if defined(F77_NAME_UPPER)\
863 #pragma _HP_SECONDARY_DEF PMPI_$ucname MPI_$ucname\
864 #elif defined(F77_NAME_LOWER_2USCORE)\
865 #pragma _HP_SECONDARY_DEF pmpi_${lcname}__ mpi_${lcname}__\
866 #elif !defined(F77_NAME_LOWER_USCORE)\
867 #pragma _HP_SECONDARY_DEF pmpi_$lcname mpi_$lcname\
868 #else\
869 #pragma _HP_SECONDARY_DEF pmpi_${lcname}_ mpi_${lcname}_\
870 #endif\
871 \
872 #elif defined(HAVE_PRAGMA_CRI_DUP)\
873 #if defined(F77_NAME_UPPER)\
874 #pragma _CRI duplicate MPI_$ucname as PMPI_$ucname\
875 #elif defined(F77_NAME_LOWER_2USCORE)\
876 #pragma _CRI duplicate mpi_${lcname}__ as pmpi_${lcname}__\
877 #elif !defined(F77_NAME_LOWER_USCORE)\
878 #pragma _CRI duplicate mpi_${lcname} as pmpi_${lcname}\
879 #else\
880 #pragma _CRI duplicate mpi_${lcname}_ as pmpi_${lcname}_\
881 #endif\
882 #endif /* HAVE_PRAGMA_WEAK */\
883 #endif /* USE_WEAK_SYMBOLS */\
884 /* End MPI profiling block */\n\n";
885
886 &AddFwrapWeakName( $lcname, $ucname, $args );
887 }
888 }
889
890 #
891 # Print the code that modifies the name
892 # The function prototypes must be loaded *after* the name block so that the
893 # name used in the function prototypes will match the one that is declared
894 # in this file.
895 sub print_name_map_block {
896 my $routine_name = $_[0];
897 my $lcname = $_[1];
898 my $ucname = uc($lcname);
899
900 # This include the code to map names for the profiling interface,
901 # using the same macro as for the rest of the MPI code
902 $uc_out_prefix = uc($out_prefix);
903 if ($do_profiling) {
904 # Remove the leading MPI_ if the name has it.
905 if ($routine_name =~ /^MPI_/) {
906 $routine_name =~ s/^MPI_//;
907 }
908 print $OUTFD "
909 /* Map the name to the correct form */
910 #ifndef MPICH_MPI_FROM_PMPI
911 #if defined(USE_WEAK_SYMBOLS) && defined(HAVE_MULTIPLE_PRAGMA_WEAK)
912 /* Define the weak versions of the PMPI routine*/
913 #ifndef F77_NAME_UPPER\n";
914 &print_weak_decl( $OUTFD, "PMPI_$ucname", $args, $lcname );
915 print $OUTFD "#endif\n#ifndef F77_NAME_LOWER_2USCORE\n";
916 &print_weak_decl( $OUTFD, "pmpi_${lcname}__", $args, $lcname );
917 print $OUTFD "#endif\n#ifndef F77_NAME_LOWER_USCORE\n";
918 &print_weak_decl( $OUTFD, "pmpi_${lcname}_", $args, $lcname );
919 print $OUTFD "#endif\n#ifndef F77_NAME_LOWER\n";
920 &print_weak_decl( $OUTFD, "pmpi_${lcname}", $args, $lcname );
921 print $OUTFD "
922 #endif
923
924 #if defined(F77_NAME_UPPER)
925 #pragma weak pmpi_${lcname}__ = PMPI_${ucname}
926 #pragma weak pmpi_${lcname}_ = PMPI_${ucname}
927 #pragma weak pmpi_${lcname} = PMPI_${ucname}
928 #elif defined(F77_NAME_LOWER_2USCORE)
929 #pragma weak PMPI_$ucname = pmpi_${lcname}__
930 #pragma weak pmpi_${lcname}_ = pmpi_${lcname}__
931 #pragma weak pmpi_${lcname} = pmpi_${lcname}__
932 #elif defined(F77_NAME_LOWER_USCORE)
933 #pragma weak PMPI_$ucname = pmpi_${lcname}_
934 #pragma weak pmpi_${lcname}__ = pmpi_${lcname}_
935 #pragma weak pmpi_${lcname} = pmpi_${lcname}_
936 #else
937 #pragma weak PMPI_$ucname = pmpi_${lcname}
938 #pragma weak pmpi_${lcname}__ = pmpi_${lcname}
939 #pragma weak pmpi_${lcname}_ = pmpi_${lcname}
940 #endif /* Test on name mapping */
941 #endif /* Use multiple pragma weak */
942
943 #ifdef F77_NAME_UPPER
944 #define ${out_prefix}${lcname}_ PMPI_${ucname}
945 #elif defined(F77_NAME_LOWER_2USCORE)
946 #define ${out_prefix}${lcname}_ pmpi_${lcname}__
947 #elif !defined(F77_NAME_LOWER_USCORE)
948 #define ${out_prefix}${lcname}_ pmpi_${lcname}
949 #else
950 #define ${out_prefix}${lcname}_ pmpi_${lcname}_
951 #endif /* Test on name mapping */
952
953 /* This defines the routine that we call, which must be the PMPI version
954 since we're renaming the Fortran entry as the pmpi version. The MPI name
955 must be undefined first to prevent any conflicts with previous renamings,
956 such as those put in place by the globus device when it is building on
957 top of a vendor MPI. */
958 #undef MPI_${routine_name}
959 #define MPI_${routine_name} PMPI_${routine_name}
960
961 #else
962 ";
963 }
964 print $OUTFD "
965 #ifdef F77_NAME_UPPER
966 #define ${out_prefix}${lcname}_ ${uc_out_prefix}${ucname}
967 #elif defined(F77_NAME_LOWER_2USCORE)
968 #define ${out_prefix}${lcname}_ ${out_prefix}${lcname}__
969 #elif !defined(F77_NAME_LOWER_USCORE)
970 #define ${out_prefix}${lcname}_ ${out_prefix}${lcname}
971 /* Else leave name alone */
972 #endif
973
974 ";
975 if ($do_profiling) {
976 print $OUTFD "
977 #endif /* MPICH_MPI_FROM_PMPI */
978 ";
979 }
980 }
981
982 # Print the arguments for the routine DEFINITION.
983 sub print_args {
984 my @parms = split(/\s*,\s*/, $_[1] );
985 my $OUTFD = $_[0];
986 my $count = 1;
987 my $last_args = "";
988 my $prototype_only = $_[2];
989 my $routine = $_[3];
990
991 # Clear the @arg_addresses and $arg_qualifiers array.
992 $#arg_addresses = -1;
993 $#arg_qualifiers = -1;
994
995 # Special case: if the only parm is "void", remove it from the list
996 print STDERR "Nparms = $#parms, parms = " . join(',',@parms) . "\n" if $debug;
997 if ($#parms == 0 && $parms[0] eq "void") {
998 print $OUTFD "( void )";
999 return
1000 }
1001 # argsep is used to add a comma before every argument, except for the
1002 # first
1003 $argsep = "";
1004 print $OUTFD "( ";
1005 foreach $parm (@parms) {
1006 # Match type to replacement
1007 print "parm = :$parm:\n" if $debug;
1008 # Remove qualifiers from the parm
1009 $arg_qualifiers[$count] = "";
1010 if ($parm =~ /^const\s+/) {
1011 $parm =~ s/^const\s+//;
1012 $arg_qualifiers[$count] .= "const ";
1013 }
1014 # remove all "const"
1015 $parm =~ s/const//;
1016
1017 if ($parm =~ /^restrict\s+/) {
1018 $parm =~ s/restrict\s+//;
1019 $arg_qualifiers[$count] .= "restrict ";
1020 }
1021 # remove leading whitespace
1022 $parm =~ s/^\s+//;
1023
1024 # Remove arg names from array types
1025 if ($parm =~ /(\w+)\s+(\w+)\s*\[\]/) {
1026 # Assume that this is <type> <name>[]; convert to <type>[]
1027 print " Removing argname $2 from parm array $parm\n" if $debug;
1028 $parm = "$1" . "[]";
1029 }
1030 elsif ($parm =~ /(\w+)\s*\*\s*(\w+)\s*\[\]/) {
1031 # Assume that this is <type>* <name>[]; convert to <type>*
1032 print " Removing argname $2 from parm array $parm\n" if $debug;
1033 $parm = "$1" . "*";
1034 }
1035 elsif ($parm =~ /(\w+)\s*\*\s*\*\s*(\w+)/) {
1036 # Remove arg names from pointer types
1037 # Assume that this is <type>** ; convert to <type>*
1038 print " Removing argname $2 from parm pointer\n" if $debug;
1039 $parm = "$1" . "*";
1040 }
1041 elsif ($parm =~ /(\w+)\s*\*\s*(\w+)/) {
1042 # Remove arg names from pointer types
1043 # Assume that this is <type>* ; convert to <type>*
1044 print " Removing argname $2 from parm pointer\n" if $debug;
1045 $parm = "$1" . "*";
1046 }
1047 # Remove blanks from the parm
1048 $parm =~ s/\s+//;
1049 $arg_addresses[$count] = 0;
1050
1051 # This handles routines that have special declaration requirements
1052 # for particular arguments
1053 if (defined($declarg{"$routine-$count"})) {
1054 print " Using declarg{$routine} for this parm\n" if $debug;
1055 $parm = $declarg{"$routine-$count"};
1056 if ($prototype_only) {
1057 print $OUTFD "$argsep$parm";
1058 }
1059 else {
1060 print $OUTFD "$argsep$parm v$count";
1061 }
1062 }
1063 elsif ($parm =~ /char\s*\*/) {
1064 # char's go out at char *v FORT_MIXED_LEN(d)
1065 # and FORT_END_LEN(d) at the end
1066 # (even if an array, because at the Fortran level, it
1067 # is still a pointer to a character variable; the length
1068 # of each entry in the array is the "d" value).
1069 # FORT_END_LEN and FORT_MIXED_LEN contain the necessary comman
1070 # if they are prsent at all.
1071 print " parm is a character string\n" if $debug;
1072 if ($prototype_only) {
1073 print $OUTFD "${argsep}char * FORT_MIXED_LEN_DECL";
1074 $last_args .= "FORT_END_LEN_DECL ";
1075 }
1076 else {
1077 print $OUTFD "${argsep}char *v$count FORT_MIXED_LEN(d$count)";
1078 $last_args .= "FORT_END_LEN(d$count) ";
1079 }
1080 }
1081 elsif ($parm =~/\[/) {
1082 # Argument type is array, so we need to
1083 # a) mark as containing a star
1084 # b) place parameter correctly
1085 $star_count = 1;
1086 $arg_addresses[$count] = $star_count;
1087 # Split into raw type and []
1088 # Use \S* instead of the equivalent [^\s]*.
1089 # (\S is not-a-space)
1090 # perl 5.8 is known to mishandle the latter, leading to
1091 # an empty basetype
1092 if ($parm =~ /\s*(\S*)\s*(\[\s*\])/) {
1093 $basetype = $1;
1094 }
1095 else {
1096 print STDERR "Internal error. Could not find basetype\n";
1097 print STDERR "This may be a bug in perl in the handling of certain expressions\n";
1098 }
1099 print "\tparm $parm is array of >$basetype<\n" if $debug;
1100 #$foundbrack = $2;
1101 if (defined($tof77{$parm})) {
1102 # This is a special case; the full type is defined.
1103 # This is used, for example, for int [][3] in the
1104 # routines that specify a range.
1105 print "Matched to full type $parm with replacement $tof77{$parm}\n" if $debug;
1106 # We use the replacement type
1107 $basetype = $tof77{$parm};
1108 $star_count = 0;
1109 $arg_addresses[$count] = $star_count;
1110 }
1111 elsif ($basetype eq "int") {
1112 # Do nothing because the [] added to the arg below
1113 # is all that is necessary.
1114 $star_count = 0;
1115 $arg_addresses[$count] = $star_count;
1116 }
1117 elsif (defined($tof77{"$basetype\[\]"})) {
1118 # Use the code for handling array parameters if
1119 # mapping code is provided.
1120 print "Match to array type $basetype\[\]\n" if $debug;
1121 $star_count = 0;
1122 $arg_addresses[$count] = $star_count;
1123 $basetype = $tof77{"$basetype\[\]"};
1124 }
1125 elsif (defined($tof77{$basetype})) {
1126 # FIXME: This code (now commented out) is not correct
1127 print STDERR "Using fall through for $basetype in $routine\n" if $debug;
1128 # if ($useOldCode eq "yes") {
1129 # $nstar_before = ($basetype =~ /\*/);
1130 # $basetype = $tof77{$basetype};
1131 # # The following fixes the case where the underlying type
1132 # # is a simple int.
1133 # if ($basetype eq "int") {
1134 # $arg_addresses[$count] = 0;
1135 # }
1136 # print "\tparm has defined type of $basetype\n" if $debug;
1137 # $nstar_after = ($basetype =~ /\*/);
1138 # if ($nstar_before != $nstar_after) {
1139 # $star_count++;
1140 # }
1141 # If we have an array, and a type mapping to fortran
1142 # We want to simply pretend that all is well (like int
1143 # above)
1144 $star_count = 0;
1145 $arg_addresses[$count] = $star_count;
1146 }
1147 if ($prototype_only) {
1148 print $OUTFD "$argsep$basetype \[\]";
1149 }
1150 else {
1151 print $OUTFD "$argsep$basetype v$count\[\]";
1152 }
1153 }
1154 else {
1155 $nstar_before = ($parm =~ /\*/);
1156 $nstar_after = $nstar_before;
1157 print "Nstar = $nstar_after\n" if $debug;
1158 if (defined($tof77{$parm})) {
1159 $parm = $tof77{$parm};
1160 $nstar_after = ($parm =~ /\*/);
1161 }
1162 $leadspace = "";
1163 if ($parm =~ /\w$/) {
1164 $leadspace = " ";
1165 }
1166 if ($prototype_only) {
1167 print $OUTFD "${argsep}${parm}";
1168 }
1169 else {
1170 if ($parm =~ /^(\w+)\*$/) {
1171 # make "type*" to "type *"
1172 $parm = "$1" . " *";
1173 }
1174 print $OUTFD "${argsep}${parm}${leadspace}v$count";
1175 }
1176 $star_count = 0;
1177 if ($nstar_before != $nstar_after) {
1178 $star_count = 1;
1179 }
1180 $arg_addresses[$count] = $star_count;
1181 }
1182 $count++;
1183 $argsep = ", ";
1184 }
1185 # Add the new error return code if necessary
1186 $tmpargs= $errparm;
1187 $tmpargs =~ s/\s*//g;
1188 if ($tmpargs ne "") {
1189 if ($prototype_only) {
1190 print $OUTFD "$argsep$errparmtype";
1191 }
1192 else {
1193 print $OUTFD "$argsep$errparm";
1194 }
1195 }
1196 print $OUTFD " $last_args";
1197 print $OUTFD ")";
1198 }
1199
1200 # Print the arguments for the routine CALL.
1201 # Handle the special arguments
1202 sub print_call_args {
1203 my @parms = split(/\s*,\s*/, $_[0] );
1204 my $count = 1;
1205 my $first = 1;
1206 print $OUTFD "( ";
1207 # Special case: if the only parm is "void", remove it from the list
1208 if ($#parms == 0 && $parms[0] eq "void") {
1209 $#parms = -1;
1210 }
1211
1212 foreach $parm (@parms) {
1213 $parm =~ s/^const\s//; # Remove const if present
1214 # Remove variable name if present in an array arg
1215 if ($parm =~ /(.*)\s+(\w+)\[\]/) {
1216 $parm = "$1 \[\]";
1217 }
1218 # Compress multiple spaces
1219 $parm =~ s/\s\s/ /g;
1220 if (!$first) { print $OUTFD ", "; } else { $first = 0; }
1221
1222 if (defined($special_args{"${routine_name}-$count"})) {
1223 # We must handle this argument specially
1224 &print_special_call_arg( $routine_name, $count );
1225 }
1226 elsif ($parm =~ /!/) {
1227 # This parameter is a special case; the exclamation point
1228 # is used to say "call with this argument as is"
1229 $parm =~ s/!//;
1230 print $OUTFD $parm;
1231 }
1232 else {
1233 # Convert to/from object type as required.
1234 #print "TMP: parm = $arg_qualifiers[$count]$parm\n";
1235 $fullparm="$arg_qualifiers[$count]$parm";
1236 if (defined($argsneedcast{$fullparm})) {
1237 $argval = "v$count";
1238 if ($arg_addresses[$count] > 0) {
1239 $argval = "*$argval";
1240 }
1241 $callparm = $argsneedcast{$fullparm};
1242 $callparm =~ s/ARG/$argval/;
1243 print $OUTFD "$callparm";
1244 }
1245 else {
1246 # Since MPICH objects are ints, we don't need to do
1247 # anything unless MPI_Fint and int are different.
1248 # print STDERR "XXX $count $#arg_addresses XXX\n";
1249 if ($arg_addresses[$count] > 0) {
1250 print $OUTFD "*";
1251 }
1252 print $OUTFD "v$count";
1253 }
1254 }
1255 $count++;
1256 }
1257 print $OUTFD " );\n";
1258 }
1259
1260 # Print the option function attribute; this supports GCC, particularly
1261 # the __atribute__ ((weak)) option. Unfortunately, the name must be
1262 # made into a string and inserted into the attribute list.
1263 sub print_attr {
1264 my $OUTFD = $_[0];
1265 my $name = $_[1];
1266 if ($do_weak) {
1267 print $OUTFD " FUNC_ATTRIBUTES($name)";
1268 }
1269 }
1270
1271 #
1272 # We allow a routine to specify an alternate weak decl by name
1273 sub set_weak_decl {
1274 my $name = $_[0];
1275 my $decl = $_[1];
1276 my $rtype = $_[2];
1277 $name = lc($name);
1278 $altweak{$name} = $decl;
1279 $altweakrtype{$name} = $rtype;
1280 }
1281 sub print_weak_decl {
1282 my $OUTFD = $_[0];
1283 my $name = $_[1];
1284 my $args = $_[2];
1285 my $lcname = $_[3];
1286
1287 my $basename = lc($name);
1288 $basename =~ s/_*$//;
1289 if (defined($altweak{$basename})) {
1290 print $OUTFD "extern FORTRAN_API $altweakrtype{$basename} FORT_CALL $name($altweak{$basename});\n";
1291 }
1292 else {
1293 print $OUTFD "extern FORTRAN_API $returnType FORT_CALL $name";
1294 &print_args( $OUTFD, $args, 1, $lcname );
1295 print $OUTFD ";\n";
1296 }
1297 }
1298 #
1299 # --------------------------------------------------------------------------
1300 # Special processing
1301 #
1302 # Each parameter can be processed by a routine, with the suffix controlling
1303 # the routine invoked for each step. Roughly, these are:
1304 #
1305 # void foo( MPI_Fint *v1, etc )
1306 # {
1307 # /* Special declarations needed for the variables */
1308 # <name>_<direction>_decl( <argnum> )
1309 # /* Special processing need for in variables */
1310 # <name>_ftoc( <argnum> )
1311 # /* Call the function. Replace special arguments with the output from */
1312 # <name>_<direction>_arg( <argnum> )
1313 # /* Special post call processing (for out variables) */
1314 # <name>_ctof( l$count, v$count ) /* local (C) variable name, fortran var name */
1315 #
1316 # Special case: For parameters that are arrays, the size of the
1317 # array is in $Array_size.
1318 #
1319 #
1320 # --------------------------------------------------------------------------
1321 # Buffer pointers
1322 sub bufptr_ftoc {
1323 my $count = $_[0];
1324 }
1325 sub bufptr_in_decl {
1326 my $count = $_[0];
1327 }
1328 sub bufptr_in_arg {
1329 my $count = $_[0];
1330 if ($do_bufptr) {
1331 print $OUTFD "MPIR_F_PTR(v$count)";
1332 }
1333 else {
1334 print $OUTFD "v$count";
1335 }
1336 }
1337 # bufptr_ctof( cvar, fvar )
1338 sub bufptr_ctof {
1339 my $coutvar = $_[0];
1340 my $outvar = $_[1];
1341 }
1342 # --------------------------------------------------------------------------
1343 # MPI_IN_PLACE buffer pointers
1344 sub inplace_ftoc {
1345 my $count = $_[0];
1346 &specialInitStatement( $OUTFD );
1347 print $OUTFD " if (v$count == MPIR_F_MPI_IN_PLACE) v$count = MPI_IN_PLACE;\n";
1348 }
1349 sub inplace_in_decl {
1350 my $count = $_[0];
1351 }
1352 sub inplace_in_arg {
1353 my $count = $_[0];
1354 print $OUTFD "v$count";
1355 }
1356 # inplace_ctof( cvar, fvar )
1357 sub inplace_ctof {
1358 my $coutvar = $_[0];
1359 my $outvar = $_[1];
1360 }
1361 # --------------------------------------------------------------------------
1362 # Logical variables
1363 sub logical_ftoc {
1364 my $count = $_[0];
1365 print $OUTFD " l$count = MPIR_FROM_FLOG(*v$count);\n";
1366 }
1367 sub logical_in_decl {
1368 my $count = $_[0];
1369 if ($do_logical) {
1370 print $OUTFD " int l$count;\n";
1371 }
1372 }
1373 sub logical_in_arg {
1374 my $count = $_[0];
1375 if ($do_logical) {
1376 print $OUTFD "l$count";
1377 }
1378 else {
1379 print $OUTFD "v$count";
1380 }
1381 }
1382 # logical_ctof( cvar, fvar )
1383 sub logical_ctof {
1384 my $coutvar = $_[0];
1385 my $outvar = $_[1];
1386 if ($do_logical) {
1387 print $OUTFD " *$outvar = MPIR_TO_FLOG($coutvar);\n";
1388 }
1389 }
1390 sub logical_out_decl {
1391 my $count = $_[0];
1392 if ($do_logical) {
1393 print $OUTFD " int l$count;\n";
1394 }
1395 }
1396 sub logical_out_arg {
1397 my $count = $_[0];
1398 if ($do_logical) {
1399 print $OUTFD "\&l$count";
1400 }
1401 else {
1402 print $OUTFD "v$count";
1403 }
1404 }
1405 # --------------------------------------------------------------------------
1406 #
1407 # Logical variables, but for an array.
1408 # Array args can use the global $Array_size and $Array_typedef if necessary
1409 sub logical_array_ftoc {
1410 print $OUTFD "\
1411 {int li;
1412 for (li=0; li<$Array_size; li++) {
1413 l$count\[li\] = MPIR_FROM_FLOG(v$count\[li\]);
1414 }
1415 }
1416 ";
1417 }
1418 sub logical_array_in_decl {
1419 my $count = $_[0];
1420 print $OUTFD " int *l$count = (int *)$malloc(sizeof(int) * ($Array_size));\n";
1421 $clean_up .= " $free(l$count);\n";
1422 }
1423 sub logical_array_in_arg {
1424 my $count = $_[0];
1425 print $OUTFD "l$count";
1426 }
1427
1428 sub logical_array_ctof {
1429 my $coutvar = $_[0];
1430 my $outvar = $_[1];
1431 print $OUTFD "\
1432 {int li;
1433 for (li=0; li<$Array_size; li++) {
1434 $outvar\[li\] = MPIR_TO_FLOG($outvar\[li\]);
1435 }
1436 }
1437 ";
1438 }
1439 sub logical_array_out_decl {
1440 }
1441 sub logical_array_out_arg {
1442 my $count = $_[0];
1443 print $OUTFD "v$count";
1444 }
1445 # --------------------------------------------------------------------------
1446 #
1447 # Index variables.
1448 # Index variables are not optional, since the values of the variable
1449 # are changed.
1450 sub index_ftoc {
1451 my $count = $_[0];
1452 }
1453 sub index_ctof {
1454 my $coutvar = $_[0];
1455 my $outvar = $_[1];
1456 print $OUTFD " *$outvar = (MPI_Fint)$coutvar;\n";
1457 print $OUTFD " if ($coutvar >= 0) *$outvar = *$outvar + 1;\n";
1458 }
1459 sub index_out_decl {
1460 my $count = $_[0];
1461 print $OUTFD " int l$count;\n";
1462 }
1463 sub index_out_arg {
1464 my $count = $_[0];
1465 print $OUTFD " \&l$count";
1466 }
1467 #
1468 # Index variables, but for an array.
1469 # Array args can use the global $Array_size and $Array_typedef if necessary
1470 sub index_array_ftoc {
1471 my $count = $_[0];
1472 }
1473 sub index_array_ctof {
1474 my $coutvar = $_[0];
1475 my $outvar = $_[1];
1476 print $OUTFD "\
1477 {int li;
1478 for (li=0; li<$Array_size; li++) {
1479 if ($outvar\[li\] >= 0) $outvar\[li\] += 1;
1480 }
1481 }
1482 "
1483 }
1484 sub index_array_out_decl {
1485 }
1486 sub index_array_out_arg {
1487 my $count = $_[0];
1488 print $OUTFD "v$count";
1489 }
1490 # --------------------------------------------------------------------------
1491 #
1492 # Address and attribute handling
1493 # Note that this construction can lead to compiler warnings on systems
1494 # where an address is larger than an MPI_Fint. This is correct; these
1495 # routines are for the MPI-1 routines that use an MPI_Fint where the
1496 # C code uses a void * (MPI_Aint in MPI-2).
1497 # Instead of using MPI_Aint, we use MPIR_Pint. This allows the MPI
1498 # implementation to set MPI_Aint to be *larger* than a pointer-sized-int,
1499 # which is needed (as a temporary workaround) on systems like Blue Gene, which
1500 # have 4 byte pointers but file systems that need 8 byte datatypes (not just
1501 # offsets).
1502 # A possible extension is to provide an error warning (much as
1503 # MPI_Address does) when the attribute value loses bits when assigned into
1504 # the MPI_Fint.
1505 #in:addrint
1506 #out:attrint:4
1507 sub addrint_ftoc {
1508 my $count = $_[0];
1509 }
1510 sub addrint_in_decl {
1511 }
1512 sub addrint_in_arg {
1513 my $count = $_[0];
1514 print $OUTFD "(void *)(MPIR_Pint)((int)*(int *)v$count)";
1515 }
1516
1517 sub attrint_ctof {
1518 my $fvar = $_[0];
1519 my $cvar = $_[1];
1520 my $flagarg = 4; # get from option
1521 # The double cast of attr$cvar first to MPIR_Pint and then to MPI_Fint
1522 # keeps some compilers happy on 64-bit platforms
1523 print $OUTFD "
1524 if ((int)*ierr || !l$flagarg) {
1525 *(MPI_Fint*)$cvar = 0;
1526 }
1527 else {
1528 *(MPI_Fint*)$cvar = (MPI_Fint)(MPIR_Pint)attr$cvar;
1529 }\n";
1530 }
1531
1532 sub attrint_out_decl {
1533 my $count = $_[0];
1534 print $OUTFD " void *attrv$count;\n";
1535 }
1536
1537 sub attrint_out_arg {
1538 my $count = $_[0];
1539 print $OUTFD "&attrv$count";
1540 }
1541 # --------------------------------------------------------------------------
1542 # Address and attribute handling
1543 # This version of attrint uses Aints instead of ints, and is appropriate
1544 # for the MPI-2 attribute caching functions
1545 #in:addraint
1546 #out:attraint:4
1547 sub addraint_ftoc {
1548 my $count = $_[0];
1549 }
1550 sub addraint_in_decl {
1551 }
1552 sub addraint_in_arg {
1553 my $count = $_[0];
1554 print $OUTFD "(void *)(*(MPI_Aint *)v$count)";
1555 }
1556
1557 sub attraint_ctof {
1558 my $fvar = $_[0];
1559 my $cvar = $_[1];
1560 my $flagarg = 4; # get from option
1561 print $OUTFD "
1562 if ((int)*ierr || !l$flagarg) {
1563 *(MPI_Aint*)$cvar = 0;
1564 }
1565 else {
1566 *(MPI_Aint*)$cvar = (MPI_Aint)attr$cvar;
1567 }\n";
1568 }
1569
1570 sub attraint_out_decl {
1571 my $count = $_[0];
1572 print $OUTFD " void *attrv$count;\n";
1573 }
1574
1575 sub attraint_out_arg {
1576 my $count = $_[0];
1577 print $OUTFD "&attrv$count";
1578 }
1579 # --------------------------------------------------------------------------
1580 #
1581 # Buffer Address output handling (Buffer_detach)
1582 #out:bufaddr
1583 sub bufaddr_ftoc {
1584 }
1585 sub bufaddr_out_decl {
1586 my $count =$_[0];
1587 print $OUTFD " void *t$count = v$count;\n";
1588 }
1589 sub bufaddr_out_arg {
1590 my $count = $_[0];
1591 print $OUTFD "&t$count";
1592 }
1593
1594 sub bufaddr_ctof {
1595 my $fvar = $_[0];
1596 my $cvar = $_[1];
1597 }
1598 # --------------------------------------------------------------------------
1599 #
1600 # Handle MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE
1601 sub status_ftoc {
1602 my $count = $_[0];
1603 # Cast MPI_STATUS_IGNORE back to an MPI_Fint (we'll re-cast it back
1604 # to (MPI_Status *) in the call to the C version of the routine)
1605 &specialInitStatement( $OUTFD );
1606 print $OUTFD "\
1607 if (v$count == MPI_F_STATUS_IGNORE) { v$count = (MPI_Fint*)MPI_STATUS_IGNORE; }\n";
1608 }
1609 sub status_ctof {
1610 my $coutvar = $_[0];
1611 my $outvar = $_[1];
1612 }
1613 sub status_in_decl {
1614 my $count = $_[0];
1615 }
1616 sub status_in_arg {
1617 my $count = $_[0];
1618 print $OUTFD "(MPI_Status *)v$count";
1619 }
1620 # --------------------------------------------------------------------------
1621 #
1622 # Handle MPI_ERRCODES_IGNORE
1623 sub errcodesignore_ftoc {
1624 my $count = $_[0];
1625 &specialInitStatement( $OUTFD );
1626 print $OUTFD "\
1627 if (v$count == MPI_F_ERRCODES_IGNORE) { v$count = MPI_ERRCODES_IGNORE; }\n";
1628 }
1629 sub errcodesignore_ctof {
1630 my $coutvar = $_[0];
1631 my $outvar = $_[1];
1632 }
1633 sub errcodesignore_in_decl {
1634 my $count = $_[0];
1635 }
1636 sub errcodesignore_in_arg {
1637 my $count = $_[0];
1638 print $OUTFD "(int *)v$count";
1639 }
1640 # --------------------------------------------------------------------------
1641 #
1642 # Index variables, but for an array.
1643 # Array args can use the global $Array_size and $Array_typedef if necessary
1644 sub status_array_ftoc {
1645 my $count = $_[0];
1646 &specialInitStatement( $OUTFD );
1647 print $OUTFD "\
1648 if (v$count == MPI_F_STATUSES_IGNORE) { v$count = (MPI_Fint *)MPI_STATUSES_IGNORE; }\n";
1649 }
1650 sub status_array_ctof {
1651 my $coutvar = $_[0];
1652 my $outvar = $_[1];
1653 }
1654 sub status_array_in_decl {
1655 }
1656 sub status_array_in_arg {
1657 my $count = $_[0];
1658 print $OUTFD "(MPI_Status *)v$count";
1659 }
1660 # --------------------------------------------------------------------------
1661 # aintToint
1662 sub aintToInt_ctof {
1663 my $coutvar = $_[0];
1664 my $outvar = $_[1];
1665 print $OUTFD " *$outvar = (MPI_Fint)($coutvar);\n";
1666 }
1667 sub aintToInt_out_decl {
1668 my $count = $_[0];
1669 print $OUTFD " MPI_Aint l$count;\n";
1670 }
1671 sub aintToInt_out_arg {
1672 my $count = $_[0];
1673 print $OUTFD "\&l$count";
1674 }
1675 # --------------------------------------------------------------------------
1676 # aintToVal - Convert address of Aint to value
1677 sub aintToVal_ftoc {
1678 my $coutvar = $_[0];
1679 my $outvar = $_[1];
1680 }
1681 sub aintToVal_in_decl {
1682 my $count = $_[0];
1683 }
1684 sub aintToVal_in_arg {
1685 my $count = $_[0];
1686 print $OUTFD "*v$count";
1687 }
1688 # ---------------------------------------------------------------------------
1689 # This is the routine that handles the post-call processing
1690 sub print_post_call {
1691 my $routine_name = $_[0];
1692 my $args = $_[1];
1693 if (defined($special_args{$routine_name})) {
1694 # Erg. Special processing
1695 foreach $count (split(/:/,$special_args{$routine_name})) {
1696 $rule = $special_args{"${routine_name}-$count"};
1697 ($direction,$method,$Array_size) = split(/:/,$rule);
1698 print STDERR "$routine_name: dir = $direction, method = $method\n" if $debug;
1699 $processing_in_routine = "${method}_in_ctof";
1700 if ($direction eq "out" || $direction eq "inout") {
1701 $processing_routine = "${method}_ctof";
1702 &$processing_routine( "l$count", "v$count" );
1703 }
1704 elsif (defined(&$processing_in_routine)) {
1705 # Invoke even for "in" args incase we need to free a temp
1706 &$processing_in_routine( "l$count", "v$count" );
1707 }
1708 if ($clean_up ne "") {
1709 print $OUTFD $clean_up;
1710 $clean_up = "";
1711 }
1712 }
1713 }
1714
1715 # Handle here any special post-only calls
1716 if (defined($specialPost{$routine_name})) {
1717 my $argnum = $specialPost{$routine_name};
1718 my $postRoutine = $specialPost{"$routine_name-$argnum"};
1719 &$postRoutine( $OUTFD, $argnum );
1720 }
1721 }
1722 #
1723 # ---------------------------------------------------------------------------
1724 #
1725 # Blankpad strings
1726 # This is complicated by the fact that the Fortran strings do not contain
1727 # null terminators and the MPI definitions of string lengths, such as
1728 # MPI_MAX_PORT_NAME, are one smaller in Fortran than in C (see 4.12.9
1729 # in the MPI-2 specification). Because of this, we need to allocate a
1730 # temporary that is one longer on
1731 sub blankpad_out_decl {
1732 my $count = $_[0];
1733 print $OUTFD " char *p$count;\n";
1734 }
1735 sub blankpad_out_arg {
1736 my $count = $_[0];
1737 print $OUTFD "p$count";
1738 }
1739 sub blankpad_out_ftoc {
1740 my $count = $_[0];
1741
1742 # Allocate space to hold the C version of the output
1743 $strlen = "d$count";
1744 print $OUTFD " p$count = (char *)$malloc((size_t)$strlen + 1);\n";
1745 }
1746 sub blankpad_ctof {
1747 my $coutvar = $_[0];
1748 my $outvar = $_[1];
1749
1750 # find the null character. Replace with blanks from there to the
1751 # end of the string. The declared lenght is given by a variable
1752 # whose name is derived from outvar
1753 $strlen = $outvar;
1754 $strlen =~ s/^v/d/;
1755 my $cvar = $outvar;
1756 $cvar =~ s/^v/p/;
1757 print $OUTFD "
1758 if (ierr == NC_NOERR) {
1759 char *p = $outvar, *pc=$cvar;
1760 while (*pc) {*p++ = *pc++;}
1761 while ((p-$outvar) < $strlen) { *p++ = ' '; }
1762 }\n";
1763 $clean_up .= " $free($cvar);\n";
1764 }
1765 #
1766 # Blankpad strings if a flag is true (for info_get, perhaps others?)
1767 # This is complicated by the fact that the Fortran strings do not contain
1768 # null terminators and the MPI definitions of string lengths, such as
1769 # MPI_MAX_PORT_NAME, are one smaller in Fortran than in C (see 4.12.9
1770 # in the MPI-2 specification). Because of this, we need to allocate a
1771 # temporary that is one longer on
1772 sub blankpadonflag_out_decl {
1773 my $count = $_[0];
1774 print $OUTFD " char *p$count;\n";
1775 }
1776 sub blankpadonflag_out_arg {
1777 my $count = $_[0];
1778 print $OUTFD "p$count";
1779 }
1780 sub blankpadonflag_out_ftoc {
1781 my $count = $_[0];
1782
1783 # Allocate space to hold the C version of the output
1784 $strlen = "d$count";
1785 print $OUTFD " p$count = (char *)$malloc((size_t)$strlen + 1);\n";
1786 }
1787 sub blankpadonflag_ctof {
1788 my $coutvar = $_[0];
1789 my $outvar = $_[1];
1790
1791 # find the null character. Replace with blanks from there to the
1792 # end of the string. The declared lenght is given by a variable
1793 # whose name is derived from outvar
1794 $strlen = $outvar;
1795 $strlen =~ s/^v/d/;
1796 my $cvar = $outvar;
1797 $cvar =~ s/^v/p/;
1798 print $OUTFD "\
1799 if ($Array_size) {char *p = $outvar, *pc=$cvar;
1800 while (*pc) {*p++ = *pc++;}
1801 while ((p-$outvar) < $strlen) { *p++ = ' '; }
1802 }
1803 ";
1804 $clean_up .= " $free( $cvar );\n";
1805 }
1806
1807 # ---------------------------------------------------------------------------
1808 # Add null to input strings
1809 # We must make a copy
1810 sub addnull_in_decl {
1811 my $count = $_[0];
1812 print $OUTFD " char *p$count, *pt$count;\n";
1813 }
1814 sub addnull_in_arg {
1815 my $count = $_[0];
1816 print $OUTFD "p$count";
1817 }
1818 sub addnull_ftoc {
1819 my $count = $_[0];
1820
1821 # Working backwards from the length argument, find the first
1822 # nonblank character
1823 # end of the string. The declared length is given by a variable
1824 # whose name is derived from outvar
1825 $strlen = "v$count";
1826 $strlen =~ s/^v/d/;
1827 print $OUTFD "\
1828 pt$count = v$count + $strlen - 1; /* point to the end of string v$count */
1829 while (*pt$count == ' ' && pt$count > v$count) pt$count--; /* find the last non-blank */
1830 pt$count++;
1831 /* it is possible character array v$count is of exact lenght $strlen */
1832 p$count = (char *) $malloc((size_t)(pt$count-v$count) + 1);
1833 memcpy(p$count, v$count, (size_t)(pt$count-v$count));
1834 p$count\[pt$count-v$count\] = '\\0';
1835 ";
1836 $clean_up .= " $free(p$count);\n";
1837 }
1838 # ----------------------------------------------------------------------------
1839 # Add null to input strings, also trim all LEADING and trailing blanks.
1840 # This is required by Info_set (but not explicitly for the other
1841 # routines).
1842 # We must make a copy
1843 sub addnullandtrim_in_decl {
1844 my $count = $_[0];
1845 print $OUTFD " char *p$count;\n";
1846 }
1847 sub addnullandtrim_in_arg {
1848 my $count = $_[0];
1849 print $OUTFD "p$count";
1850 }
1851 sub addnullandtrim_ftoc {
1852 my $count = $_[0];
1853
1854 # Working backwards from the length argument, find the first
1855 # nonblank character
1856 # end of the string. The declared length is given by a variable
1857 # whose name is derived from outvar
1858 $strlen = "v$count";
1859 $strlen =~ s/^v/d/;
1860 print $OUTFD "\
1861 {char *p = v$count + $strlen - 1;
1862 char *pin = v$count;
1863 int li;
1864 while (*p == ' ' && p > v$count) p--;
1865 p++;
1866 while (*pin == ' ' && pin < p) pin++;
1867 p$count = (char *)$malloc((size_t)(p-pin) + 1);
1868 for (li=0; li<(p-pin); li++) { p$count\[li\] = pin\[li\]; }
1869 p$count\[li\] = '\\0';
1870 }
1871 ";
1872 $clean_up .= " $free(p$count);\n";
1873 }
1874
1875 # ----------------------------------------------------------------------------
1876 # Add null to arrays of input strings
1877 # We must make a copy
1878 # chararray is used ONLY in comm_spawn
1879 sub chararray_in_decl {
1880 my $count = $_[0];
1881 print $OUTFD " char **p$count;\n";
1882 if (!$Array_size) { print $OUTFD " char *pcpy$count;\n"; }
1883 # pcpy<digit> is used for the case where the array length is not known
1884 print $OUTFD " int asize$count=0;\n";
1885 }
1886 sub chararray_in_arg {
1887 my $count = $_[0];
1888 print $OUTFD "p$count";
1889 }
1890 sub chararray_ftoc {
1891 my $count = $_[0];
1892
1893 # There is a special case - the input is MPI_ARGV_NULL. We
1894 # detect this by checking for a null string (all blanks).
1895 # The initialization of MPI_ARGV_NULL is done in the special
1896 #init setup
1897 &specialInitStatement( $OUTFD );
1898 # First, compute the number of elements. In Fortran, a null
1899 # string terminates the array. The array is stored as
1900 # a two-dimensional field of fixed-length characters.
1901 # Then copy the strings into the new storage, appending the
1902 # null at the end
1903 print $OUTFD "\
1904 { int i;
1905 char *ptmp;\n";
1906 if ($Array_size) {
1907 print $OUTFD "\
1908 asize$count = $Array_size + 1;\n";
1909 }
1910 else {
1911 print $OUTFD "\
1912 /* Compute the size of the array by looking for an all-blank line */
1913 pcpy$count = v$count;
1914 for (asize$count=1; 1; asize$count++) {
1915 char *pt = pcpy$count + d$count - 1;
1916 while (*pt == ' ' && pt > pcpy$count) pt--;
1917 if (*pt == ' ') break;
1918 pcpy$count += d$count;
1919 }\n";
1920 }
1921 print $OUTFD "\
1922 p$count = (char **)$malloc(sizeof(char *) * (asize$count));
1923 ptmp = (char *)$malloc((size_t)asize$count * (d$count + 1));
1924 for (i=0; i<asize$count-1; i++) {
1925 char *p = v$count + i * d$count, *pin, *pdest;
1926 int j;
1927
1928 pdest = ptmp + i * (d$count + 1);
1929 p$count\[i\] = pdest;
1930 /* Move to the end and work back */
1931 pin = p + d$count - 1;
1932 while (*pin == ' ' && pin > p) pin--;
1933 /* Copy and then null terminate */
1934 for (j=0; j<(pin-p)+1; j++) { pdest\[j\] = p\[j\]; }
1935 pdest\[j\] = '\\0';
1936 }
1937 /* Null terminate the array */
1938 p$count\[asize$count-1\] = '\\0';
1939 }\n";
1940 $clean_up .= " $free( p$count\[0\] ); $free( p$count );\n";
1941 }
1942
1943 # Add null to 2-dimensional arrays of input strings. Used only
1944 # by comm_spawn_multiple
1945 # FIXME : THIS CODE IS NOT CORRECT YET
1946 # Note the special handling of MPI_ARGVS_NULL
1947 sub chararray2_in_decl {
1948 my $count = $_[0];
1949 print $OUTFD " char ***p$count=0;\n";
1950 }
1951 sub chararray2_in_arg {
1952 my $count = $_[0];
1953 print $OUTFD "p$count";
1954 }
1955 sub chararray2_ftoc {
1956 my $count = $_[0];
1957
1958 if ($Array_size eq "") {
1959 print STDERR "A leading array size is required for 2-d Character arrays\n";
1960 return 1;
1961 }
1962
1963 # First, compute the number of elements. In Fortran, a null
1964 # string terminates the array. The array is stored as
1965 # a two-dimensional field of fixed-length characters.
1966 # Then copy the strings into the new storage, appending the
1967 # null at the end
1968 # Since this is a 2-d array, we always know the first dimension,
1969 # the second dimension must be computed, this is asize$count.
1970 # The first dimension is Array_size.
1971 &specialInitStatement( $OUTFD );
1972 print $OUTFD "\
1973 /* Check for the special case of a the null args case. */
1974 if (v$count == MPI_F_ARGVS_NULL) { v$count = (char *)MPI_ARGVS_NULL; }
1975 else {
1976 /* We must convert from the 2-dimensional Fortran array of
1977 fixed length strings to a C variable-sized array (really an
1978 array of pointers for each command of pointers to each
1979 argument, which is null terminated.*/\n";
1980
1981 # We must be careful. A blank line is ALL blank, not just leading blank
1982 # We must also be careful allocating the array, as C and Fortran
1983 # arrays are not the same. In C, for a two dimensional array
1984 # sized at run time, we must
1985 # allocate an array of pointers to arrays.
1986 # p = (char ***) malloc(sizeof(char **) * nrows)
1987 # where we are letting using p[nrows][colindex].
1988 # For MPI_Comm_spawn_multiple, each of these rows is for one command.
1989 # Each p[k] is a pointer to an array of character strings.
1990 # For MPI_Comm_spawn_multiple, all we know is that in the
1991 # corresponding Fortran code, the two-dimensional character array
1992 # contains an all-blank entry as the terminating element; the
1993 # corresponding C array must have a null entry (pointer) in
1994 # the corresponding position.
1995 # Thus, the C code must make several allocations:
1996 # p = nrows * sizeof(char **)
1997 # for p[k], (ncols + 1) * sizeof(char *)
1998 # for p[k][i], space for the ith input argument.
1999 # To reduce the number of allocations, we allocate space for all
2000 # elements on a row at one time.
2001
2002 # Purely local variables don't need $count
2003 print $OUTFD "\
2004 int k;
2005
2006 /* Allocate the array of pointers for the commands */
2007 p$count = (char ***)$malloc(sizeof(char **) * ($Array_size));
2008
2009 for (k=0; k<$Array_size; k++) {
2010 /* For each command, find the number of command-line arguments.
2011 They are terminated by an empty entry. */
2012 /* Find the first entry in the Fortran array for this row */
2013 char *p = v$count + k * d$count;
2014 int arglen = 0, argcnt=0, i;
2015 char **pargs, *pdata;
2016 for (argcnt=0; 1; argcnt ++) {
2017 char *pin = p + d$count - 1; /* Move to the end of the
2018 current Fortran string */
2019 while (*pin == ' ' && pin > p) pin--; /* Move backwards until
2020 we find a non-blank
2021 (Fortran is blank padded)*/
2022 if (pin == p && *pin == ' ') {
2023 /* found the terminating empty arg */
2024 break;
2025 }
2026 /* Keep track of the amount of space needed */
2027 arglen += (pin - p) + 2; /* add 1 for the null */
2028 /* Advance to the next entry in the array */
2029 p += ($Array_size) * d$count;
2030 }
2031
2032 /* argcnt is the number of provided arguments.
2033 Allocate the necessary elements and copy, null terminating copies */
2034 pargs = (char **)$malloc(sizeof(char*) * (argcnt+1));
2035 pdata = (char *)$malloc((size_t)arglen );
2036 p$count\[k\] = pargs;
2037 pargs\[argcnt\] = '\\0'; /* Null terminate end */
2038 /* Copy each argument to consequtive locations in pdata,
2039 and set the corresponding pointer entry */
2040 p = v$count + k * d$count;
2041 for (i=0; i<argcnt; i++) {
2042 int j;
2043 char *pin;
2044 p$count\[k\]\[i\] = pdata;
2045 /* Move to the end and work back */
2046 pin = p + d$count - 1;
2047 while (*pin == ' ' && pin > p) pin--;
2048 /* Copy and then null terminate */
2049 for (j=0; j<(pin-p)+1; j++) { *pdata++ = p\[j\]; }
2050 *pdata++ = 0;
2051 /* Advance to the next entry in the array */
2052 p += ($Array_size) * d$count;
2053 }
2054 /* Set the terminator */
2055 p$count\[k\]\[i\] = '\\0';
2056 }
2057 }\n";
2058
2059 $clean_up .= " if (v$count != (char *)MPI_ARGVS_NULL) {
2060 int i;
2061 for (i=0; i <$Array_size; i++) {
2062 $free( p$count\[i\]\[0\] ); /* Free space allocated to args */
2063 $free( p$count\[i\] ); /* Free space allocated to arg array */
2064 }
2065 /* Free the array of arrays */
2066 $free( p$count );
2067 }\n";
2068 }
2069
2070 # ---------------------------------------------------------------------------
2071 # Convert from an int array to an Aint array for routines taking an Aint as
2072 # input
2073 sub intToAintArr_in_decl {
2074 my $count = $_[0];
2075 print $OUTFD " MPI_Aint *l$count;\n";
2076 }
2077 sub intToAintArr_ftoc {
2078 my $count = $_[0];
2079 print $OUTFD "
2080 #ifdef HAVE_AINT_LARGER_THAN_FINT
2081 if ($Array_size > 0) {
2082 int li;
2083 l$count = (MPI_Aint *)$malloc(sizeof(MPI_Aint) * ($Array_size));
2084 for (li=0; li<$Array_size; li++)
2085 l$count\[li\] = v$count\[li\];
2086 }
2087 else l$count = 0;
2088 #else
2089 l$count = v$count;
2090 #endif\n";
2091 }
2092 sub intToAintArr_in_arg {
2093 my $count = $_[0];
2094 print $OUTFD "l$count";
2095 }
2096 # This routine is invoked even for the in case (to free the result)
2097 sub intToAintArr_in_ctof {
2098 my $lname = $_[0];
2099 my $vname = $_[1];
2100 print $OUTFD "
2101 #ifdef HAVE_AINT_LARGER_THAN_FINT
2102 if ($lname) { $free($lname); }
2103 #endif\n";
2104 }
2105 # ---------------------------------------------------------------------------
2106 # Convert from an int to an Aint for routines taking an Aint as
2107 # input
2108 sub intToAint_in_decl {
2109 my $count = $_[0];
2110 print $OUTFD " MPI_Aint l$count;\n";
2111 }
2112 sub intToAint_ftoc {
2113 my $count = $_[0];
2114 print $OUTFD " l$count = (MPI_Aint)*v$count;\n";
2115 }
2116 sub intToAint_in_arg {
2117 my $count = $_[0];
2118 print $OUTFD "l$count";
2119 }
2120
2121 # ---------------------------------------------------------------------------
2122 # Convert from an FILE to a fortran int
2123 # (output).
2124 # -- temp
2125 sub FileToFint_inout_decl {
2126 my $count = $_[0];
2127 print $OUTFD " MPI_File l$count = MPI_File_f2c(*v$count);\n";
2128 }
2129 sub FileToFint_inout_arg {
2130 my $count = $_[0];
2131 print $OUTFD "&l$count";
2132 }
2133 # -- end temp
2134
2135 sub FileToFint_out_decl {
2136 my $count = $_[0];
2137 print $OUTFD " MPI_File l$count;\n";
2138 }
2139 sub FileToFint_ctof {
2140 my $lvar = $_[0];
2141 my $gvar = $_[1];
2142 print $OUTFD " *$gvar = MPI_File_c2f($lvar);\n";
2143 }
2144 sub FileToFint_out_arg {
2145 my $count = $_[0];
2146 print $OUTFD "&l$count";
2147 }
2148 # ---------------------------------------------------------------------------
2149 # Check for the null datarep functions
2150 sub checkdatarep_in_decl {
2151 my $count = $_[0];
2152 # if ($count == 2) {
2153 # print $OUTFD "
2154 # #ifndef HAVE_MPI_CONVERSION_DEFN
2155 # #define HAVE_MPI_CONVERSION_DEFN
2156 # #ifdef F77_NAME_UPPER
2157 # #define mpi_conversion_fn_null_ MPI_CONVERSION_FN_NULL
2158 # #elif defined(F77_NAME_LOWER_2USCORE)
2159 # #define mpi_conversion_fn_null_ mpi_conversion_fn_null__
2160 # #elif !defined(F77_NAME_LOWER_USCORE)
2161 # #define mpi_conversion_fn_null_ mpi_conversion_fn_null
2162 # /* Else leave name alone */
2163 # #endif
2164 # /* Add the prototype so the routine knows what this is */
2165 # extern FORTRAN_API int FORT_CALL mpi_conversion_fn_null_ ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
2166 # #endif
2167 # ";
2168 # }
2169 }
2170 sub checkdatarep_in_arg {
2171 my $count = $_[0];
2172 print $OUTFD "v$count";
2173 }
2174 sub checkdatarep_ftoc {
2175 my $count = $_[0];
2176
2177 # Check to see if the pointer is the same as the null function
2178 # We do something ugly here: we exploit the fact that we know which is
2179 # the first argument that needs this definition
2180 print $OUTFD "\
2181 if (v$count == (MPI_Datarep_conversion_function *)mpi_conversion_fn_null_){
2182 v$count = 0;
2183 }\n";
2184 }
2185 # ---------------------------------------------------------------------------
2186 # Special post processing for some routines
2187 sub setF90Type_keyval {
2188 my $FD = $_[0];
2189 my $argnum = $_[1];
2190
2191 print $FD "\
2192 if (*ierr == MPI_SUCCESS) {
2193 MPIR_Keyval_set_proxy( *v$argnum, MPIR_Type_copy_attr_f90_proxy, MPIR_Type_delete_attr_f90_proxy );
2194 }\n";
2195 }
2196 sub setF90Comm_keyval {
2197 my $FD = $_[0];
2198 my $argnum = $_[1];
2199
2200 print $FD "\
2201 if (*ierr == MPI_SUCCESS) {
2202 MPIR_Keyval_set_proxy( *v$argnum, MPIR_Comm_copy_attr_f90_proxy, MPIR_Comm_delete_attr_f90_proxy );
2203 }\n";
2204 }
2205 sub setF90Win_keyval {
2206 my $FD = $_[0];
2207 my $argnum = $_[1];
2208
2209 print $FD "\
2210 if (*ierr == MPI_SUCCESS) {
2211 MPIR_Keyval_set_proxy( *v$argnum, MPIR_Win_copy_attr_f90_proxy, MPIR_Win_delete_attr_f90_proxy );
2212 }\n";
2213 }
2214 sub setF77greq {
2215 my $FD = $_[0];
2216 my $argnum = $_[1];
2217
2218 print $FD "\
2219 if (*ierr == MPI_SUCCESS) {
2220 MPIR_Grequest_set_lang_f77( *v$argnum );
2221 }\n";
2222 }
2223
2224
2225 # ---------------------------------------------------------------------------
2226 # This routine handles the special arguments in the *call*
2227 sub print_special_call_arg {
2228 my $routine_name = $_[0];
2229 my $count = $_[1];
2230
2231 $rule = $special_args{"${routine_name}-$count"};
2232 ($direction,$method,$Array_size) = split(/:/,$rule);
2233
2234 $processing_routine = "${method}_${direction}_arg";
2235 &$processing_routine( $count );
2236 }
2237
2238 # This routine prints any declarations that are needed
2239 sub print_special_decls {
2240 my $routine_name = $_[0];
2241
2242 if ($returnErrval) {
2243 print $OUTFD " int $errparmrval;\n";
2244 }
2245 if (defined($special_args{$routine_name})) {
2246 # First do the declarations
2247 foreach $count (split(/:/,$special_args{$routine_name})) {
2248 $rule = $special_args{"${routine_name}-$count"};
2249 ($direction,$method,$Array_size) = split(/:/,$rule);
2250 # Sanity check: method and direction must be nonnull
2251 if ($method eq "" || $direction eq "") {
2252 print STDERR "Error in special args for argument number $count of $routine_name\n";
2253 last;
2254 }
2255 $processing_routine = "${method}_${direction}_decl";
2256 &$processing_routine( $count );
2257 }
2258 }
2259 if (defined($special_args{$routine_name})) {
2260 # Then do the precall steps
2261 foreach $count (split(/:/,$special_args{$routine_name})) {
2262 $rule = $special_args{"${routine_name}-$count"};
2263 ($direction,$method,$Array_size) = split(/:/,$rule);
2264 if ($direction eq "in") {
2265 $processing_routine = "${method}_ftoc";
2266 &$processing_routine( $count );
2267 }
2268 else {
2269 $processing_routine = "${method}_out_ftoc";
2270 if (defined(&$processing_routine)) {
2271 &$processing_routine( $count );
2272 }
2273 }
2274 }
2275 }
2276 }
2277
2278 #
2279 # --------------------------------------------------------------------------
2280 # Create mpif.h.in from mpi.h
2281 #
2282 # Need to put this into a routine similar to the ReadInterface routine
2283 # in the c++ version. This will allow us to read both mpi.h.in
2284 # and mpio.h.in (or other files)
2285
2286 &ReadInterfaceForDefinitions( $prototype_file );
2287 if ( -s "../../mpi/romio/include/mpio.h.in" && $build_io) {
2288 %skipBlocks = ( 'HAVE_MPI_DARRAY_SUBARRAY' => 1,
2289 'HAVE_MPI_INFO' => 1,
2290 'MPICH2' => 1 );
2291 &ReadInterfaceForDefinitions( "../../mpi/romio/include/mpio.h.in" );
2292 %skipBlocks = ();
2293 }
2294 #
2295 if ($write_mpif) {
2296
2297 # The ONLY valid comment character for Fortran 77 is a C in column 1
2298 # For those Fortran compilers that support it (which is most at this point)
2299 # the top-level configure will replace the "C" in column 1 with "!"
2300 # (also in column 1)
2301 $cchar = "C";
2302 open ( MPIFFD, ">mpif.h.in.new" ) || die "Could not open mpif.h.in.new\n";
2303
2304
2305 # Now, write out the file
2306 # This first line makes sure that other tools know that this is a
2307 # Fortran file
2308 print MPIFFD "$cchar /* -*- Mode: Fortran; -*- */\n";
2309 print MPIFFD "$cchar \n";
2310 print MPIFFD "$cchar (C) 2003 by Argonne National Laboratory and Northwestern University.\n";
2311 print MPIFFD "$cchar See COPYRIGHT in top-level directory.\n";
2312 print MPIFFD "$cchar \n";
2313 print MPIFFD "$cchar DO NOT EDIT\n";
2314 print MPIFFD "$cchar This file created by command:\n";
2315 print MPIFFD "$cchar ./buildiface $arg_string\n";
2316 print MPIFFD "$cchar \n";
2317 #
2318 # Status elements
2319 # FIXME: The offsets for the status elements are hardwired. If they
2320 # change in mpi.h.in, they need to change here as well.
2321 print MPIFFD " INTEGER MPI_SOURCE, MPI_TAG, MPI_ERROR\n";
2322 print MPIFFD " PARAMETER (MPI_SOURCE=3,MPI_TAG=4,MPI_ERROR=5)\n";
2323 print MPIFFD " INTEGER MPI_STATUS_SIZE\n";
2324 print MPIFFD " PARAMETER (MPI_STATUS_SIZE=\@MPI_STATUS_SIZE\@)\n";
2325 # Temporary until configure handles these. Define as arrays to keep
2326 # Fortran compilers from complaining excessively.
2327 print MPIFFD " INTEGER MPI_STATUS_IGNORE(MPI_STATUS_SIZE)\n";
2328 print MPIFFD " INTEGER MPI_STATUSES_IGNORE(MPI_STATUS_SIZE,1)\n";
2329 #
2330 # Other special constants. ERRCODES_IGNORE and ARGVS_NULL
2331 # are both like STATUS(ES)_IGNORE
2332 print MPIFFD " INTEGER MPI_ERRCODES_IGNORE(1)\n";
2333 print MPIFFD " CHARACTER*1 MPI_ARGVS_NULL(1,1)\n";
2334 # Unfortunately, we cannot parameter initialize this. Further,
2335 # there is no default initialization. We could use a block data item...
2336 # ARGV_NULL can actually be a single blank string, but it needs
2337 # to be typed as a character array
2338 print MPIFFD " CHARACTER*1 MPI_ARGV_NULL(1)\n";
2339
2340 #
2341 # Error Classes
2342 print MPIFFD " INTEGER MPI_SUCCESS\n";
2343 print MPIFFD " PARAMETER (MPI_SUCCESS=0)\n";
2344 foreach $key (keys(%mpidef)) {
2345 if ($key =~ /MPI_ERR_/) {
2346 &print_mpif_int( $key );
2347 }
2348 }
2349 # Predefined error handlers
2350 foreach $key (ERRORS_ARE_FATAL, ERRORS_RETURN) {
2351 &print_mpif_int( "MPI_$key" );
2352 }
2353 # Compare operations
2354 foreach $key (IDENT,CONGRUENT,SIMILAR,UNEQUAL) {
2355 &print_mpif_int( "MPI_$key" );
2356 }
2357 # Collective operations
2358 foreach $key (MAX, MIN, SUM, PROD, LAND, BAND, LOR, BOR, LXOR, BXOR, MINLOC, MAXLOC, REPLACE ) {
2359 &print_mpif_int( "MPI_$key" );
2360 }
2361 # Objects
2362 foreach $key ('COMM_WORLD', 'COMM_SELF', 'GROUP_EMPTY', 'COMM_NULL', 'WIN_NULL', 'FILE_NULL', 'GROUP_NULL', 'OP_NULL', 'DATATYPE_NULL', 'REQUEST_NULL', 'ERRHANDLER_NULL', 'INFO_NULL', ) {
2363 &print_mpif_int( "MPI_$key" );
2364 }
2365 # Attributes
2366 foreach $key (TAG_UB, HOST, IO, WTIME_IS_GLOBAL, UNIVERSE_SIZE, LASTUSEDCODE, APPNUM, WIN_BASE, WIN_SIZE, WIN_DISP_UNIT ) {
2367 # Special cast: The Fortran versions of these attributes have
2368 # value 1 greater than the C versions
2369 $attrval = $mpidef{"MPI_$key"};
2370 print "$key is $attrval\n" if $debug;
2371 if ($attrval =~ /^0x/) { $attrval = hex $attrval; }
2372 $attrval++;
2373 $attrval = "0x" . sprintf "%x", $attrval;
2374 print "$key is now $attrval\n" if $debug;
2375 $mpidef{"MPI_$key"} = $attrval;
2376 &print_mpif_int( "MPI_$key" );
2377 }
2378 # String sizes
2379 # See MPI-2 2.6.2 and 4.12.9; the constants for string lenghts are
2380 # defined as one less than the C/C++ version
2381
2382 # Missing - max processor name!
2383 # Handle max processor name here.
2384 $mpidef{"MPI_MAX_PROCESSOR_NAME"} = "\@MPI_MAX_PROCESSOR_NAME\@";
2385 # Other maximum values
2386 foreach $key (MAX_ERROR_STRING, MAX_PORT_NAME,
2387 MAX_OBJECT_NAME, MAX_INFO_KEY, MAX_INFO_VAL,
2388 MAX_PROCESSOR_NAME, MAX_DATAREP_STRING ) {
2389 &print_mpif_int( "MPI_$key", -1 );
2390 }
2391
2392 # predefined constants
2393 print MPIFFD " INTEGER MPI_UNDEFINED\n";
2394 print MPIFFD " PARAMETER (MPI_UNDEFINED=$mpidef{'MPI_UNDEFINED'})\n";
2395 &print_mpif_int( "MPI_KEYVAL_INVALID" );
2396 foreach $key ('BSEND_OVERHEAD', 'PROC_NULL', 'ANY_SOURCE', 'ANY_TAG', 'ROOT') {
2397 &print_mpif_int( "MPI_$key" );
2398 }
2399 #
2400 # Topology types
2401 foreach $key (GRAPH, CART) {
2402 &print_mpif_int( "MPI_$key" );
2403 }
2404 #
2405 # version
2406 &print_mpif_int( "MPI_VERSION" );
2407 &print_mpif_int( "MPI_SUBVERSION" );
2408
2409 # Special RMA values
2410 &print_mpif_int( "MPI_LOCK_EXCLUSIVE" );
2411 &print_mpif_int( "MPI_LOCK_SHARED" );
2412 #
2413 # Datatypes
2414 # These are determined and set at configure time
2415 foreach $key (COMPLEX, DOUBLE_COMPLEX, LOGICAL, REAL, DOUBLE_PRECISION, INTEGER, '2INTEGER', '2COMPLEX', '2DOUBLE_PRECISION', '2REAL', '2DOUBLE_COMPLEX', CHARACTER) {
2416 print MPIFFD " INTEGER MPI_$key\n";
2417 print MPIFFD " PARAMETER (MPI_$key=\@MPI_$key\@)\n";
2418 }
2419 # Value of MPI_BYTE from top level configure!
2420 $mpidef{"MPI_BYTE"} = hex "0x4c00010d";
2421 foreach $key (BYTE, UB, LB, PACKED) {
2422 print MPIFFD " INTEGER MPI_$key\n";
2423 print MPIFFD " PARAMETER (MPI_$key=\@MPI_F77_$key\@)\n";
2424 }
2425 #&print_mpif_int( "MPI_BYTE" );
2426 #&print_mpif_int( "MPI_UB" );
2427 #&print_mpif_int( "MPI_LB" );
2428 #&print_mpif_int( "MPI_PACKED" );
2429
2430 # Optional types
2431 # Warning: Should these use \@MPI_$key\@, since the
2432 # C-version must also compute these?
2433 foreach $key (INTEGER1, INTEGER2, INTEGER4, INTEGER8, INTEGER16,
2434 REAL4, REAL8, REAL16, COMPLEX8, COMPLEX16, COMPLEX32) {
2435 print MPIFFD " INTEGER MPI_$key\n";
2436 print MPIFFD " PARAMETER (MPI_$key=\@F77_$key\@)\n";
2437 }
2438 #
2439 # Fortran 90 types
2440 print MPIFFD " INTEGER MPI_ADDRESS_KIND, MPI_OFFSET_KIND\n";
2441 print MPIFFD " PARAMETER (MPI_ADDRESS_KIND=\@ADDRESS_KIND\@)\n";
2442 print MPIFFD " PARAMETER (MPI_OFFSET_KIND=\@OFFSET_KIND\@)\n";
2443 #
2444 # C Types. Note that we need to convert the C hex constant
2445 # into a decimal constant for Fortran (there is no standard
2446 # for for hex constants in Fortran, and different compilers make
2447 # use of different extensions)
2448 foreach $key (CHAR, SIGNED_CHAR, UNSIGNED_CHAR, WCHAR, SHORT,
2449 UNSIGNED_SHORT, INT, UNSIGNED, LONG, UNSIGNED_LONG,
2450 FLOAT, DOUBLE, LONG_DOUBLE, LONG_LONG_INT,
2451 UNSIGNED_LONG_LONG, LONG_LONG, FLOAT_INT, DOUBLE_INT,
2452 LONG_INT, SHORT_INT, "2INT", LONG_DOUBLE_INT) {
2453 print MPIFFD " INTEGER MPI_$key\n";
2454 print MPIFFD " PARAMETER (MPI_$key=\@MPI_F77_$key\@)\n";
2455 }
2456 # C types added in MPI 2.2
2457 foreach $key (INT8_T, INT16_T, INT32_T, INT64_T, UINT8_T, UINT16_T,
2458 UINT32_T, UINT64_T, C_BOOL, C_FLOAT_COMPLEX, C_COMPLEX,
2459 C_DOUBLE_COMPLEX, C_LONG_DOUBLE_COMPLEX, AINT, OFFSET) {
2460 print MPIFFD " INTEGER MPI_$key\n";
2461 print MPIFFD " PARAMETER (MPI_$key=\@MPI_F77_$key\@)\n";
2462 }
2463 # Datatype combiners
2464 foreach $key (NAMED, DUP, CONTIGUOUS, VECTOR, HVECTOR_INTEGER, HVECTOR,
2465 INDEXED, HINDEXED_INTEGER, HINDEXED, INDEXED_BLOCK,
2466 STRUCT_INTEGER, STRUCT, SUBARRAY, DARRAY, F90_REAL,
2467 F90_COMPLEX, F90_INTEGER, RESIZED) {
2468 &print_mpif_int( "MPI_COMBINER_$key" );
2469 }
2470 # Typeclasses
2471 foreach $key (REAL, INTEGER, COMPLEX) {
2472 &print_mpif_int( "MPI_TYPECLASS_$key" );
2473 }
2474
2475 # RMA Asserts
2476 foreach $mode (NOCHECK, NOSTORE, NOPUT, NOPRECEDE, NOSUCCEED) {
2477 &print_mpif_int( "MPI_MODE_$mode" );
2478 }
2479
2480 # Thread values
2481 foreach my $threadlevel (SINGLE, FUNNELED, SERIALIZED, MULTIPLE) {
2482 &print_mpif_int( "MPI_THREAD_$threadlevel" );
2483 }
2484
2485 # MPI-2 types: Files
2486 if ($build_io) {
2487 # Modes
2488 foreach $mode (RDONLY, RDWR, WRONLY, DELETE_ON_CLOSE, UNIQUE_OPEN,
2489 CREATE, EXCL, APPEND, SEQUENTIAL) {
2490 &print_mpif_int( "MPI_MODE_$mode" );
2491 }
2492 # Seek
2493 foreach $dir (SET, CUR, END) {
2494 &print_mpif_int( "MPI_SEEK_$dir" );
2495 }
2496 # Order
2497 foreach $order (C, FORTRAN) {
2498 &print_mpif_int("MPI_ORDER_$order");
2499 }
2500 # direction
2501 foreach $distrib (BLOCK, CYCLIC, NONE, DFLT_DARG) {
2502 &print_mpif_int("MPI_DISTRIBUTE_$distrib");
2503 }
2504 &print_mpif_int( "MPI_DISPLACEMENT_CURRENT", 0,
2505 "\@FORTRAN_MPI_OFFSET\@" );
2506 }
2507 #
2508 # Finally, the special symbols
2509 print MPIFFD " INTEGER MPI_BOTTOM, MPI_IN_PLACE\n";
2510
2511 # And the external names. This are necessary to
2512 # ensure that these are passed as routines, not implicitly-defined
2513 # variables
2514 print MPIFFD " EXTERNAL MPI_DUP_FN, MPI_NULL_DELETE_FN, MPI_NULL_COPY_FN\n";
2515 # Note that pmpi_wtime can cause problems with some Fortran compilers
2516 # if the corresponding routines aren't available (even if not used)
2517 print MPIFFD " EXTERNAL MPI_WTIME, MPI_WTICK\n";
2518 print MPIFFD " EXTERNAL PMPI_WTIME, PMPI_WTICK\n";
2519 # Add the external names for the MPI-2 attribute functions
2520 print MPIFFD " EXTERNAL MPI_COMM_DUP_FN, MPI_COMM_NULL_DELETE_FN\n";
2521 print MPIFFD " EXTERNAL MPI_COMM_NULL_COPY_FN\n";
2522 print MPIFFD " EXTERNAL MPI_WIN_DUP_FN, MPI_WIN_NULL_DELETE_FN\n";
2523 print MPIFFD " EXTERNAL MPI_WIN_NULL_COPY_FN\n";
2524 print MPIFFD " EXTERNAL MPI_TYPE_DUP_FN, MPI_TYPE_NULL_DELETE_FN\n";
2525 print MPIFFD " EXTERNAL MPI_TYPE_NULL_COPY_FN\n";
2526 print MPIFFD " EXTERNAL MPI_CONVERSION_FN_NULL\n";
2527 # the time/tick functions
2528 # Special option. Some compilers (particularly IBM's xl compilers)
2529 # allow the user to change the definition of the datatypes, such as
2530 # making real 8 bytes and double precision 16. To allow mpif.h
2531 # to be used with such compilers, those compilers allow the
2532 # use of the non-standard real*8 to force exactly 8 bytes.
2533 # WARNING: REAL*8 is not standard and must not be used here.
2534 # Instead, the top level configure (in mpich2/configure) will
2535 # replace DOUBLE PRECISION with REAL*8 where the Fortran compiler
2536 # supports it.
2537 print MPIFFD " DOUBLE PRECISION MPI_WTIME, MPI_WTICK\n";
2538 print MPIFFD " DOUBLE PRECISION PMPI_WTIME, PMPI_WTICK\n";
2539 # We avoid adding the external declarations because some Fortran
2540 # compilers then insist on linking with the routines, even if
2541 # they are not used. Combined with systems that do not have weak
2542 # symbols, and you can get some strange link failures.
2543
2544 # When building the Fortran interface for Microsoft Windows, there
2545 # are some additional compiler directives needed
2546 # This provides a hook for any DLL import directives. We need to
2547 # make this a configure-time variable because some compilers (in
2548 # particular, a version of the Intel Fortran compiler for Linux)
2549 # will read directives for other compilers and then flag as fatal
2550 # errors directives that it does not support but does recognize.
2551 print MPIFFD "\@DLLIMPORT\@\n";
2552
2553 # Add the common blocks for the special constants
2554 # (Use two to avoid problems with continuations)
2555 print MPIFFD "\
2556 COMMON /MPIPRIV1/ MPI_BOTTOM, MPI_IN_PLACE, MPI_STATUS_IGNORE\n";
2557 print MPIFFD "\
2558 COMMON /MPIPRIV2/ MPI_STATUSES_IGNORE, MPI_ERRCODES_IGNORE\n";
2559 print MPIFFD " SAVE /MPIPRIV1/,/MPIPRIV2/\n";
2560 # Add the common block for the character parameter ARGVS_NULL (Fortran
2561 # requires character data in a different common block than
2562 # non-character data)
2563 print MPIFFD "\
2564 COMMON /MPIPRIVC/ MPI_ARGVS_NULL, MPI_ARGV_NULL
2565 SAVE /MPIPRIVC/\n";
2566
2567 close( MPIFFD );
2568 &ReplaceIfDifferent( "mpif.h.in", "mpif.h.in.new" );
2569 } # if write_mpif
2570
2571 #
2572 # Look through $args for parameter names (foo\s+name)
2573 # and remove them
2574 sub clean_args {
2575 my $newargs = "";
2576 my $comma = "";
2577 for $parm (split(',',$args)) {
2578 # Remove any leading or trailing spaces
2579 $parm =~ s/^\s*//;
2580 $parm =~ s/\s*$//;
2581 # Handle parameters with parameter names
2582 # First if handles "int foo", second handles "int *foo"
2583 if ( ($parm =~ /^([A-Za-z0-9_]+)\s+[A-Za-z0-9_]+$/) ) {
2584 $parm = $1;
2585 }
2586 elsif ( ($parm =~ /([A-Za-z0-9_]+\s*\*)\s*[A-Za-z0-9_]+$/) ) {
2587 $parm = $1;
2588 }
2589 $newargs .= "$comma$parm";
2590 $comma = ",";
2591 }
2592 print STDERR "$newargs\n" if $debug;
2593 $args = $newargs;
2594 }
2595
2596 # print_type_decl( $FD, $lcname )
2597
2598 sub print_routine_type_decl {
2599 my $OUTFD = $_[0];
2600 my $lcname = $_[1];
2601 # The name "FORTRAN_API" may be use to tell the compiler that
2602 #
2603 if ($do_subdecls) {
2604 print $OUTFD "FORTRAN_API $returnType FORT_CALL ";
2605 }
2606 else {
2607 print $OUTFD "$returnType ";
2608 }
2609 print $OUTFD "${out_prefix}${lcname}_ ";
2610 }
2611
2612 #
2613 # Build the special routines
2614 sub build_specials {
2615 my $filename = "";
2616 # The init routine contains some configure-time values.
2617 # We may not want to do this if we are supporting multiple
2618 # Fortran compilers with different values for Fortran .TRUE. and
2619 # .FALSE., but to get started, this is easiest.
2620 $OUTFD = "INITFFD";
2621 $filename = "initf.c";
2622 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2623 $files[$#files+1] = $filename;
2624 &print_header( "MPI_Init", "init", "" );
2625
2626 &print_routine_type_decl( $OUTFD, "init" );
2627 $args = "";
2628 &print_args( $OUTFD, $args, 0, "init" );
2629 # If an attribute can be added before the code, then do that here.
2630 # Gcc only allows attributes on the prototypes, not the function
2631 # definitions
2632 print $OUTFD "{\n";
2633 print $OUTFD "#ifndef F77_RUNTIME_VALUES
2634 /* any compile/link time values go here */
2635 #else
2636 # error \"Fortran values must be determined at configure time\"
2637 #endif
2638 ";
2639 # See the discussion on MPIR_F_NeedInit at the head of this file
2640 print $OUTFD " mpirinitf_(); MPIR_F_NeedInit = 0;\n";
2641 print $OUTFD " *ierr = MPI_Init( 0, 0 );\n";
2642 # Still to do:
2643 # Initialize the Fortran versions of the predefined keyvals.
2644 # Find the value of MPI_BOTTOM.
2645 # Call a Fortran routine that calls a C routine that is passed
2646 # MPI_BOTTOM from the common block.
2647 #
2648 print $OUTFD "}\n";
2649 close ($OUTFD);
2650 &ReplaceIfDifferent( $filename, $filename . ".new" );
2651 &AddPrototype( "init", $args );
2652
2653 $OUTFD = "INITFFD";
2654 $filename = "initthreadf.c";
2655 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2656 $files[$#files+1] = $filename;
2657 $args = "int, int *";
2658 &print_header( "MPI_Init_thread", "init_thread", $args );
2659
2660 &print_routine_type_decl( $OUTFD, "init_thread" );
2661 &print_args( $OUTFD, $args, 0, "init_thread" );
2662 print $OUTFD "{\n";
2663 # See the discussion on MPIR_F_NeedInit at the head of this file
2664 print $OUTFD " mpirinitf_(); MPIR_F_NeedInit = 0;\n";
2665 print $OUTFD " *ierr = MPI_Init_thread( 0, 0, *v1, v2 );\n";
2666 print $OUTFD "}\n";
2667 close ($OUTFD);
2668 &ReplaceIfDifferent( $filename, $filename . ".new" );
2669 &AddPrototype( "init_thread", $args );
2670
2671 # Functions used by the C init process, but that must be called
2672 # from C
2673 $OUTFD = "FORTTOC";
2674 $filename = "setbot.c";
2675 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2676 #setbot.c is not one of the mpi_sources files
2677 #$files[$#files+1] = $filename;
2678 &print_copyright;
2679 &print_gcc_pragma;
2680
2681 print $OUTFD "
2682 #ifdef F77_NAME_UPPER
2683 #define mpirinitc_ MPIRINITC
2684 #define mpirinitc2_ MPIRINITC2
2685 #elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE)
2686 /* leave name alone */
2687 #else
2688 #define mpirinitc_ mpirinitc
2689 #define mpirinitc2_ mpirinitc2
2690 #endif
2691 /* These functions are called from Fortran so only need prototypes in
2692 this file. Note that the last argument is a character array, so
2693 we need to include the elements of the Fortran character \"dope vector\".
2694 */
2695 FORTRAN_API void FORT_CALL mpirinitc_( void *, void *, void *, void *,
2696 void *, void * FORT_MIXED_LEN_DECL
2697 FORT_END_LEN_DECL );
2698 FORTRAN_API void FORT_CALL mpirinitc2_( char * FORT_MIXED_LEN_DECL
2699 FORT_END_LEN_DECL );
2700 ";
2701 # These are here rather than in initf.c to solve some link order
2702 # problems for Windows when separate libraries are used for the C and
2703 # Fortran routines.
2704 # Note that the global variables have values. This is to work around
2705 # a bug in some C environments (e.g., Mac OS/X) that don't load
2706 # external symbols that don't have a value assigned at compile time
2707 # (so called common symbols)
2708 print $OUTFD "
2709 #ifndef F77_USE_BOOLEAN_LITERALS
2710 #if defined(F77_RUNTIME_VALUES) || !defined(F77_TRUE_VALUE_SET)
2711 MPI_Fint MPIR_F_TRUE = 1, MPIR_F_FALSE = 0;
2712 #else
2713 const MPI_Fint MPIR_F_TRUE=F77_TRUE_VALUE;
2714 const MPI_Fint MPIR_F_FALSE=F77_FALSE_VALUE;
2715 #endif
2716 #endif
2717 ";
2718 # MPI-2, section 4.12.5, on the declaration of MPI_F_STATUS_IGNORE
2719 # MPI_F_STATUSES_IGNORE as global variables in mpi.h (!)
2720 print $OUTFD "
2721 #ifndef USE_POINTER_FOR_BOTTOM
2722 int MPIR_F_NeedInit = 1;
2723 void *MPIR_F_MPI_BOTTOM = 0;
2724 void *MPIR_F_MPI_IN_PLACE = 0;
2725 /* MPI_F_STATUS_IGNORE etc must be declared within mpi.h (MPI-2 standard
2726 requires this) */
2727 /*
2728 void *MPI_F_STATUS_IGNORE = 0;
2729 void *MPI_F_STATUSES_IGNORE = 0;
2730 */
2731 int *MPI_F_ERRCODES_IGNORE = 0;
2732 void *MPI_F_ARGVS_NULL = 0;
2733 #endif
2734 \n";
2735
2736
2737 print $OUTFD "
2738 FORTRAN_API void FORT_CALL mpirinitc_( void *a, void *b, void *c, void *d,
2739 void *e, void *f FORT_MIXED_LEN(d1)
2740 FORT_END_LEN(d1) )
2741 {
2742 MPIR_F_MPI_BOTTOM = a;
2743 MPIR_F_MPI_IN_PLACE = b;
2744 MPI_F_STATUS_IGNORE = (MPI_Fint *)c;
2745 MPI_F_STATUSES_IGNORE = (MPI_Fint *)d;
2746 MPI_F_ERRCODES_IGNORE = (int *)e;
2747 MPI_F_ARGVS_NULL = f;
2748 }
2749 /* Initialize the Fortran ARGV_NULL to a blank. Using this routine
2750 avoids potential problems with string manipulation routines that
2751 exist in the Fortran runtime but not in the C runtime libraries */
2752 FORTRAN_API void FORT_CALL mpirinitc2_( char *a FORT_MIXED_LEN(d1)
2753 FORT_END_LEN(d1) )
2754 {
2755 *a = ' ';
2756 }
2757 ";
2758 close ($OUTFD);
2759 &ReplaceIfDifferent( $filename, $filename . ".new" );
2760
2761 $OUTFD = "PCONTROLFFD";
2762 $filename = "pcontrolf.c";
2763 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2764 $files[$#files+1] = $filename;
2765 $args = "int";
2766 &print_header( "MPI_Pcontrol", "pcontrol", $args );
2767 &print_routine_type_decl( $OUTFD, "pcontrol" );
2768 &print_args( $OUTFD, $args, 0, "pcontrol" );
2769 #&print_attr;
2770 print $OUTFD "{\n";
2771 print $OUTFD " *ierr = MPI_Pcontrol( (int)*v1 );\n";
2772 print $OUTFD "}\n";
2773 close ($OUTFD);
2774 &ReplaceIfDifferent( $filename, $filename . ".new" );
2775 &AddPrototype( "pcontrol", $args );
2776
2777 $OUTFD = "ADDRESSFFD";
2778 $filename = "addressf.c";
2779 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2780 $files[$#files+1] = $filename;
2781 $args = "void *, int *";
2782 &print_header( "MPI_Address", "address", $args );
2783 # Add the definitions needed for error reporting
2784 # (We could use mpiimpl.h, but mpierrs.h should be sufficient)
2785 # mpierror.h references FILE *, so needs stdio.h
2786 print $OUTFD "#include \"mpierrs.h\"\n";
2787 print $OUTFD "#include <stdio.h>\n";
2788 print $OUTFD "#include \"mpierror.h\"\n";
2789 &print_routine_type_decl( $OUTFD, "address" );
2790 &print_args( $OUTFD, $args, 0, "address" );
2791 #&print_attr;
2792 print $OUTFD "{
2793 MPI_Aint a, b;
2794 *ierr = MPI_Address( v1, &a );\n";
2795 &specialInitStatement( $OUTFD );
2796 print $OUTFD "\
2797 #ifdef USE_POINTER_FOR_BOTTOM
2798 b = a;
2799 #else
2800 b = a - (MPIR_Pint) MPIR_F_MPI_BOTTOM;
2801 #endif
2802 *v2 = (MPI_Fint)( b );
2803 #ifdef HAVE_AINT_LARGER_THAN_FINT
2804 /* Check for truncation */
2805 if ((MPI_Aint)*v2 - b != 0) {
2806 *ierr = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
2807 \"MPI_Address\", __LINE__, MPI_ERR_ARG, \"**inttoosmall\", 0 );
2808 (void)MPIR_Err_return_comm( 0, \"MPI_Address\", *ierr );
2809 }
2810 #endif
2811 }\n";
2812 close ($OUTFD);
2813 &ReplaceIfDifferent( $filename, $filename . ".new" );
2814 &AddPrototype( "address", $args );
2815
2816 $OUTFD = "GETADDRESSFFD";
2817 $filename = "getaddressf.c";
2818 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2819 $files[$#files+1] = $filename;
2820 $args = "void *, MPI_FAintp";
2821 &print_header( "MPI_Get_address", "get_address", $args );
2822 # Add the definitions needed for error reporting
2823 # (We could use mpiimpl.h, but mpierrs.h should be sufficient)
2824 # mpierror.h references FILE *, so needs stdio.h
2825 print $OUTFD "#include \"mpierrs.h\"\n";
2826 print $OUTFD "#include <stdio.h>\n";
2827 print $OUTFD "#include \"mpierror.h\"\n";
2828 &print_routine_type_decl( $OUTFD, "get_address" );
2829 &print_args( $OUTFD, $args, 0, "get_address" );
2830 #&print_attr;
2831 print $OUTFD "{
2832 MPI_Aint a;
2833 *ierr = MPI_Get_address( v1, &a );\n";
2834 &specialInitStatement( $OUTFD );
2835 print $OUTFD "\
2836 #ifndef USE_POINTER_FOR_BOTTOM
2837 a = a - (MPIR_Pint) MPIR_F_MPI_BOTTOM;
2838 #endif
2839 *v2 = a;
2840 }\n";
2841 close ($OUTFD);
2842 &ReplaceIfDifferent( $filename, $filename . ".new" );
2843 &AddPrototype( "get_address", $args );
2844
2845 $OUTFD = "WTIMEFD";
2846 $filename = "wtimef.c";
2847 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2848 $files[$#files+1] = $filename;
2849 $returnType = "double";
2850 &set_weak_decl( "MPI_Wtime", "void", "double" );
2851 &set_weak_decl( "PMPI_Wtime", "void", "double" );
2852 &print_header( "MPI_Wtime", "wtime", "" );
2853 # mpichtimer.h is needed for the timer definitions
2854 print $OUTFD "#include \"mpichconf.h\"\n";
2855 print $OUTFD "#include \"mpichtimer.h\"\n";
2856 &print_routine_type_decl( $OUTFD, "wtime" );
2857 print $OUTFD "( void ) ";
2858 #&print_attr;
2859 print $OUTFD "{\n";
2860 print $OUTFD " double d; MPID_Time_t t;\n
2861 MPID_Wtime( &t );
2862 MPID_Wtime_todouble( &t, &d );
2863 return d;\n";
2864 print $OUTFD "}\n";
2865 close ($OUTFD);
2866 &ReplaceIfDifferent( $filename, $filename . ".new" );
2867
2868 if ($build_prototypes) {
2869 print PROTOFD "extern ";
2870 &print_routine_type_decl( PROTOFD, "wtime" );
2871 print PROTOFD "( void )";
2872 &print_attr( PROTOFD, "${out_prefix}wtime_" );
2873 print PROTOFD ";\n";
2874 }
2875 $returnType = "void";
2876
2877 $OUTFD = "WTICKFD";
2878 $filename = "wtickf.c";
2879 open( $OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2880 $files[$#files+1] = $filename;
2881 $returnType = "double";
2882 &set_weak_decl( "MPI_Wtick", "void", "double" );
2883 &set_weak_decl( "PMPI_Wtick", "void", "double" );
2884 &print_header( "MPI_Wtick", "wtick", "" );
2885 # mpichtimer.h is needed for the timer definitions
2886 print $OUTFD "#include \"mpichconf.h\"\n";
2887 print $OUTFD "#include \"mpichtimer.h\"\n";
2888 &print_routine_type_decl( $OUTFD, "wtick" );
2889 print $OUTFD "( void ) ";
2890 #&print_attr;
2891 print $OUTFD "{\n";
2892 print $OUTFD " double d;
2893 d = MPID_Wtick( );
2894 return d;\n";
2895 print $OUTFD "}\n";
2896 close ($OUTFD);
2897 &ReplaceIfDifferent( $filename, $filename . ".new" );
2898
2899 if ($build_prototypes) {
2900 print PROTOFD "extern ";
2901 &print_routine_type_decl( PROTOFD, "wtick" );
2902 print PROTOFD "( void )";
2903 &print_attr( PROTOFD, "${out_prefix}wtick_" );
2904 print PROTOFD ";\n";
2905 }
2906 $returnType = "void";
2907
2908 $OUTFD = "KEYVALCREATEF";
2909 $filename = "keyval_createf.c";
2910 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
2911 $files[$#files+1] = $filename;
2912 $args = "MPI_Copy_function , MPI_Delete_function , int *, void *";
2913 &print_header( "MPI_Keyval_create", "keyval_create", $args );
2914 print $OUTFD "
2915 #ifndef MPICH_MPI_FROM_PMPI
2916 #undef MPI_Comm_create_keyval
2917 #define MPI_Comm_create_keyval PMPI_Comm_create_keyval
2918 #endif
2919 ";
2920
2921 print $OUTFD "
2922 /* The F77 attr copy function prototype and calling convention */
2923 typedef void (FORT_CALL F77_CopyFunction) (MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *,MPI_Fint *, MPI_Fint *, MPI_Fint *);
2924
2925 /* Helper proxy function to thunk the attr copy function call into F77 calling convention */
2926 static
2927 int
2928 MPIR_Comm_copy_attr_f77_proxy(
2929 MPI_Comm_copy_attr_function* user_function,
2930 MPI_Comm comm,
2931 int keyval,
2932 void* extra_state,
2933 MPIR_AttrType value_type,
2934 void* value,
2935 void** new_value,
2936 int* flag
2937 )
2938 {
2939 MPI_Fint ierr = 0;
2940 MPI_Fint fhandle = (MPI_Fint)comm;
2941 MPI_Fint fkeyval = (MPI_Fint)keyval;
2942 MPI_Fint fvalue = (MPI_Fint) MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
2943 MPI_Fint* fextra = (MPI_Fint*)extra_state;
2944 MPI_Fint fnew = 0;
2945 MPI_Fint fflag = 0;
2946
2947 ((F77_CopyFunction*)user_function)( &fhandle, &fkeyval, fextra, &fvalue, &fnew, &fflag, &ierr );
2948
2949 *flag = fflag;
2950 *new_value = MPI_AINT_CAST_TO_VOID_PTR ((MPI_Aint) fnew);
2951 return ierr;
2952 }
2953
2954
2955 /* The F77 attr delete function prototype and calling convention */
2956 typedef void (FORT_CALL F77_DeleteFunction) (MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *, MPI_Fint *);
2957
2958 /* Helper proxy function to thunk the attr delete function call into F77 calling convention */
2959 static
2960 int
2961 MPIR_Comm_delete_attr_f77_proxy(
2962 MPI_Comm_delete_attr_function* user_function,
2963 MPI_Comm comm,
2964 int keyval,
2965 MPIR_AttrType value_type,
2966 void* value,
2967 void* extra_state
2968 )
2969 {
2970 MPI_Fint ierr = 0;
2971 MPI_Fint fhandle = (MPI_Fint)comm;
2972 MPI_Fint fkeyval = (MPI_Fint)keyval;
2973 MPI_Fint fvalue = (MPI_Fint) MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
2974 MPI_Fint* fextra = (MPI_Fint*)extra_state;
2975
2976 ((F77_DeleteFunction*)user_function)( &fhandle, &fkeyval, &fvalue, fextra, &ierr );
2977 return ierr;
2978 }
2979
2980
2981 ";
2982 &print_routine_type_decl( $OUTFD, "keyval_create" );
2983 &print_args( $OUTFD, $args, 0, "keyval_create" );
2984 #&print_attr;
2985 print $OUTFD "{
2986 *ierr = MPI_Comm_create_keyval( v1, v2, v3, v4 );
2987 if (!*ierr) {
2988 MPIR_Keyval_set_proxy(*v3, MPIR_Comm_copy_attr_f77_proxy, MPIR_Comm_delete_attr_f77_proxy);
2989 }
2990 }\n";
2991 close ($OUTFD);
2992 &ReplaceIfDifferent( $filename, $filename . ".new" );
2993 &AddPrototype( "keyval_create", $args );
2994
2995 # Default attribute functions.
2996 # We must create separate functions since we cannot rely on
2997 # using a preprocessor to alias the names.
2998 # OPTION: we could use weak symbols where available to
2999 # reduce the number of files.
3000 $OUTFD = "DUPFN";
3001 $filename = "dup_fnf.c";
3002 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3003 $files[$#files+1] = $filename;
3004 $args = "MPI_Fint, MPI_Fint *, void *, void **, void **, MPI_Fint *";
3005 &print_header( "mpi_dup_fn", "dup_fn", $args );
3006 &print_routine_type_decl( $OUTFD, "dup_fn" );
3007 &print_args( $OUTFD, $args, 0, "dup_fn" );
3008 #&print_attr;
3009 print $OUTFD "{
3010 *v5 = *v4;
3011 *v6 = MPIR_TO_FLOG(1);
3012 *ierr = MPI_SUCCESS;
3013 }\n";
3014 close ($OUTFD);
3015 &ReplaceIfDifferent( $filename, $filename . ".new" );
3016 &AddPrototype( "dup_fn", $args );
3017
3018 $OUTFD = "NULLDELFN";
3019 $filename = "null_del_fnf.c";
3020 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3021 $files[$#files+1] = $filename;
3022 $args = "MPI_Fint *, MPI_Fint *, void *, void *";
3023 &print_header( "mpi_null_delete_fn", "null_delete_fn", $args );
3024 &print_routine_type_decl( $OUTFD, "null_delete_fn" );
3025 &print_args( $OUTFD, $args, 0, "null_delete_fn" );
3026 #&print_attr;
3027 print $OUTFD "{
3028 *ierr = MPI_SUCCESS;
3029 }\n";
3030 close ($OUTFD);
3031 &ReplaceIfDifferent( $filename, $filename . ".new" );
3032 &AddPrototype( "null_delete_fn", $args );
3033
3034 $OUTFD = "NULLCOPYFN";
3035 $filename = "null_copy_fnf.c";
3036 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3037 $files[$#files+1] = $filename;
3038 $args = "MPI_Fint *, MPI_Fint *, void *, void *, void *, int *";
3039 &print_header( "mpi_null_copy_fn", "null_copy_fn", $args );
3040 &print_routine_type_decl( $OUTFD, "null_copy_fn" );
3041 &print_args( $OUTFD, $args, 0, "null_copy_fn" );
3042 print $OUTFD "{
3043 *ierr = MPI_SUCCESS;
3044 *v6 = MPIR_TO_FLOG(0);
3045 }\n";
3046 close ($OUTFD);
3047 &ReplaceIfDifferent( $filename, $filename . ".new" );
3048 &AddPrototype( "null_copy_fn", $args );
3049
3050 &WriteAttrDefaults( "comm_" );
3051 &WriteAttrDefaults( "win_" );
3052 &WriteAttrDefaults( "type_" );
3053
3054 # Datarep conversion function
3055 # This is a special case. We need to define this function
3056 # but it should never be called (we convert a reference to it
3057 # to a reference to null, which is how the C version of this
3058 # routine is defined.
3059 #
3060 # This is now part of the register_datarep function
3061 # $OUTFD = "NULLCONVERSIONFN";
3062 # $filename = "null_conv_fnf.c";
3063 # $returnType = "int";
3064 # open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3065 # $files[$#files+1] = $filename;
3066 # $args = "void *, MPI_Fint *, MPI_Fint *, void *, MPI_Offset *, MPI_Aint *, MPI_Fint *";
3067 # &print_header( "mpi_conversion_fn_null", "conversion_fn_null", $args,
3068 # "#ifdef MPI_CONVERSION_FN_NULL\n#undef MPI_CONVERSION_FN_NULL\n#endif\n" );
3069 # &print_routine_type_decl( $OUTFD, "conversion_fn_null" );
3070 # &print_args( $OUTFD, $args, 0, "conversion_fn_null" );
3071 # # This is tricky; we don't want to call this function at all
3072 # # FIXME
3073 # print $OUTFD "\n{\n return MPI_SUCCESS;\n}\n";
3074 # close ($OUTFD);
3075 # &ReplaceIfDifferent( $filename, $filename . ".new" );
3076 # &AddPrototype( "conversion_fn_null", $args );
3077
3078
3079 # The status conversion functions.
3080 # These are a little different because they are routines that
3081 # are called from C.
3082 # Also note that we must exclude them from the routines that
3083 # are generated for Fortran. These are here because they need to
3084 # know how Fortran stores a status (e.g., if C and Fortran integers
3085 # are the same size).
3086 $OUTFD = "STATUSF2C";
3087 $filename = "statusf2c.c";
3088 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3089 $files[$#files+1] = $filename;
3090 # Status_f2c and c2f will need to have const added before the input
3091 # argument for MPI 2.2
3092 print $OUTFD "
3093 /* -*- Mode: C; c-basic-offset:4 ; -*- */
3094 /*
3095 * (C) 2003 by Argonne National Laboratory and Northwestern University.
3096 * See COPYRIGHT in top-level directory.
3097 *
3098 * This file is automatically generated by command:\
3099 * ./buildiface $arg_string\
3100 * DO NOT EDIT
3101 */
3102 #include \"mpi_fortimpl.h\"
3103 /* mpierrs.h and mpierror.h for the error code creation */
3104 #include \"mpierrs.h\"
3105 #include <stdio.h>
3106 #include \"mpierror.h\"
3107
3108 /* -- Begin Profiling Symbol Block for routine MPI_Status_f2c */
3109 #if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES)
3110 #if defined(HAVE_PRAGMA_WEAK)
3111 #pragma weak MPI_Status_f2c = PMPI_Status_f2c
3112 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
3113 #pragma _HP_SECONDARY_DEF PMPI_Status_f2c MPI_Status_f2c
3114 #elif defined(HAVE_PRAGMA_CRI_DUP)
3115 #pragma _CRI duplicate MPI_Status_f2c as PMPI_Status_f2c
3116 #endif
3117 #endif
3118 /* -- End Profiling Symbol Block */
3119
3120 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
3121 the MPI routines */
3122 #ifndef MPICH_MPI_FROM_PMPI
3123 #undef MPI_Status_f2c
3124 #define MPI_Status_f2c PMPI_Status_f2c
3125 #endif
3126
3127 #undef FUNCNAME
3128 #define FUNCNAME MPI_Status_f2c
3129
3130 int MPI_Status_f2c( MPI_Fint *f_status, MPI_Status *c_status )
3131 {
3132 int mpi_errno = MPI_SUCCESS;
3133 /* This code assumes that the ints are the same size */\n";
3134 &specialInitStatement( $OUTFD );
3135 print $OUTFD "\
3136 if (f_status == MPI_F_STATUS_IGNORE) {
3137 /* The call is erroneous (see 4.12.5 in MPI-2) */
3138 mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
3139 \"MPI_Status_f2c\", __LINE__, MPI_ERR_OTHER, \"**notfstatignore\", 0 );
3140 return MPIR_Err_return_comm( 0, \"MPI_Status_f2c\", mpi_errno );
3141 }
3142 *c_status = *(MPI_Status *) f_status;
3143 return MPI_SUCCESS;
3144 }\n";
3145 close ($OUTFD);
3146 &ReplaceIfDifferent( $filename, $filename . ".new" );
3147
3148 $OUTFD = "STATUSC2F";
3149 $filename = "statusc2f.c";
3150 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3151 $files[$#files+1] = $filename;
3152 print $OUTFD "
3153 /* -*- Mode: C; c-basic-offset:4 ; -*- */
3154 /*
3155 * (C) 2003 by Argonne National Laboratory and Northwestern University.
3156 * See COPYRIGHT in top-level directory.
3157 *
3158 * This file is automatically generated by command:\
3159 * ./buildiface $arg_string\
3160 * DO NOT EDIT
3161 */
3162 #include \"mpi_fortimpl.h\"
3163 /* mpierrs.h and mpierror.h for the error code creation */
3164 #include \"mpierrs.h\"
3165 #include <stdio.h>
3166 #include \"mpierror.h\"
3167
3168 /* -- Begin Profiling Symbol Block for routine MPI_Status_c2f */
3169 #if defined(USE_WEAK_SYMBOLS) && !defined(USE_ONLY_MPI_NAMES)
3170 #if defined(HAVE_PRAGMA_WEAK)
3171 #pragma weak MPI_Status_c2f = PMPI_Status_c2f
3172 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
3173 #pragma _HP_SECONDARY_DEF PMPI_Status_c2f MPI_Status_c2f
3174 #elif defined(HAVE_PRAGMA_CRI_DUP)
3175 #pragma _CRI duplicate MPI_Status_c2f as PMPI_Status_c2f
3176 #endif
3177 #endif
3178 /* -- End Profiling Symbol Block */
3179
3180 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
3181 the MPI routines */
3182 #ifndef MPICH_MPI_FROM_PMPI
3183 #undef MPI_Status_c2f
3184 #define MPI_Status_c2f PMPI_Status_c2f
3185 #endif
3186
3187 #undef FUNCNAME
3188 #define FUNCNAME MPI_Status_c2f
3189
3190 int MPI_Status_c2f( MPI_Status *c_status, MPI_Fint *f_status )
3191 {
3192 int mpi_errno = MPI_SUCCESS;
3193 /* This code assumes that the ints are the same size */
3194 if (c_status == MPI_STATUS_IGNORE ||
3195 c_status == MPI_STATUSES_IGNORE) {
3196 /* The call is erroneous (see 4.12.5 in MPI-2) */
3197 mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
3198 \"MPI_Status_c2f\", __LINE__, MPI_ERR_OTHER, \"**notcstatignore\", 0 );
3199 return MPIR_Err_return_comm( 0, \"MPI_Status_c2f\", mpi_errno );
3200 }
3201 *(MPI_Status *)f_status = *c_status;
3202 return MPI_SUCCESS;
3203 }\n";
3204 close ($OUTFD);
3205 &ReplaceIfDifferent( $filename, $filename . ".new" );
3206
3207 }
3208
3209 sub print_mpif_int {
3210 my $key = $_[0];
3211 my $value = $mpidef{$key};
3212 my $valueOffset = $_[1];
3213 my $inttype = $_[2];
3214
3215 # integertype lets use change the integer type of the
3216 # variable; e.g., to make it integer*8 or integer (kind=MPI_OFFSET_KIND).
3217 # This is needed for MPI_DISPLACEMENT_CURRENT.
3218 # Because this will need to be set by configure, if set, this
3219 # needs to be a configure variable.
3220 my $integertype = "INTEGER";
3221
3222 if (defined($inttype)) {
3223 $integertype = $inttype;
3224 }
3225
3226 if (!defined($value) || $value eq "") {
3227 print STDERR "No value found for \"$key\"\n";
3228 return 0;
3229 }
3230 # Remove any casts
3231 print "Input value for $key = $value\n" if $debug;
3232 if ($value =~ /\(MPI/) {
3233 $value =~ s/\(MPI_[A-Za-z0-9]*\s*\)//;
3234 print "cast removal: $value\n" if $debug;
3235 }
3236 # Remove any surrounding ()
3237 if ($value =~ /\(\s*[-a-fx0-9]*\)/) {
3238 $value =~ s/\(\s*([-a-fx0-9]*)\s*\)/$1/;
3239 print "paren removal: $value\n" if $debug;
3240 }
3241 # Convert hex to decimal
3242 if ($value =~ /^0x[a-f\d]*/) {
3243 $value = hex $value;
3244 print "hex conversion: $value\n" if $debug;
3245 }
3246 if (defined($valueOffset) && $valueOffset ne "0") {
3247 if ($value =~ /^-?\d+/) {
3248 $value += $valueOffset;
3249 }
3250 else {
3251 $value .= "$valueOffset";
3252 }
3253 }
3254 print MPIFFD " $integertype $key\n";
3255 print MPIFFD " PARAMETER ($key=$value)\n";
3256 }
3257
3258 sub inq_file_info {
3259 print $OUTFD "{
3260 int ierr;
3261 MPI_Info info;
3262
3263 ierr = ncmpi_inq_file_info( (int)(*v1), &info );
3264 *v2 = MPI_Info_c2f(info);
3265 return ierr;
3266 }\n";
3267 }
3268
3269 sub get_file_info {
3270 print $OUTFD "{
3271 int ierr;
3272 MPI_Info info;
3273
3274 ierr = ncmpi_get_file_info( (int)(*v1), &info );
3275 *v2 = MPI_Info_c2f(info);
3276 return ierr;
3277 }\n";
3278 }
3279
3280 sub ReadAndProcessInterface {
3281 my $prototype_file = $_[0];
3282 my $protectMPIO = $_[1]; # Wrap MPI-IO routines in ifdefs MPI_MODE_RDONLY
3283 my $linecount = 0;
3284 my $newfilename = "";
3285 my $filename = "";
3286 open( FD, "<$prototype_file" ) || die "Cannot open $prototype_file\n";
3287
3288 # Skip to prototypes
3289 while (<FD>) {
3290 $linecount ++;
3291 if ( /\/\*\s*Begin Prototypes/ ) { last; }
3292 }
3293
3294 if (! $buildfiles) {
3295 $OUTFD = STDOUT;
3296 &print_copyright( );
3297 &print_gcc_pragma( );
3298 if ($build_prototypes) {
3299 print $OUTFD "
3300 /* Prototypes for the Fortran interfaces */
3301 #include \"$prototype_header_file\"
3302 ";
3303 }
3304 }
3305
3306 # Read each one
3307 while (<FD>) {
3308 $linecount ++;
3309 print $_ if $debug;
3310 # In some packages (not MPI but in PnetCDF) not all prototypes
3311 # have Fortran equivalents. The following lets us skip over them
3312 if (/\/\*\s*Begin Skip Prototypes/) {
3313 while (<FD>) {
3314 if (/\/\*\s*End Skip Prototypes/) { last; }
3315 }
3316 }
3317 if (/\/\*\s*End Prototypes/) { last; }
3318
3319 # We should also skip #ifndef xxx, for some xxx.
3320 if (/^#\s*ifndef\s+(\w*)/) {
3321 $ndefname = $1;
3322 if (defined($skipBlocks{$ndefname})) {
3323 &SkipCPPIfdef( FD );
3324 }
3325 }
3326 # Remove any comments; check for problems
3327 $origline = $_;
3328 while (/(.*)\/\*(.*?)\*\/(.*)/) {
3329 my $removed = $2;
3330 $_ = $1.$3;
3331 if ($2 =~ /\/\*/) {
3332 print STDERR "Error in processing comment within interface file $prototype_file in line $origline";
3333 }
3334 }
3335
3336 # if (/^int\s+$routine_prefix($routine_pattern)\s*\((.*)/) {
3337 if (/extern int/) { # next line is the API
3338 $_ = <FD>;
3339 if (/$routine_prefix($routine_pattern)\s*\((.*)/) {
3340 $routine_name = $1;
3341 $args = $2;
3342 while (! ($args =~ /;/)) {
3343 $args .= <FD>;
3344 $linecount++;
3345 }
3346 $args =~ s/\)\s*;//g;
3347 $args =~ s/[\r\n]*//g;
3348 # remove qualifiers from args
3349 ### TEMP - REMEMBER const because we may need it later
3350 $args =~ s/\s*const\s+//g;
3351 # Convert MPIO_Request to MPI_Request (temporary)
3352 # $args =~ s/MPIO_Request/MPI_Request/g;
3353
3354 # Get the name of the Fortran routine (without the prefix).
3355 # Normally, the name is just the lower-case version, but
3356 # some libraries (such as NetCDF) use "real" in Fortran
3357 # where C uses "float".
3358 $lcname = lc($routine_name);
3359 # $isIntAPI = ((substr($lcname, -3) eq "int") || (substr($lcname, -7) eq "int_all"));
3360 $isIntAPI = 0; # should keep _int API for buffer of type integer*4
3361 if (defined($CtoFName{$lcname})) {
3362 $lcname = $CtoFName{$lcname};
3363 }
3364 # Eventually, we'll create a new file here.
3365 # For C++, we may create similar files by looking up
3366 # the corresponding routines.
3367 if (defined($special_routines{$routine_name})) {
3368 print "Skipping $routine_name\n" if $debug;
3369 }
3370 else {
3371 # Check for duplicates in the list of routines
3372 if (defined($mpi_routines{$routine_name})) {
3373 my $found = "";
3374 if (defined($mpiRoutinesFile{$routine_name})) {
3375 my $location = $mpiRoutinesFile{$routine_name};
3376 $found = "previous prototoype found in $location\n";
3377 }
3378 print STDERR "Duplicate prototypes for $routine_name in $prototype_file:$linecount\n$found";
3379 next;
3380 }
3381 # Clear variables
3382 &clean_args;
3383 $mpi_routines{$routine_name} = $args;
3384 $mpiRoutinesFile{$routine_name} = "$prototype_file:$linecount";
3385
3386 $clean_up = "";
3387 if ($buildfiles) {
3388 if (defined($name_map{$lcname})) {
3389 $filename = $name_map{$lcname} . "f.c";
3390 }
3391 else {
3392 $filename = $lcname . "f.c";
3393 }
3394 $OUTFD = OUTPUTFILED; # Needed for pre 5.6 versions of perl
3395 $newfilename = $filename . ".new";
3396 open ($OUTFD, ">$newfilename" ) || die "Cannot open $newfilename\n";
3397 # Add the name to the list of files"
3398 $files[$#files+1] = $filename;
3399 }
3400 else {
3401 $OUTFD = STDOUT;
3402 }
3403 &print_header( $routine_name, $lcname, $args );
3404 if ($do_subdecls) {
3405 print $OUTFD "FORTRAN_API $returnType FORT_CALL ";
3406 }
3407 else {
3408 print $OUTFD "$returnType ";
3409 }
3410 print $OUTFD "${out_prefix}${lcname}_ ";
3411 # Print args not only prints the arguments but fills the
3412 # array @arg_addresses to indicate the number of dereference
3413 # operations are needed to recover the original value (since
3414 # all Fortran parameters are passed either by value-result or
3415 # by reference, many value parameters in the C calls are
3416 # replaced by reference parameters in the Fortran interface.
3417 print "Printing arguments for $routine_prefix${lcname}_\n" if $debug;
3418 &print_args( $OUTFD, $args, 0, $lcname );
3419
3420 if ($lcname eq "inq_file_info") {
3421 &inq_file_info( );
3422 }
3423 elsif ($lcname eq "get_file_info") {
3424 &get_file_info( );
3425 }
3426 elsif ($isIntAPI) {
3427 #&print_attr;
3428 print $OUTFD "{\n";
3429 &specialInitClear;
3430 &print_special_decls( $routine_name );
3431 print $OUTFD "#if SIZEOF_MPI_FINT == 8\n";
3432 if (defined($ChangeCall{$routine_name})) {
3433 my ($newName,$extraArgs) =
3434 split(/:/,$ChangeCall{$routine_name} );
3435 if (substr($newName, -7) eq "int_all") {
3436 $int_api = $newName;
3437 substr($int_api, -7) = "longlong_all";
3438 }
3439 else {
3440 $int_api = $newName;
3441 substr($int_api, -3) = "longlong";
3442 }
3443 print $OUTFD " $errparmlval = $int_api";
3444 my $largs = $args . "," . $extraArgs;
3445 &print_call_args( $largs );
3446 }
3447 else {
3448 if (substr($routine_name, -7) eq "int_all") {
3449 $int_api = $routine_name;
3450 substr($int_api, -7) = "longlong_all";
3451 }
3452 else {
3453 $int_api = $routine_name;
3454 substr($int_api, -3) = "longlong";
3455 }
3456 print $OUTFD " $errparmlval = $routine_prefix$int_api";
3457 print "Printing call arguments for mpi_${lcname}_\n" if $debug;
3458 &print_call_args( $args );
3459 }
3460 print $OUTFD "#else\n";
3461 if (defined($ChangeCall{$routine_name})) {
3462 my ($newName,$extraArgs) =
3463 split(/:/,$ChangeCall{$routine_name} );
3464 print $OUTFD " $errparmlval = $newName";
3465 my $largs = $args . "," . $extraArgs;
3466 &print_call_args( $largs );
3467 }
3468 else {
3469 print $OUTFD " $errparmlval = $routine_prefix$routine_name";
3470 print "Printing call arguments for mpi_${lcname}_\n" if $debug;
3471 &print_call_args( $args );
3472 }
3473 print $OUTFD "#endif\n";
3474 # Print any post call processing
3475 &print_post_call( $routine_name, $args );
3476 if ($returnErrval) {
3477 print $OUTFD " return $errparmrval;\n";
3478 }
3479 print $OUTFD "}\n";
3480 }
3481 else {
3482 #&print_attr;
3483 print $OUTFD "{\n";
3484 &specialInitClear;
3485 if ($protectMPIO) {
3486 print $OUTFD "#ifdef MPI_MODE_RDONLY\n";
3487 }
3488 &print_special_decls( $routine_name );
3489 if (defined($ChangeCall{$routine_name})) {
3490 my ($newName,$extraArgs) =
3491 split(/:/,$ChangeCall{$routine_name} );
3492 print $OUTFD " $errparmlval = $newName";
3493 my $largs = $args . "," . $extraArgs;
3494 &print_call_args( $largs );
3495 }
3496 else {
3497 print $OUTFD " $errparmlval = $routine_prefix$routine_name";
3498 print "Printing call arguments for mpi_${lcname}_\n" if $debug;
3499 &print_call_args( $args );
3500 }
3501 # Print any post call processing
3502 &print_post_call( $routine_name, $args );
3503 if ($protectMPIO) {
3504 print $OUTFD "#else\n$errparmlval = MPI_ERR_INTERN;\n#endif\n";
3505 }
3506 if ($returnErrval) {
3507 print $OUTFD " return $errparmrval;\n";
3508 }
3509 print $OUTFD "}\n";
3510 }
3511 if ($buildfiles) {
3512 close ($OUTFD);
3513 &ReplaceIfDifferent( $filename, $newfilename );
3514 }
3515 if ($build_prototypes) {
3516 if ($do_subdecls) {
3517 print PROTOFD "extern FORTRAN_API $returnType FORT_CALL ${out_prefix}${lcname}_ ";
3518 }
3519 else {
3520 print PROTOFD "extern $returnType ${out_prefix}${lcname}_ ";
3521 }
3522 &print_args( PROTOFD, $args, 0, $lcname );
3523 &print_attr( PROTOFD, "${out_prefix}${lcname}_" );
3524 print PROTOFD ";\n";
3525 }
3526 }
3527 }
3528 }
3529 }
3530 }
3531
3532 sub ReadInterfaceForDefinitions {
3533 my $prototype_file = $_[0];
3534 my $linecount = 0;
3535
3536 open ( MPIFD, "<$prototype_file" ) || die "Could not open $prototype_file\n";
3537 #
3538 # First, find the values that we need
3539 while (<MPIFD>) {
3540 $linecount++;
3541 # Remove any comments; check for problems
3542 $origline = $_;
3543 while (/(.*)\/\*(.*?)\*\/(.*)/) {
3544 my $removed = $2;
3545 $_ = $1.$3;
3546 if ($2 =~ /\/\*/) {
3547 print STDERR "Error in processing comment within interface file $prototype_file in line $origline";
3548 }
3549 }
3550
3551 # We should also skip #ifndef xxx, for some xxx.
3552 if (/^#\s*ifndef\s+(\w*)/) {
3553 $ndefname = $1;
3554 if (defined($skipBlocks{$ndefname})) {
3555 &SkipCPPIfdef( MPIFD );
3556 }
3557 }
3558
3559 # Use \S instead of [^\s]. See the comment above
3560 if (/^\s*#\s*define\s+(MPI_[A-Za-z_0-9]*)\s+(\S+)(.*)/) {
3561 my $name = $1;
3562 my $val = $2;
3563 my $remainder = $3;
3564 print "Found definition of $name as $val\n" if $debug;
3565 # If the name has some lower case letters in it, we
3566 # need to skip it (e.g., for a define MPI_Comm_c2f...)
3567 if ($name =~ /[a-z]/) { next; }
3568 if (defined($mpidef{$name})) {
3569 # We want to catch the case ((cast) value). In
3570 # The above definition, the space will break the
3571 # value into the cast (actually, "((cast)").
3572 $fullval = "$val $remainder";
3573 if ($fullval =~ /\(\(([^\(\)]*)\)\s*([^\(\)]*)\s*\)/) {
3574 $val = "(($1)$2)";
3575 }
3576 if ($mpidef{$name} ne $val) {
3577 my $found = "";
3578 if (defined($mpidefFile{$name})) {
3579 my $location = $mpidefFile{$name};
3580 $found = " found in $location";
3581 }
3582 print STDERR "Attempting to redefine $name with a new value $val found in $prototype_file:$linecount,\nusing original value of $mpidef{$name}$found\n";
3583 }
3584 }
3585 else {
3586 $mpidef{$name} = $val;
3587 $mpidefFile{$name} = "$prototype_file:$linecount";
3588 }
3589 }
3590 elsif (/typedef\s+enum\s+[A-Za-z0-9_]*\s*{\s*(.*)/) {
3591 # Allow a named type
3592 # Eat until we find the closing right brace
3593 $enum_line = $1;
3594 while (! ($enum_line =~ /}/)) {
3595 $enum_line .= <MPIFD>;
3596 $linecount++;
3597 }
3598 # Now process for names and values
3599 while ( ($enum_line =~ /\s*(MPI_[A-Z_0-9]*)\s*=\s*([a-fx0-9]*)(.*)/ ) ){
3600 $mpidef{$1} = $2;
3601 $mpidefFile{$1} = "$prototype_file:$linecount";
3602 $enum_line = $3;
3603 print "Defining $1 as $2\n" if $debug;
3604 }
3605
3606 }
3607 elsif (/enum\s+([A-Za-z0-9_]*)\s*{\s*(.*)/) {
3608 # Allow a named type
3609 # Eat until we find the closing right brace
3610 my $enum_name = $1;
3611 my $enum_line = $2;
3612 while (! ($enum_line =~ /}/)) {
3613 print "reading for $enum_name...\n" if $debug;
3614 my $newline = <MPIFD>;
3615 $newline =~ s/\r*\n//;
3616 $enum_line .= $newline;
3617 $linecount++;
3618 }
3619 # Now process for names and values
3620 while ( ($enum_line =~ /\s*(MPI_[A-Z_0-9]*)\s*=\s*([a-fx0-9]*)(.*)/ ) ){
3621 my $name = $1;
3622 my $val = $2;
3623 my $remainder = $3;
3624 $mpidef{$name} = $val;
3625 $mpidefFile{$name} = "$prototype_file:$linecount";
3626 $enum_line = $remainder;
3627 print "Defining $name as $val\n" if $debug;
3628 }
3629
3630 }
3631 }
3632 close (MPIFD);
3633 }
3634
3635 # ----------------------------------------------------------------------------
3636 # Check for a working autoconf
3637 #
3638 # Try the following first
3639 # in a new directory, create configure.in containing:
3640 # AC_INIT(configure.in)
3641 # AC_LANG_FORTRAN77
3642 # AC_TRY_COMPILE(,[integer a],a=1,a=0)
3643 # Then run autoconf
3644 # Then grep endEOF configure. If found (status 0), then autoconf is
3645 # broken.
3646 #
3647 # CheckAutoconf - returns 0 if autoconf works, 1 if broken.
3648 sub CheckAutoconf {
3649 if (! -d "tmp") {
3650 mkdir "tmp", 0777 || die "Cannot create temporary directory\n";
3651 }
3652 open (ACFD, ">tmp/configure.in" ) || die "Cannot create test configure.in\n";
3653 print ACFD "AC_INIT(configure.in)\nAC_LANG_FORTRAN77\n";
3654 print ACFD "AC_TRY_COMPILE(,[integer a],a=1,a=0)\n";
3655 close ACFD;
3656
3657 chdir 'tmp';
3658 $rc = system "autoconf >/dev/null 2>&1 ";
3659 $rc = system "grep endEOF configure >/dev/null 2>&1";
3660 $rc = !$rc;
3661 chdir "..";
3662
3663 system "rm -rf tmp";
3664 return $rc;
3665 }
3666 #
3667 # ISSUES NOT YET HANDLED
3668 # ----------------------------------------------------------------------------
3669 # Fortran Integer conversion.
3670 # If C ints and Fortran integers are not the same size, we have to do
3671 # more. In the case of arrays, we must make temporary copies.
3672 # In MPICH1, there is also code for the case where the sizes of
3673 # the C and Fortran integers are not known. Roughly, the code could look
3674 # like
3675 # #ifdef SIZEOF_F77_INTEGER = SIZEOF_INT
3676 # straight-forward code
3677 # #else
3678 # {
3679 # code that converts arrays, calls routine, frees arrays
3680 # }
3681 # #endif
3682 #
3683 # There are several options for allocating the temporary arrays
3684 # For some, like cartesian dimension arrays, it is reasonable to
3685 # use a predeclared array (and signal an error if too large)
3686 # For the others, use a predeclared array with a special case
3687 # for extra-large
3688 #
3689 # Scalars:
3690 # FintToint_in_decl: int *vi$count;
3691 # FintToint_in_arg: vi$count
3692 # FintToint_ftoc: vi$count = (int)v$count
3693 # similar for intToFint_out
3694 # For arrays,
3695 # FintTointArray_in_decl ...
3696 #
3697 # ----------------------------------------------------------------------------
3698 # Character buffer handling for choice arguments
3699 # If Fortran passes character arrays as a pair of arguments (rather than
3700 # putting the second argument at the end of the arg list), then all of the
3701 # choice arg routines must check the *count* of the number of arguments,
3702 # and then, if there are too many args, assume that the choice buffer
3703 # is a character. Note that for Sendrecv, there is no unique
3704 # solution unless you know more about the MPI datatypes.
3705 #
3706 # ----------------------------------------------------------------------------
3707 sub SkipCPPIfdef {
3708 my $FD = $_[0];
3709 my $depth = 1;
3710
3711 while (<$FD>) {
3712 if (/^#\s*endif/) {
3713 $depth--;
3714 #print "Depth is now $depth\n";
3715 }
3716 elsif (/^#\s*if/) {
3717 $depth++;
3718 #print "Depth is now $depth\n";
3719 }
3720 #print "Skipping $_";
3721 if ($depth <= 0) { last; }
3722 }
3723 return 0;
3724 }
3725 # ---------------------------------------------------------------------------
3726 # Add a prototype for (functionname, arguments)
3727 sub AddPrototype {
3728 my ($funcname,$args) = @_;
3729 if ($build_prototypes) {
3730 print PROTOFD "extern ";
3731 &print_routine_type_decl( PROTOFD, "$funcname" );
3732 &print_args( PROTOFD, $args, 1, "$funcname" );
3733 &print_attr( PROTOFD, "${out_prefix}${funcname}_" );
3734 print PROTOFD ";\n";
3735 }
3736 }
3737 # ---------------------------------------------------------------------------
3738 # This function writes the attribute copy/delete/dup functions
3739 # with a particular prefix (and a null prefix is allowed)
3740 # WriteAttrDefaults( prefix )
3741 sub WriteAttrDefaults {
3742 my $prefix =$_[0];
3743 my $ucprefix = uc($prefix);
3744
3745 my $filename = "dup_${prefix}fnf.c";
3746 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3747 $files[$#files+1] = $filename;
3748 # The dup functions with a prefix in Fortran take an MPI_Aint * as
3749 # the argument, not a void *. When sizeof(MPI_Aint) > sizeof(void *),
3750 # its important to use an MPI_Aint * instead of a void **
3751 # $args = "MPI_Fint, MPI_Fint *, void *, void **, void **, MPI_Fint *";
3752 $args = "MPI_Fint, MPI_Fint *, void *, MPI_FAintp, MPI_FAintp, MPI_Fint *";
3753 &print_header( "mpi_${prefix}dup_fn", "${prefix}dup_fn", $args,
3754 "#ifdef MPI_${ucprefix}DUP_FN\n#undef MPI_${ucprefix}DUP_FN\n#endif\n" );
3755 &print_routine_type_decl( $OUTFD, "${prefix}dup_fn" );
3756 &print_args( $OUTFD, $args, 0, "${prefix}dup_fn" );
3757 #&print_attr;
3758 print $OUTFD "{
3759 *v5 = *v4;
3760 *v6 = MPIR_TO_FLOG(1);
3761 *ierr = MPI_SUCCESS;
3762 }\n";
3763 close ($OUTFD);
3764 &ReplaceIfDifferent( $filename, $filename . ".new" );
3765 &AddPrototype( "${prefix}dup_fn", $args );
3766
3767 $OUTFD = "NULLDELFN";
3768 $filename = "null_${prefix}del_fnf.c";
3769 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3770 $files[$#files+1] = $filename;
3771 $args = "MPI_Fint *, MPI_Fint *, MPI_FAintp, MPI_FAintp";
3772 &print_header( "mpi_${prefix}null_delete_fn", "${prefix}null_delete_fn", $args,
3773 "#ifdef MPI_${ucprefix}NULL_DELETE_FN\n#undef MPI_${ucprefix}NULL_DELETE_FN\n#endif\n" );
3774 &print_routine_type_decl( $OUTFD, "${prefix}null_delete_fn" );
3775 &print_args( $OUTFD, $args, 0, "${prefix}null_delete_fn" );
3776 #&print_attr;
3777 print $OUTFD "{
3778 *ierr = MPI_SUCCESS;
3779 }\n";
3780 close ($OUTFD);
3781 &ReplaceIfDifferent( $filename, $filename . ".new" );
3782 &AddPrototype( "${prefix}null_delete_fn", $args );
3783
3784 $OUTFD = "NULLCOPYFN";
3785 $filename = "null_${prefix}copy_fnf.c";
3786 open ($OUTFD, ">$filename.new" ) || die "Cannot open $filename.new\n";
3787 $files[$#files+1] = $filename;
3788 $args = "MPI_Fint *, MPI_Fint *, MPI_FAintp, MPI_FAintp, MPI_FAintp, int *";
3789 &print_header( "mpi_${prefix}null_copy_fn", "${prefix}null_copy_fn", $args,
3790 "#ifdef MPI_${ucprefix}NULL_COPY_FN\n#undef MPI_${ucprefix}NULL_COPY_FN\n#endif\n" );
3791 &print_routine_type_decl( $OUTFD, "${prefix}null_copy_fn" );
3792 &print_args( $OUTFD, $args, 0, "${prefix}null_copy_fn" );
3793 print $OUTFD "{
3794 *ierr = MPI_SUCCESS;
3795 *v6 = MPIR_TO_FLOG(0);
3796 }\n";
3797 close ($OUTFD);
3798 &ReplaceIfDifferent( $filename, $filename . ".new" );
3799
3800 &AddPrototype( "${prefix}null_copy_fn", $args );
3801 }
3802
3803 #
3804 # Replace old file with new file only if new file is different
3805 # Otherwise, remove new filename
3806 sub ReplaceIfDifferent {
3807 my ($oldfilename,$newfilename) = @_;
3808 my $rc = 1;
3809 if (-s $oldfilename) {
3810 $rc = system "cmp -s $newfilename $oldfilename";
3811 $rc >>= 8; # Shift right to get exit status
3812 }
3813 if ($rc != 0) {
3814 # The files differ. Replace the old file
3815 # with the new one
3816 if (-s $oldfilename) {
3817 print STDERR "Replacing $oldfilename\n";
3818 unlink $oldfilename;
3819 }
3820 # else {
3821 # print STDERR "Creating $oldfilename\n";
3822 # }
3823 rename $newfilename, $oldfilename ||
3824 die "Could not replace $oldfilename";
3825 }
3826 else {
3827 unlink $newfilename;
3828 }
3829 }
3830 # ------------------------------------------------------------------------
3831 # We wish to have the option of adding a special init call for some
3832 # variables. This lets us ensure that MPI routines that need special
3833 # symbols (such as MPI_BOTTOM or MPI_IN_PLACE) can initialize them without
3834 # requiring any Fortran routines be called from the C verison of MPI_Init
3835 # (this can cause problems if the Fortran object file includes references
3836 # to compiler-specific symbols, making it difficult and inconvenient at
3837 # best to link C programs)
3838 # ------------------------------------------------------------------------
3839 sub specialInitClear {
3840 $specialInitAdded = 0;
3841 }
3842 sub specialInitStatement {
3843 my $FD = $_[0];
3844
3845 if ($specialInitAdded) { return; }
3846 if (length($specialInitString) > 0) {
3847 print $FD $specialInitString . "\n";
3848 }
3849 $specialInitAdded = 1;
3850 }
3851 # ------------------------------------------------------------------------
3852 # Helper function entries. Only one so far
3853 sub HelperForRegister_datarep {
3854 my $OUTFD = $_[0];
3855
3856 print $OUTFD "\
3857 /* There is a dummy routine, mpi_conversion_fn_null, that is available
3858 for use as the conversion function for MPI_Register_datarep.
3859 Like the attribute null functions, we provide multiple weak versions
3860 of this if possible */
3861 #if defined(USE_WEAK_SYMBOLS) && defined(HAVE_MULTIPLE_PRAGMA_WEAK)
3862 extern FORTRAN_API int FORT_CALL mpi_conversion_fn_null_ ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
3863 extern FORTRAN_API int FORT_CALL mpi_conversion_fn_null__ ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
3864 extern FORTRAN_API int FORT_CALL mpi_conversion_fn_null ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
3865 extern FORTRAN_API int FORT_CALL MPI_CONVERSION_FN_NULL ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
3866 /* */
3867 #ifndef MPICH_MPI_FROM_PMPI
3868 #pragma weak mpi_conversion_fn_null__ = mpi_conversion_fn_null_
3869 #pragma weak mpi_conversion_fn_null = mpi_conversion_fn_null_
3870 #pragma weak MPI_CONVERSION_FN_NULL = mpi_conversion_fn_null_
3871 #endif /* MPICH_MPI_FROM_PMPI */
3872
3873 #else
3874 /* No weak symbols, so simply rename the one version to match the
3875 Fortran naming convention */
3876 #ifdef F77_NAME_UPPER
3877 #define mpi_conversion_fn_null_ MPI_CONVERSION_FN_NULL
3878 #elif defined(F77_NAME_LOWER_2USCORE)
3879 #define mpi_conversion_fn_null_ mpi_conversion_fn_null__
3880 #elif !defined(F77_NAME_LOWER_USCORE)
3881 #define mpi_conversion_fn_null_ mpi_conversion_fn_null
3882 /* Else leave name alone */
3883 #endif /* Test on name mapping */
3884
3885 /* Add the prototype so the routine knows what this is */
3886 extern FORTRAN_API int FORT_CALL mpi_conversion_fn_null_ ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr );
3887
3888
3889 #endif /* Test on use multiple weak symbols */
3890 #ifndef MPICH_MPI_FROM_PMPI
3891
3892 /* This isn't a callable function */
3893 FORTRAN_API int FORT_CALL mpi_conversion_fn_null_ ( void*v1, MPI_Fint*v2, MPI_Fint*v3, void*v4, MPI_Offset*v5, MPI_Fint *v6, MPI_Fint*v7, MPI_Fint *ierr ) {
3894 return 0;
3895 }
3896 #endif
3897
3898 ";
3899
3900 }
3901
3902 sub HelperForType_create_keyval {
3903 my $OUTFD = $_[0];
3904
3905 print $OUTFD "\
3906
3907 /* The F90 attr copy function prototype and calling convention */
3908 typedef void (FORT_CALL F90_CopyFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *,MPI_Aint *, MPI_Fint *, MPI_Fint *);
3909
3910 /* Helper proxy function to thunk the attr copy function call into F90 calling convention */
3911 static
3912 int
3913 MPIR_Type_copy_attr_f90_proxy(
3914 MPI_Type_copy_attr_function* user_function,
3915 MPI_Datatype datatype,
3916 int keyval,
3917 void* extra_state,
3918 MPIR_AttrType value_type,
3919 void* value,
3920 void** new_value,
3921 int* flag
3922 )
3923 {
3924 MPI_Fint ierr = 0;
3925 MPI_Fint fhandle = (MPI_Fint)datatype;
3926 MPI_Fint fkeyval = (MPI_Fint)keyval;
3927 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
3928 MPI_Aint* fextra = (MPI_Aint*)extra_state;
3929 MPI_Aint fnew = 0;
3930 MPI_Fint fflag = 0;
3931
3932 ((F90_CopyFunction*)user_function)( &fhandle, &fkeyval, fextra, &fvalue, &fnew, &fflag, &ierr );
3933
3934 *flag = fflag;
3935 *new_value = MPI_AINT_CAST_TO_VOID_PTR (fnew);
3936 return ierr;
3937 }
3938
3939
3940 /* The F90 attr delete function prototype and calling convention */
3941 typedef void (FORT_CALL F90_DeleteFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *, MPI_Fint *);
3942
3943 /* Helper proxy function to thunk the attr delete function call into F77 calling convention */
3944 static
3945 int
3946 MPIR_Type_delete_attr_f90_proxy(
3947 MPI_Type_delete_attr_function* user_function,
3948 MPI_Datatype datatype,
3949 int keyval,
3950 MPIR_AttrType value_type,
3951 void* value,
3952 void* extra_state
3953 )
3954 {
3955 MPI_Fint ierr = 0;
3956 MPI_Fint fhandle = (MPI_Fint)datatype;
3957 MPI_Fint fkeyval = (MPI_Fint)keyval;
3958 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
3959 MPI_Aint* fextra = (MPI_Aint*)extra_state;
3960
3961 ((F90_DeleteFunction*)user_function)( &fhandle, &fkeyval, &fvalue, fextra, &ierr );
3962 return ierr;
3963 }\n";
3964 }
3965
3966 sub HelperForComm_create_keyval {
3967 my $OUTFD = $_[0];
3968
3969 print $OUTFD "\
3970
3971 /* The F90 attr copy function prototype and calling convention */
3972 typedef void (FORT_CALL F90_CopyFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *,MPI_Aint *, MPI_Fint *, MPI_Fint *);
3973
3974 /* Helper proxy function to thunk the attr copy function call into F90 calling convention */
3975 static
3976 int
3977 MPIR_Comm_copy_attr_f90_proxy(
3978 MPI_Comm_copy_attr_function* user_function,
3979 MPI_Comm comm,
3980 int keyval,
3981 void* extra_state,
3982 MPIR_AttrType value_type,
3983 void* value,
3984 void** new_value,
3985 int* flag
3986 )
3987 {
3988 MPI_Fint ierr = 0;
3989 MPI_Fint fhandle = (MPI_Fint)comm;
3990 MPI_Fint fkeyval = (MPI_Fint)keyval;
3991 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
3992 MPI_Aint* fextra = (MPI_Aint*)extra_state;
3993 MPI_Aint fnew = 0;
3994 MPI_Fint fflag = 0;
3995
3996 ((F90_CopyFunction*)user_function)( &fhandle, &fkeyval, fextra, &fvalue, &fnew, &fflag, &ierr );
3997
3998 *flag = fflag;
3999 *new_value = MPI_AINT_CAST_TO_VOID_PTR (fnew);
4000 return ierr;
4001 }
4002
4003
4004 /* The F90 attr delete function prototype and calling convention */
4005 typedef void (FORT_CALL F90_DeleteFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *, MPI_Fint *);
4006
4007 /* Helper proxy function to thunk the attr delete function call into F77 calling convention */
4008 static
4009 int
4010 MPIR_Comm_delete_attr_f90_proxy(
4011 MPI_Comm_delete_attr_function* user_function,
4012 MPI_Comm comm,
4013 int keyval,
4014 MPIR_AttrType value_type,
4015 void* value,
4016 void* extra_state
4017 )
4018 {
4019 MPI_Fint ierr = 0;
4020 MPI_Fint fhandle = (MPI_Fint)comm;
4021 MPI_Fint fkeyval = (MPI_Fint)keyval;
4022 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
4023 MPI_Aint* fextra = (MPI_Aint*)extra_state;
4024
4025 ((F90_DeleteFunction*)user_function)( &fhandle, &fkeyval, &fvalue, fextra, &ierr );
4026 return ierr;
4027 }\n";
4028 }
4029
4030 sub HelperForWin_create_keyval {
4031 my $OUTFD = $_[0];
4032
4033 print $OUTFD "\
4034
4035 /* The F90 attr copy function prototype and calling convention */
4036 typedef void (FORT_CALL F90_CopyFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *,MPI_Aint *, MPI_Fint *, MPI_Fint *);
4037
4038 /* Helper proxy function to thunk the attr copy function call into F90 calling convention */
4039 static
4040 int
4041 MPIR_Win_copy_attr_f90_proxy(
4042 MPI_Win_copy_attr_function* user_function,
4043 MPI_Win win,
4044 int keyval,
4045 void* extra_state,
4046 MPIR_AttrType value_type,
4047 void* value,
4048 void** new_value,
4049 int* flag
4050 )
4051 {
4052 MPI_Fint ierr = 0;
4053 MPI_Fint fhandle = (MPI_Fint)win;
4054 MPI_Fint fkeyval = (MPI_Fint)keyval;
4055 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
4056 MPI_Aint* fextra = (MPI_Aint*)extra_state;
4057 MPI_Aint fnew = 0;
4058 MPI_Fint fflag = 0;
4059
4060 ((F90_CopyFunction*)user_function)( &fhandle, &fkeyval, fextra, &fvalue, &fnew, &fflag, &ierr );
4061
4062 *flag = fflag;
4063 *new_value = MPI_AINT_CAST_TO_VOID_PTR (fnew);
4064 return ierr;
4065 }
4066
4067
4068 /* The F90 attr delete function prototype and calling convention */
4069 typedef void (FORT_CALL F90_DeleteFunction) (MPI_Fint *, MPI_Fint *, MPI_Aint *, MPI_Aint *, MPI_Fint *);
4070
4071 /* Helper proxy function to thunk the attr delete function call into F77 calling convention */
4072 static
4073 int
4074 MPIR_Win_delete_attr_f90_proxy(
4075 MPI_Win_delete_attr_function* user_function,
4076 MPI_Win win,
4077 int keyval,
4078 MPIR_AttrType value_type,
4079 void* value,
4080 void* extra_state
4081 )
4082 {
4083 MPI_Fint ierr = 0;
4084 MPI_Fint fhandle = (MPI_Fint)win;
4085 MPI_Fint fkeyval = (MPI_Fint)keyval;
4086 MPI_Aint fvalue = MPI_VOID_PTR_CAST_TO_MPI_AINT (value);
4087 MPI_Aint* fextra = (MPI_Aint*)extra_state;
4088
4089 ((F90_DeleteFunction*)user_function)( &fhandle, &fkeyval, &fvalue, fextra, &ierr );
4090 return ierr;
4091 }\n";
4092 }
4093 #
4094 # FWRAPLIB is a special case. We want to compile all of the same files,
4095 # but with MPICH_MPI_FROM_PMPI defined, even (or especially) if weak symbols
4096 # are defined.
4097 #
4098 sub AddFwrapDefs {
4099 &print_line( MAKEFD, "wrap_objs = ", 80, "\\\n\t", 8 );
4100 for ($i=0; $i<=$#files; $i++) {
4101 $name = $files[$i];
4102 # files contains only the "mpi" files, which is what
4103 # we want
4104 my $basename = $name;
4105 $basename =~ s/\.c//;
4106 &print_line( MAKEFD, "_w$basename.o ", 80, "\\\n\t", 8 );
4107 }
4108 &print_endline( MAKEFD );
4109 # FWRAPNAME is the name of a library that contains ONLY the
4110 # Fortran wrappers
4111 print MAKEFD "FWRAPNAME = \@FWRAPNAME\@\n";
4112 print MAKEFD "\
4113 lib\${FWRAPNAME}_a_DIR = ROOTDIR/lib\
4114 lib\${FWRAPNAME}_a_SOURCES = \${wrap_objs}\n";
4115 }
4116
4117 sub AddFwrapBuild {
4118 for ($i=0; $i<=$#files; $i++) {
4119 $name = $files[$i];
4120 # files contains only the "mpi" files, which is what
4121 # we want
4122 my $basename = $name;
4123 $basename =~ s/\.c//;
4124 # Some versions of make won't figure out the $< in this case,
4125 # so we use the explicit version
4126 # To conform to the newer format of output produced by simplemake,
4127 # we output the same set of commands to shorten the output lines
4128 # (it seems wierd to optimize make output which is too long to
4129 # watch manually anyway, but this seems to be the current expected
4130 # practice). (Note that CC is the C++ compiler on some systems;
4131 # this use of CC is apparently supposed to be a shorthand for \$(CC),
4132 # which may not be correct either.
4133 print MAKEFD "_w$basename.o: $name\n";
4134 print MAKEFD " \@if [ \"x\$(VERBOSE)\" != \"x1\" ] ; then \\
4135 echo \" CC -o _w$basename.o -c -D... \$(srcdir)/$basename.c\" ; \\
4136 else \\
4137 echo \"\$(C_COMPILE) -o _w$basename.o -c -DMPICH_MPI_FROM_PMPI -DUSE_ONLY_MPI_NAMES \$(srcdir)/$basename.c\" ; \\
4138 fi\n";
4139 print MAKEFD "\t\@\$(C_COMPILE) -o _w$basename.o -c -DMPICH_MPI_FROM_PMPI -DUSE_ONLY_MPI_NAMES \$(srcdir)/$basename.c\n";
4140
4141 print MAKEFD "_w$basename.lo: $name\n";
4142 print MAKEFD " \@if [ \"x\$(VERBOSE)\" != \"x1\" ] ; then \\
4143 echo \" CC -o _sw$basename.o -c -D... \$(srcdir)/$basename.c\" ; \\
4144 else \\
4145 echo \"\$(C_COMPILE_SHL) -o _sw$basename.o -c -DMPICH_MPI_FROM_PMPI -DUSE_ONLY_MPI_NAMES \$(srcdir)/$basename.c\" ; \\
4146 fi\n";
4147 print MAKEFD "\t\@\$(C_COMPILE_SHL) -o _sw$basename.o -c -DMPICH_MPI_FROM_PMPI -DUSE_ONLY_MPI_NAMES \$(srcdir)/$basename.c\n";
4148 print MAKEFD "\t\@mv -f _sw$basename.o _w$basename.lo\n";
4149 }
4150 }
4151
4152 # Allow multiple underscore versions of names
4153 # but without the PMPI versions (needed for the wrapper library)
4154 sub AddFwrapWeakName {
4155 my ($lcname, $ucname, $args) = @_;
4156
4157 print $OUTFD "
4158 /* These definitions are used only for generating the Fortran wrappers */
4159 #if defined(USE_WEAK_SYMBOLS) && defined(HAVE_MULTIPLE_PRAGMA_WEAK) && \\
4160 defined(USE_ONLY_MPI_NAMES)\n";
4161 &print_weak_decl( $OUTFD, "MPI_$ucname", $args, $lcname );
4162 &print_weak_decl( $OUTFD, "mpi_${lcname}__", $args, $lcname );
4163 &print_weak_decl( $OUTFD, "mpi_${lcname}", $args, $lcname );
4164 &print_weak_decl( $OUTFD, "mpi_${lcname}_", $args, $lcname );
4165 print $OUTFD "\
4166 #if defined(F77_NAME_UPPER)
4167 #pragma weak mpi_${lcname}__ = MPI_${ucname}
4168 #pragma weak mpi_${lcname}_ = MPI_${ucname}
4169 #pragma weak mpi_${lcname} = MPI_${ucname}
4170 #elif defined(F77_NAME_LOWER_2USCORE)
4171 #pragma weak MPI_$ucname = mpi_${lcname}__
4172 #pragma weak mpi_${lcname}_ = mpi_${lcname}__
4173 #pragma weak mpi_${lcname} = mpi_${lcname}__
4174 #elif defined(F77_NAME_LOWER_USCORE)
4175 #pragma weak MPI_$ucname = mpi_${lcname}_
4176 #pragma weak mpi_${lcname}__ = mpi_${lcname}_
4177 #pragma weak mpi_${lcname} = mpi_${lcname}_
4178 #else
4179 #pragma weak MPI_$ucname = mpi_${lcname}
4180 #pragma weak mpi_${lcname}__ = mpi_${lcname}
4181 #pragma weak mpi_${lcname}_ = mpi_${lcname}
4182 #endif
4183
4184 #endif
4185 ";
4186 }