1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2008 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
8 * This file contains the C routines used in testing that all C datatypes
9 * are available in Fortran and have the correct values.
11 * The tests follow this pattern:
13 * Fortran main program
14 * calls the c routine f2ctype with each of the C types and the name of
15 * the type. That c routine using MPI_Type_f2c to convert the
16 * Fortran handle to a C handle, and then compares it to the corresponding
17 * C type, which is found by looking up the C handle by name
19 * C routine uses xxx_f2c routine to get C handle, checks some
20 * properties (i.e., size and rank of communicator, contents of datatype)
22 * Then the Fortran main program calls a C routine that provides
23 * a handle, and the Fortran program performs similar checks.
25 * We also assume that a C int is a Fortran integer. If this is not the
26 * case, these tests must be modified.
29 /* style: allow:fprintf:10 sig:0 */
32 #include "../../include/mpitestconf.h"
35 /* Create an array with all of the MPI names in it */
36 /* This is extracted from the test in test/mpi/types/typename.c ; only the
37 C types are included. */
39 typedef struct mpi_names_t { MPI_Datatype dtype; const char *name; } mpi_names_t;
41 /* The MPI standard specifies that the names must be the MPI names,
42 not the related language names (e.g., MPI_CHAR, not char) */
44 static mpi_names_t mpi_names[] = {
45 { MPI_CHAR, "MPI_CHAR" },
46 { MPI_SIGNED_CHAR, "MPI_SIGNED_CHAR" },
47 { MPI_UNSIGNED_CHAR, "MPI_UNSIGNED_CHAR" },
48 { MPI_WCHAR, "MPI_WCHAR" },
49 { MPI_SHORT, "MPI_SHORT" },
50 { MPI_UNSIGNED_SHORT, "MPI_UNSIGNED_SHORT" },
51 { MPI_INT, "MPI_INT" },
52 { MPI_UNSIGNED, "MPI_UNSIGNED" },
53 { MPI_LONG, "MPI_LONG" },
54 { MPI_UNSIGNED_LONG, "MPI_UNSIGNED_LONG" },
55 { MPI_FLOAT, "MPI_FLOAT" },
56 { MPI_DOUBLE, "MPI_DOUBLE" },
57 { MPI_FLOAT_INT, "MPI_FLOAT_INT" },
58 { MPI_DOUBLE_INT, "MPI_DOUBLE_INT" },
59 { MPI_LONG_INT, "MPI_LONG_INT" },
60 { MPI_SHORT_INT, "MPI_SHORT_INT" },
61 { MPI_2INT, "MPI_2INT" },
62 { MPI_LONG_DOUBLE, "MPI_LONG_DOUBLE" },
63 { MPI_LONG_LONG_INT, "MPI_LONG_LONG_INT" },
64 { MPI_LONG_LONG, "MPI_LONG_LONG" },
65 { MPI_UNSIGNED_LONG_LONG, "MPI_UNSIGNED_LONG_LONG" },
66 { MPI_LONG_DOUBLE_INT, "MPI_LONG_DOUBLE_INT" },
67 { 0, (char *)0 }, /* Sentinal used to indicate the last element */
71 Name mapping. All routines are created with names that are lower case
72 with a single trailing underscore. This matches many compilers.
73 We use #define to change the name for Fortran compilers that do
74 not use the lowercase/underscore pattern
78 #define f2ctype_ F2CTYPE
80 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
81 /* Mixed is ok because we use lowercase in all uses */
82 #define f2ctype_ f2ctype
84 #elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE) || \
85 defined(F77_NAME_MIXED_USCORE)
86 /* Else leave name alone (routines have no underscore, so both
87 of these map to a lowercase, single underscore) */
89 #error 'Unrecognized Fortran name mapping'
92 /* Prototypes to keep compilers happy */
93 int f2ctype_( MPI_Fint *, MPI_Fint * );
96 int f2ctype_( MPI_Fint *fhandle, MPI_Fint *typeidx )
101 /* printf( "Testing %s\n", mpi_names[*typeidx].name ); */
102 ctype = MPI_Type_f2c( *fhandle );
103 if (ctype != mpi_names[*typeidx].dtype) {
104 char mytypename[MPI_MAX_OBJECT_NAME];
106 /* An implementation is not *required* to deliver the
107 corresponding C version of the MPI Datatype bit-for-bit. But
108 if *must* act like it - e.g., the datatype name must be the same */
109 MPI_Type_get_name( ctype, mytypename, &mytypenamelen );
110 if (strcmp( mytypename, mpi_names[*typeidx].name ) != 0) {
112 printf( "C and Fortran types for %s (c name is %s) do not match f=%d, ctof=%d.\n",
113 mpi_names[*typeidx].name, mytypename, *fhandle, MPI_Type_c2f( ctype ) );