Blame src/binding/fortran/use_mpi/create_f90_int.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*  
Packit 0848f5
 *  (C) 2004 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "create_f90_util.h"
Packit 0848f5
Packit 0848f5
#include "mpiimpl.h"
Packit 0848f5
#ifdef HAVE_FC_TYPE_ROUTINES
Packit 0848f5
#include "mpif90model.h"
Packit 0848f5
#else
Packit 0848f5
/* Assume only 4 byte integers available */
Packit 0848f5
#define MPIR_F90_INTEGER_MODEL_MAP { 9, 4, 4 },
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
/* -- Begin Profiling Symbol Block for routine MPI_Type_create_f90_integer */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_Type_create_f90_integer = PMPI_Type_create_f90_integer
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_Type_create_f90_integer  MPI_Type_create_f90_integer
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_Type_create_f90_integer as PMPI_Type_create_f90_integer
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_Type_create_f90_integer(int range, MPI_Datatype *newtype) __attribute__((weak,alias("PMPI_Type_create_f90_integer")));
Packit 0848f5
#endif
Packit 0848f5
/* -- End Profiling Symbol Block */
Packit 0848f5
Packit 0848f5
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit 0848f5
   the MPI routines.  You can use USE_WEAK_SYMBOLS to see if MPICH is
Packit 0848f5
   using weak symbols to implement the MPI routines. */
Packit 0848f5
#ifndef MPICH_MPI_FROM_PMPI
Packit 0848f5
#define MPI_Type_create_f90_integer PMPI_Type_create_f90_integer
Packit 0848f5
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
typedef struct intModel {
Packit 0848f5
    int range, kind, bytes; } intModel;
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_Type_create_f90_integer
Packit 0848f5
Packit 0848f5
/*@
Packit 0848f5
   MPI_Type_create_f90_integer - Return a predefined type that matches 
Packit 0848f5
   the specified range
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
.  range - Decimal range (number of digits) desired
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
.  newtype - A predefine MPI Datatype that matches the range.
Packit 0848f5
Packit 0848f5
   Notes:
Packit 0848f5
If there is no corresponding type for the specified range, the call is 
Packit 0848f5
erroneous.  This implementation sets 'newtype' to 'MPI_DATATYPE_NULL' and
Packit 0848f5
returns an error of class 'MPI_ERR_ARG'.
Packit 0848f5
Packit 0848f5
.N Fortran
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_ERR_ARG
Packit 0848f5
@*/
Packit 0848f5
int MPI_Type_create_f90_integer( int range, MPI_Datatype *newtype )
Packit 0848f5
{
Packit 0848f5
    static const char FCNAME[] = "MPI_Type_create_f90_integer";
Packit 0848f5
    int i, bytes;
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPI_Datatype basetype = MPI_DATATYPE_NULL;
Packit 0848f5
    static intModel f90_integer_map[] = { MPIR_F90_INTEGER_MODEL_MAP
Packit 0848f5
					  {0, 0, 0 } };
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);
Packit 0848f5
Packit 0848f5
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit 0848f5
Packit 0848f5
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit 0848f5
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);
Packit 0848f5
Packit 0848f5
    /* ... body of routine ...  */
Packit 0848f5
    for (i=0; f90_integer_map[i].range > 0; i++) {
Packit 0848f5
	if (f90_integer_map[i].range >= range) {
Packit 0848f5
	    /* Find the corresponding INTEGER type */
Packit 0848f5
	    bytes = f90_integer_map[i].bytes;
Packit 0848f5
	    switch (bytes) {
Packit 0848f5
	    case 1: basetype = MPI_INTEGER1; break;
Packit 0848f5
	    case 2: basetype = MPI_INTEGER2; break;
Packit 0848f5
	    case 4: basetype = MPI_INTEGER4; break;
Packit 0848f5
	    case 8: basetype = MPI_INTEGER8; break;
Packit 0848f5
	    default: break;
Packit 0848f5
	    }
Packit 0848f5
	    break;
Packit 0848f5
	}
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    if (basetype == MPI_DATATYPE_NULL) {
Packit 0848f5
	mpi_errno = MPIR_Err_create_code( MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
Packit 0848f5
					  "MPI_Type_create_f90_integer",
Packit 0848f5
					  __LINE__, MPI_ERR_OTHER,
Packit 0848f5
 					  "**f90typeintnone", 
Packit 0848f5
					  "**f90typeintnone %d", range );
Packit 0848f5
    }
Packit 0848f5
    else {
Packit 0848f5
	mpi_errno = MPIR_Create_unnamed_predefined( basetype, 
Packit 0848f5
			    MPI_COMBINER_F90_INTEGER, range, -1, newtype );
Packit 0848f5
    }
Packit 0848f5
    if (mpi_errno) goto fn_fail;
Packit 0848f5
Packit 0848f5
    /* ... end of body of routine ... */
Packit 0848f5
 fn_exit:
Packit 0848f5
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_TYPE_CREATE_F90_INTEGER);
Packit 0848f5
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit 0848f5
    return mpi_errno;
Packit 0848f5
 fn_fail:
Packit 0848f5
    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
	mpi_errno = MPIR_Err_create_code(
Packit 0848f5
	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_type_create_f90_int",
Packit 0848f5
	    "**mpi_type_create_f90_int %d", range );
Packit 0848f5
    }
Packit 0848f5
#   endif
Packit 0848f5
    mpi_errno = MPIR_Err_return_comm( 0, FCNAME, mpi_errno );
Packit 0848f5
    goto fn_exit;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
}