|
Packit |
0848f5 |
/* This file created from test/mpi/f77/io/c2f2cio.c with f77tof90 */
|
|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* This file contains the C routines used in testing the c2f and f2c
|
|
Packit |
0848f5 |
* handle conversion functions for MPI_File
|
|
Packit |
0848f5 |
* The tests follow this pattern:
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* Fortran main program
|
|
Packit |
0848f5 |
* calls c routine with each handle type, with a prepared
|
|
Packit |
0848f5 |
* and valid handle (often requires constructing an object)
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* C routine uses xxx_f2c routine to get C handle, checks some
|
|
Packit |
0848f5 |
* properties (i.e., size and rank of communicator, contents of datatype)
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* Then the Fortran main program calls a C routine that provides
|
|
Packit |
0848f5 |
* a handle, and the Fortran program performs similar checks.
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* We also assume that a C int is a Fortran integer. If this is not the
|
|
Packit |
0848f5 |
* case, these tests must be modified.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* style: allow:fprintf:1 sig:0 */
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include "mpi.h"
|
|
Packit |
0848f5 |
#include "../../include/mpitestconf.h"
|
|
Packit |
0848f5 |
#include <string.h>
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
Name mapping. All routines are created with names that are lower case
|
|
Packit |
0848f5 |
with a single trailing underscore. This matches many compilers.
|
|
Packit |
0848f5 |
We use #define to change the name for Fortran compilers that do
|
|
Packit |
0848f5 |
not use the lowercase/underscore pattern
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#ifdef F77_NAME_UPPER
|
|
Packit |
0848f5 |
#define c2ffile_ C2FFILE
|
|
Packit |
0848f5 |
#define f2cfile_ F2CFILE
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#elif defined(F77_NAME_LOWER) || defined(F77_NAME_MIXED)
|
|
Packit |
0848f5 |
/* Mixed is ok because we use lowercase in all uses */
|
|
Packit |
0848f5 |
#define c2ffile_ c2ffile
|
|
Packit |
0848f5 |
#define f2cfile_ f2cfile
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#elif defined(F77_NAME_LOWER_2USCORE) || defined(F77_NAME_LOWER_USCORE) || \
|
|
Packit |
0848f5 |
defined(F77_NAME_MIXED_USCORE)
|
|
Packit |
0848f5 |
/* Else leave name alone (routines have no underscore, so both
|
|
Packit |
0848f5 |
of these map to a lowercase, single underscore) */
|
|
Packit |
0848f5 |
#else
|
|
Packit |
0848f5 |
#error 'Unrecognized Fortran name mapping'
|
|
Packit |
0848f5 |
#endif
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Prototypes to keep compilers happy */
|
|
Packit |
0848f5 |
int c2ffile_(int *);
|
|
Packit |
0848f5 |
void f2cfile_(int *);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int c2ffile_(int *file)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
MPI_File cFile = MPI_File_f2c(*file);
|
|
Packit |
0848f5 |
MPI_Group group, wgroup;
|
|
Packit |
0848f5 |
int result;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_File_get_group(cFile, &group);
|
|
Packit |
0848f5 |
MPI_Comm_group(MPI_COMM_WORLD, &wgroup);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Group_compare(group, wgroup, &result);
|
|
Packit |
0848f5 |
if (result != MPI_IDENT) {
|
|
Packit |
0848f5 |
fprintf(stderr, "File: did not get expected group\n");
|
|
Packit |
0848f5 |
return 1;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Group_free(&group);
|
|
Packit |
0848f5 |
MPI_Group_free(&wgroup);
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* The following routines provide handles to the calling Fortran program
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
void f2cfile_(int *file)
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
MPI_File cFile;
|
|
Packit |
0848f5 |
int rc;
|
|
Packit |
0848f5 |
rc = MPI_File_open(MPI_COMM_WORLD, (char *) "temp",
|
|
Packit |
0848f5 |
MPI_MODE_RDWR | MPI_MODE_DELETE_ON_CLOSE | MPI_MODE_CREATE,
|
|
Packit |
0848f5 |
MPI_INFO_NULL, &cFile);
|
|
Packit |
0848f5 |
if (rc) {
|
|
Packit |
0848f5 |
*file = 0;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
*file = MPI_File_c2f(cFile);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|