1
1
openmpi/ompi/mpi/fortran/mpif-h/register_datarep_f.c
Jeff Squyres 253444c6d0 == Highlights ==
1. New mpifort wrapper compiler: you can utilize mpif.h, use mpi, and use mpi_f08 through this one wrapper compiler
 1. mpif77 and mpif90 still exist, but are sym links to mpifort and may be removed in a future release
 1. The mpi module has been re-implemented and is significantly "mo' bettah"
 1. The mpi_f08 module offers many, many improvements over mpif.h and the mpi module

This stuff is coming from a VERY long-lived mercurial branch (3 years!); it'll almost certainly take a few SVN commits and a bunch of testing before I get it correctly committed to the SVN trunk.

== More details ==

Craig Rasmussen and I have been working with the MPI-3 Fortran WG and Fortran J3 committees for a long, long time to make a prototype MPI-3 Fortran bindings implementation.  We think we're at a stable enough state to bring this stuff back to the trunk, with the goal of including it in OMPI v1.7.  

Special thanks go out to everyone who has been incredibly patient and helpful to us in this journey:

 * Rolf Rabenseifner/HLRS (mastermind/genius behind the entire MPI-3 Fortran effort)
 * The Fortran J3 committee
 * Tobias Burnus/gfortran
 * Tony !Goetz/Absoft
 * Terry !Donte/Oracle
 * ...and probably others whom I'm forgetting :-(

There's still opportunities for optimization in the mpi_f08 implementation, but by and large, it is as far along as it can be until Fortran compilers start implementing the new F08 dimension(..) syntax.

Note that gfortran is currently unsupported for the mpi_f08 module and the new mpi module.  gfortran users will a) fall back to the same mpi module implementation that is in OMPI v1.5.x, and b) not get the new mpi_f08 module.  The gfortran maintainers are actively working hard to add the necessary features to support both the new mpi_f08 module and the new mpi module implementations.  This will take some time.

As mentioned above, ompi/mpi/f77 and ompi/mpi/f90 no longer exist.  All the fortran bindings implementations have been collated under ompi/mpi/fortran; each implementation has its own subdirectory:

{{{
ompi/mpi/fortran/
  base/               - glue code
  mpif-h/             - what used to be ompi/mpi/f77
  use-mpi-tkr/        - what used to be ompi/mpi/f90
  use-mpi-ignore-tkr/ - new mpi module implementation
  use-mpi-f08/        - new mpi_f08 module implementation
}}}

There's also a prototype 6-function-MPI implementation under use-mpi-f08-desc that emulates the new F08 dimension(..) syntax that isn't fully available in Fortran compilers yet.  We did that to prove it to ourselves that it could be done once the compilers fully support it.  This directory/implementation will likely eventually replace the use-mpi-f08 version.

Other things that were done:

 * ompi_info grew a few new output fields to describe what level of Fortran support is included
 * Existing Fortran examples in examples/ were renamed; new mpi_f08 examples were added
 * The old Fortran MPI libraries were renamed:
   * libmpi_f77 -> libmpi_mpifh
   * libmpi_f90 -> libmpi_usempi
 * The configury for Fortran was consolidated and significantly slimmed down.  Note that the F77 env variable is now IGNORED for configure; you should only use FC. Example:
{{{
shell$ ./configure CC=icc CXX=icpc FC=ifort ...
}}}

All of this work was done in a Mercurial branch off the SVN trunk, and hosted at Bitbucket.  This branch has got to be one of OMPI's longest-running branches.  Its first commit was Tue Apr 07 23:01:46 2009 -0400 -- it's over 3 years old!  :-)  We think we've pulled in all relevant changes from the OMPI trunk (e.g., Fortran implementations of the new MPI-3 MPROBE stuff for mpif.h, use mpi, and use mpi_f08, and the recent Fujitsu Fortran patches).

I anticipate some instability when we bring this stuff into the trunk, simply because it touches a LOT of code in the MPI layer in the OMPI code base.  We'll try our best to make it as pain-free as possible, but please bear with us when it is committed.

This commit was SVN r26283.
2012-04-18 15:57:29 +00:00

254 строки
11 KiB
C

/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "ompi_config.h"
#include "opal/class/opal_object.h"
#include "ompi/mpi/fortran/mpif-h/bindings.h"
#include "ompi/mpi/fortran/base/constants.h"
#include "ompi/mpi/fortran/base/datarep.h"
#include "ompi/mpi/fortran/base/strings.h"
#include "ompi/mpi/fortran/base/fint_2_int.h"
#include "ompi/runtime/mpiruntime.h"
#include "ompi/file/file.h"
#if OPAL_HAVE_WEAK_SYMBOLS && OMPI_PROFILE_LAYER
#pragma weak PMPI_REGISTER_DATAREP = ompi_register_datarep_f
#pragma weak pmpi_register_datarep = ompi_register_datarep_f
#pragma weak pmpi_register_datarep_ = ompi_register_datarep_f
#pragma weak pmpi_register_datarep__ = ompi_register_datarep_f
#pragma weak PMPI_Register_datarep_f = ompi_register_datarep_f
#pragma weak PMPI_Register_datarep_f08 = ompi_register_datarep_f
#elif OMPI_PROFILE_LAYER
OMPI_GENERATE_F77_BINDINGS (PMPI_REGISTER_DATAREP,
pmpi_register_datarep,
pmpi_register_datarep_,
pmpi_register_datarep__,
pompi_register_datarep_f,
(char *datarep, ompi_mpi2_fortran_datarep_conversion_fn_t *read_conversion_fn, ompi_mpi2_fortran_datarep_conversion_fn_t *write_conversion_fn, ompi_mpi2_fortran_datarep_extent_fn_t *dtype_file_extent_fn, MPI_Aint *extra_state, MPI_Fint *ierr, int datarep_len),
(datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr, datarep_len) )
#endif
#if OPAL_HAVE_WEAK_SYMBOLS
#pragma weak MPI_REGISTER_DATAREP = ompi_register_datarep_f
#pragma weak mpi_register_datarep = ompi_register_datarep_f
#pragma weak mpi_register_datarep_ = ompi_register_datarep_f
#pragma weak mpi_register_datarep__ = ompi_register_datarep_f
#pragma weak MPI_Register_datarep_f = ompi_register_datarep_f
#pragma weak MPI_Register_datarep_f08 = ompi_register_datarep_f
#endif
#if ! OPAL_HAVE_WEAK_SYMBOLS && ! OMPI_PROFILE_LAYER
OMPI_GENERATE_F77_BINDINGS (MPI_REGISTER_DATAREP,
mpi_register_datarep,
mpi_register_datarep_,
mpi_register_datarep__,
ompi_register_datarep_f,
(char *datarep, ompi_mpi2_fortran_datarep_conversion_fn_t *read_conversion_fn, ompi_mpi2_fortran_datarep_conversion_fn_t *write_conversion_fn, ompi_mpi2_fortran_datarep_extent_fn_t *dtype_file_extent_fn, MPI_Aint *extra_state, MPI_Fint *ierr, int datarep_len),
(datarep, read_conversion_fn, write_conversion_fn, dtype_file_extent_fn, extra_state, ierr, datarep_len) )
#endif
#if OMPI_PROFILE_LAYER && ! OPAL_HAVE_WEAK_SYMBOLS
#include "ompi/mpi/fortran/mpif-h/profile/defines.h"
#endif
static const char FUNC_NAME[] = "MPI_REGISTER_DATAREP";
/* Intercept functions used below (see below for explanations in
comments) */
static int read_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
void *filebuf, MPI_Offset position,
void *extra_state);
static int write_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
void *filebuf, MPI_Offset position,
void *extra_state);
static int extent_intercept_fn(MPI_Datatype type_c, MPI_Aint *file_extent,
void *extra_state);
/* Data structure passed to the intercepts (see below). It is an OPAL
list_item_t so that we can clean this memory up during
MPI_FINALIZE. */
typedef struct intercept_extra_state {
opal_list_item_t base;
ompi_mpi2_fortran_datarep_conversion_fn_t *read_fn_f77;
ompi_mpi2_fortran_datarep_conversion_fn_t *write_fn_f77;
ompi_mpi2_fortran_datarep_extent_fn_t *extent_fn_f77;
MPI_Aint *extra_state_f77;
} intercept_extra_state_t;
OBJ_CLASS_DECLARATION(intercept_extra_state_t);
#if !OMPI_PROFILE_LAYER || OPAL_HAVE_WEAK_SYMBOLS
static void intercept_extra_state_constructor(intercept_extra_state_t *obj)
{
obj->read_fn_f77 = NULL;
obj->write_fn_f77 = NULL;
obj->extent_fn_f77 = NULL;
obj->extra_state_f77 = NULL;
}
OBJ_CLASS_INSTANCE(intercept_extra_state_t,
opal_list_item_t,
intercept_extra_state_constructor, NULL);
#endif /* !OMPI_PROFILE_LAYER */
/*
* This function works by calling the C version of
* MPI_Register_datarep (like most other MPI API functions). To do
* that, however, we need to call the C MPI_Register_datarep with *C*
* callback functions -- the callback functions passed in to this
* function are Fortran functions, and expect Fortran argument passing
* conventions.
*
* So we have 3 C intercept functions that are passed to the back-end
* MPI_Register_datarep. Hence, when/if this datarep is ever used,
* the intercept function(s) are invoked, who then translate the
* arguments to Fortran and then invoke the registered callback
* function.
*/
void ompi_register_datarep_f(char *datarep,
ompi_mpi2_fortran_datarep_conversion_fn_t *read_fn_f77,
ompi_mpi2_fortran_datarep_conversion_fn_t *write_fn_f77,
ompi_mpi2_fortran_datarep_extent_fn_t *extent_fn_f77,
MPI_Aint *extra_state_f77,
MPI_Fint *ierr, int datarep_len)
{
char *c_datarep;
int c_ierr, ret;
MPI_Datarep_conversion_function *read_fn_c, *write_fn_c;
intercept_extra_state_t *intercept;
/* Malloc space for the intercept callback data */
intercept = OBJ_NEW(intercept_extra_state_t);
if (NULL == intercept) {
c_ierr = OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL,
OMPI_ERR_OUT_OF_RESOURCE, FUNC_NAME);
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
return;
}
/* Save the new object on a global list because per MPI-2:9.5.3,
there are no ways for the user to deregister datareps once
they've been created. Hece, this is a memory leak. So we
track these extra resources in a global list so that they can
be freed during MPI_FINALIZE (so that memory-tracking debuggers
won't show MPI as leaking memory). */
opal_list_append(&ompi_registered_datareps, &(intercept->base));
/* Convert the fortran string */
if (OMPI_SUCCESS != (ret = ompi_fortran_string_f2c(datarep, datarep_len,
&c_datarep))) {
c_ierr = OMPI_ERRHANDLER_INVOKE(MPI_FILE_NULL, ret, FUNC_NAME);
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
return;
}
/* Convert the Fortran function callbacks to C equivalents. Use
local intercepts if they're not MPI_CONVERSION_FN_NULL so that
we can just call the C MPI API MPI_Register_datarep(). If they
*are* MPI_CONVERSION_FN_NULL, then just pass that to
MPI_Register_datarep so that it becomes a no-op (i.e., no
callback is ever triggered). */
if (OMPI_IS_FORTRAN_CONVERSION_FN_NULL(read_fn_f77)) {
/* Can't use the MPI_CONVERSION_FN_NULL macro here because it
is specifically not defined when compiling this file so
that we can prototype an all-caps Fortran function */
read_fn_c = (MPI_Datarep_conversion_function*) 0;
} else {
intercept->read_fn_f77 = read_fn_f77;
read_fn_c = read_intercept_fn;
}
if (OMPI_IS_FORTRAN_CONVERSION_FN_NULL(write_fn_f77)) {
/* Can't use the MPI_CONVERSION_FN_NULL macro here because it
is specifically not defined when compiling this file so
that we can prototype an all-caps Fortran function */
write_fn_c = (MPI_Datarep_conversion_function*) 0;
} else {
intercept->write_fn_f77 = write_fn_f77;
write_fn_c = write_intercept_fn;
}
intercept->extent_fn_f77 = extent_fn_f77;
intercept->extra_state_f77 = extra_state_f77;
/* Now that the intercept data has been setup, call the C function
with the setup intercept routines and the intercept-specific
data/extra state. */
c_ierr = MPI_Register_datarep(c_datarep,
read_fn_c, write_fn_c,
extent_intercept_fn,
intercept);
if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);
free(c_datarep);
}
/*
* C->Fortran intercept for the read conversion.
*/
static int read_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
void *filebuf, MPI_Offset position,
void *extra_state)
{
MPI_Fint ierr, count_f77 = OMPI_FINT_2_INT(count_c);
MPI_Fint type_f77 = MPI_Type_c2f(type_c);
intercept_extra_state_t *intercept_data =
(intercept_extra_state_t*) extra_state;
intercept_data->read_fn_f77((char *) userbuf, &type_f77, &count_f77, (char *) filebuf,
&position, intercept_data->extra_state_f77,
&ierr);
return OMPI_FINT_2_INT(ierr);
}
/*
* C->Fortran intercept for the write conversion.
*/
static int write_intercept_fn(void *userbuf, MPI_Datatype type_c, int count_c,
void *filebuf, MPI_Offset position,
void *extra_state)
{
MPI_Fint ierr, count_f77 = OMPI_FINT_2_INT(count_c);
MPI_Fint type_f77 = MPI_Type_c2f(type_c);
intercept_extra_state_t *intercept_data =
(intercept_extra_state_t*) extra_state;
intercept_data->write_fn_f77((char *) userbuf, &type_f77, &count_f77, (char *) filebuf,
&position, intercept_data->extra_state_f77,
&ierr);
return OMPI_FINT_2_INT(ierr);
}
/*
* C->Fortran intercept for the extent calculation.
*/
static int extent_intercept_fn(MPI_Datatype type_c, MPI_Aint *file_extent_f77,
void *extra_state)
{
MPI_Fint ierr, type_f77 = MPI_Type_c2f(type_c);
intercept_extra_state_t *intercept_data =
(intercept_extra_state_t*) extra_state;
intercept_data->extent_fn_f77(&type_f77, file_extent_f77,
intercept_data->extra_state_f77, &ierr);
return OMPI_FINT_2_INT(ierr);
}