Logo AND Algorithmique Numérique Distribuée

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