Logo AND Algorithmique Numérique Distribuée

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