Debian Codegraph @

test/mpi/f77/rma/c2f2cwin.c

raw
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 /*
7 * This file contains the C routines used in testing the c2f and f2c
8 * handle conversion functions for MPI_Win
9 *
10 * The tests follow this pattern:
11 *
12 * Fortran main program
13 * calls c routine with each handle type, with a prepared
14 * and valid handle (often requires constructing an object)
15 *
16 * C routine uses xxx_f2c routine to get C handle, checks some
17 * properties (i.e., size and rank of communicator, contents of datatype)
18 *
19 * Then the Fortran main program calls a C routine that provides
20 * a handle, and the Fortran program performs similar checks.
21 *
22 * We also assume that a C int is a Fortran integer. If this is not the
23 * case, these tests must be modified.
24 */
25
26 /* style: allow:fprintf:1 sig:0 */
27 #include <stdio.h>
28 #include "mpi.h"
29 #include "../../include/mpitestconf.h"
30 #include <string.h>
31
32 /*
33 Name mapping. All routines are created with names that are lower case
34 with a single trailing underscore. This matches many compilers.
35 We use #define to change the name for Fortran compilers that do
36 not use the lowercase/underscore pattern
37 */
38
39 #ifdef F77_NAME_UPPER
40 #define c2fwin_ C2FWIN
41 #define f2cwin_ F2CWIN
42
43 #elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
44 /* Mixed is ok because we use lowercase in all uses */
45 #define c2fwin_ c2fwin
46 #define f2cwin_ f2cwin
47
48 #elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE) || \
49 defined(F77_NAME_MIXED_USCORE)
50 /* Else leave name alone (routines have no underscore, so both
51 of these map to a lowercase, single underscore) */
52 #else
53 #error 'Unrecognized Fortran name mapping'
54 #endif
55
56 /* Prototypes to keep compilers happy */
57 int c2fwin_(int *);
58 void f2cwin_(int *);
59
60 int c2fwin_(int *win)
61 {
62 MPI_Win cWin = MPI_Win_f2c(*win);
63 MPI_Group group, wgroup;
64 int result;
65
66 MPI_Win_get_group(cWin, &group);
67 MPI_Comm_group(MPI_COMM_WORLD, &wgroup);
68
69 MPI_Group_compare(group, wgroup, &result);
70 if (result != MPI_IDENT) {
71 fprintf(stderr, "Win: did not get expected group\n");
72 return 1;
73 }
74
75 MPI_Group_free(&group);
76 MPI_Group_free(&wgroup);
77
78 return 0;
79 }
80
81 /*
82 * The following routines provide handles to the calling Fortran program
83 */
84 void f2cwin_(int *win)
85 {
86 MPI_Win cWin;
87 MPI_Win_create(0, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &cWin);
88 *win = MPI_Win_c2f(cWin);
89 }