Blame src/mpi/datatype/type_get_name.c

Packit Service c5cf8c
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit Service c5cf8c
/*
Packit Service c5cf8c
 *
Packit Service c5cf8c
 *  (C) 2001 by Argonne National Laboratory.
Packit Service c5cf8c
 *      See COPYRIGHT in top-level directory.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#include "mpiimpl.h"
Packit Service c5cf8c
#include "datatype.h"
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPI_Type_get_name */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Type_get_name = PMPI_Type_get_name
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Type_get_name  MPI_Type_get_name
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Type_get_name as PMPI_Type_get_name
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Type_get_name(MPI_Datatype datatype, char *type_name, int *resultlen)
Packit Service c5cf8c
    __attribute__ ((weak, alias("PMPI_Type_get_name")));
Packit Service c5cf8c
#endif
Packit Service c5cf8c
/* -- End Profiling Symbol Block */
Packit Service c5cf8c
Packit Service c5cf8c
/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
Packit Service c5cf8c
   the MPI routines */
Packit Service c5cf8c
#ifndef MPICH_MPI_FROM_PMPI
Packit Service c5cf8c
#undef MPI_Type_get_name
Packit Service c5cf8c
#define MPI_Type_get_name PMPI_Type_get_name
Packit Service c5cf8c
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
/* This routine initializes all of the name fields in the predefined
Packit Service c5cf8c
   datatypes */
Packit Service c5cf8c
#ifndef MPICH_MPI_FROM_PMPI
Packit Service c5cf8c
/* Include these definitions only with the PMPI version */
Packit Service c5cf8c
typedef struct mpi_names_t {
Packit Service c5cf8c
    MPI_Datatype dtype;
Packit Service c5cf8c
    const char *name;
Packit Service c5cf8c
} mpi_names_t;
Packit Service c5cf8c
/* The MPI standard specifies that the names must be the MPI names,
Packit Service c5cf8c
   not the related language names (e.g., MPI_CHAR, not char) */
Packit Service c5cf8c
#define type_name_entry(x_) { x_, #x_ }
Packit Service c5cf8c
static mpi_names_t mpi_names[] = {
Packit Service c5cf8c
    type_name_entry(MPI_CHAR),
Packit Service c5cf8c
    type_name_entry(MPI_SIGNED_CHAR),
Packit Service c5cf8c
    type_name_entry(MPI_UNSIGNED_CHAR),
Packit Service c5cf8c
    type_name_entry(MPI_BYTE),
Packit Service c5cf8c
    type_name_entry(MPI_WCHAR),
Packit Service c5cf8c
    type_name_entry(MPI_SHORT),
Packit Service c5cf8c
    type_name_entry(MPI_UNSIGNED_SHORT),
Packit Service c5cf8c
    type_name_entry(MPI_INT),
Packit Service c5cf8c
    type_name_entry(MPI_UNSIGNED),
Packit Service c5cf8c
    type_name_entry(MPI_LONG),
Packit Service c5cf8c
    type_name_entry(MPI_UNSIGNED_LONG),
Packit Service c5cf8c
    type_name_entry(MPI_FLOAT),
Packit Service c5cf8c
    type_name_entry(MPI_DOUBLE),
Packit Service c5cf8c
    type_name_entry(MPI_LONG_DOUBLE),
Packit Service c5cf8c
    /* LONG_LONG is a synonym of LONG_LONG_INT; we don't make it a separate
Packit Service c5cf8c
     * type */
Packit Service c5cf8c
/*    type_name_entry(MPI_LONG_LONG), */
Packit Service c5cf8c
    type_name_entry(MPI_LONG_LONG_INT),
Packit Service c5cf8c
    type_name_entry(MPI_UNSIGNED_LONG_LONG),
Packit Service c5cf8c
    type_name_entry(MPI_PACKED),
Packit Service c5cf8c
    type_name_entry(MPI_LB),
Packit Service c5cf8c
    type_name_entry(MPI_UB),
Packit Service c5cf8c
Packit Service c5cf8c
/* The maxloc/minloc types are not builtin because their size and
Packit Service c5cf8c
   extent may not be the same. */
Packit Service c5cf8c
/*
Packit Service c5cf8c
    type_name_entry(MPI_FLOAT_INT),
Packit Service c5cf8c
    type_name_entry(MPI_DOUBLE_INT),
Packit Service c5cf8c
    type_name_entry(MPI_LONG_INT),
Packit Service c5cf8c
    type_name_entry(MPI_SHORT_INT),
Packit Service c5cf8c
*/
Packit Service c5cf8c
    /* Fortran */
Packit Service c5cf8c
    type_name_entry(MPI_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_DOUBLE_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_LOGICAL),
Packit Service c5cf8c
    type_name_entry(MPI_REAL),
Packit Service c5cf8c
    type_name_entry(MPI_DOUBLE_PRECISION),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER),
Packit Service c5cf8c
    type_name_entry(MPI_2INTEGER),
Packit Service c5cf8c
#ifdef MPICH_DEFINE_2COMPLEX
Packit Service c5cf8c
    type_name_entry(MPI_2COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_2DOUBLE_COMPLEX),
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    type_name_entry(MPI_2REAL),
Packit Service c5cf8c
    type_name_entry(MPI_2DOUBLE_PRECISION),
Packit Service c5cf8c
    type_name_entry(MPI_CHARACTER),
Packit Service c5cf8c
    /* Size-specific types (C, Fortran, and C++) */
Packit Service c5cf8c
    type_name_entry(MPI_REAL4),
Packit Service c5cf8c
    type_name_entry(MPI_REAL8),
Packit Service c5cf8c
    type_name_entry(MPI_REAL16),
Packit Service c5cf8c
    type_name_entry(MPI_COMPLEX8),
Packit Service c5cf8c
    type_name_entry(MPI_COMPLEX16),
Packit Service c5cf8c
    type_name_entry(MPI_COMPLEX32),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER1),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER2),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER4),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER8),
Packit Service c5cf8c
    type_name_entry(MPI_INTEGER16),
Packit Service c5cf8c
Packit Service c5cf8c
    /* C99 types */
Packit Service c5cf8c
    type_name_entry(MPI_INT8_T),
Packit Service c5cf8c
    type_name_entry(MPI_INT16_T),
Packit Service c5cf8c
    type_name_entry(MPI_INT32_T),
Packit Service c5cf8c
    type_name_entry(MPI_INT64_T),
Packit Service c5cf8c
    type_name_entry(MPI_UINT8_T),
Packit Service c5cf8c
    type_name_entry(MPI_UINT16_T),
Packit Service c5cf8c
    type_name_entry(MPI_UINT32_T),
Packit Service c5cf8c
    type_name_entry(MPI_UINT64_T),
Packit Service c5cf8c
    type_name_entry(MPI_C_BOOL),
Packit Service c5cf8c
    /* C_FLOAT_COMPLEX is a synonym of C_COMPLEX; we don't make it a separate
Packit Service c5cf8c
     * type */
Packit Service c5cf8c
/*    type_name_entry(MPI_C_FLOAT_COMPLEX), */
Packit Service c5cf8c
    type_name_entry(MPI_C_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_C_DOUBLE_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_C_LONG_DOUBLE_COMPLEX),
Packit Service c5cf8c
Packit Service c5cf8c
    /* C++ types */
Packit Service c5cf8c
    type_name_entry(MPI_CXX_BOOL),
Packit Service c5cf8c
    type_name_entry(MPI_CXX_FLOAT_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_CXX_DOUBLE_COMPLEX),
Packit Service c5cf8c
    type_name_entry(MPI_CXX_LONG_DOUBLE_COMPLEX),
Packit Service c5cf8c
Packit Service c5cf8c
    /* address/offset types */
Packit Service c5cf8c
    type_name_entry(MPI_AINT),
Packit Service c5cf8c
    type_name_entry(MPI_OFFSET),
Packit Service c5cf8c
    type_name_entry(MPI_COUNT),
Packit Service c5cf8c
Packit Service c5cf8c
    {0, (char *) 0},    /* Sentinel used to indicate the last element */
Packit Service c5cf8c
};
Packit Service c5cf8c
Packit Service c5cf8c
static mpi_names_t mpi_maxloc_names[] = {
Packit Service c5cf8c
    type_name_entry(MPI_FLOAT_INT),
Packit Service c5cf8c
    type_name_entry(MPI_DOUBLE_INT),
Packit Service c5cf8c
    type_name_entry(MPI_LONG_INT),
Packit Service c5cf8c
    type_name_entry(MPI_SHORT_INT),
Packit Service c5cf8c
    type_name_entry(MPI_2INT),
Packit Service c5cf8c
    type_name_entry(MPI_LONG_DOUBLE_INT),
Packit Service c5cf8c
    {0, (char *) 0},    /* Sentinel used to indicate the last element */
Packit Service c5cf8c
};
Packit Service c5cf8c
Packit Service c5cf8c
#undef type_name_entry
Packit Service c5cf8c
/* This routine is also needed by type_set_name */
Packit Service c5cf8c
Packit Service c5cf8c
#undef  FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Datatype_init_names
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Datatype_init_names(void)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    int i;
Packit Service c5cf8c
    MPIR_Datatype *datatype_ptr = NULL;
Packit Service c5cf8c
    static volatile int needsInit = 1;
Packit Service c5cf8c
Packit Service c5cf8c
    MPID_THREAD_CS_ENTER(POBJ, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    if (needsInit) {
Packit Service c5cf8c
        /* Make sure that the basics have datatype structures allocated
Packit Service c5cf8c
         * and filled in for them.  They are just integers prior to this
Packit Service c5cf8c
         * call.
Packit Service c5cf8c
         */
Packit Service c5cf8c
        mpi_errno = MPIR_Datatype_builtin_fillin();
Packit Service c5cf8c
        if (mpi_errno != MPI_SUCCESS) {
Packit Service c5cf8c
            MPIR_ERR_POPFATAL(mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
Packit Service c5cf8c
        /* For each predefined type, ensure that there is a corresponding
Packit Service c5cf8c
         * object and that the object's name is set */
Packit Service c5cf8c
        for (i = 0; mpi_names[i].name != 0; i++) {
Packit Service c5cf8c
            /* The size-specific types may be DATATYPE_NULL, as might be those
Packit Service c5cf8c
             * based on 'long long' and 'long double' if those types were
Packit Service c5cf8c
             * disabled at configure time. */
Packit Service c5cf8c
            if (mpi_names[i].dtype == MPI_DATATYPE_NULL)
Packit Service c5cf8c
                continue;
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_Datatype_get_ptr(mpi_names[i].dtype, datatype_ptr);
Packit Service c5cf8c
Packit Service c5cf8c
            if (datatype_ptr < MPIR_Datatype_builtin ||
Packit Service c5cf8c
                datatype_ptr > MPIR_Datatype_builtin + MPIR_DATATYPE_N_BUILTIN) {
Packit Service c5cf8c
                MPIR_ERR_SETFATALANDJUMP1(mpi_errno, MPI_ERR_INTERN,
Packit Service c5cf8c
                                          "**typeinitbadmem", "**typeinitbadmem %d", i);
Packit Service c5cf8c
            }
Packit Service c5cf8c
            if (!datatype_ptr) {
Packit Service c5cf8c
                MPIR_ERR_SETFATALANDJUMP1(mpi_errno, MPI_ERR_INTERN,
Packit Service c5cf8c
                                          "**typeinitfail", "**typeinitfail %d", i - 1);
Packit Service c5cf8c
            }
Packit Service c5cf8c
Packit Service c5cf8c
            MPL_DBG_MSG_FMT(MPIR_DBG_DATATYPE, VERBOSE, (MPL_DBG_FDEST,
Packit Service c5cf8c
                                                         "mpi_names[%d].name = %p", i,
Packit Service c5cf8c
                                                         mpi_names[i].name));
Packit Service c5cf8c
Packit Service c5cf8c
            MPL_strncpy(datatype_ptr->name, mpi_names[i].name, MPI_MAX_OBJECT_NAME);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        /* Handle the minloc/maxloc types */
Packit Service c5cf8c
        for (i = 0; mpi_maxloc_names[i].name != 0; i++) {
Packit Service c5cf8c
            /* types based on 'long long' and 'long double' may be disabled at
Packit Service c5cf8c
             * configure time, and their values set to MPI_DATATYPE_NULL.  skip
Packit Service c5cf8c
             * those types. */
Packit Service c5cf8c
            if (mpi_maxloc_names[i].dtype == MPI_DATATYPE_NULL)
Packit Service c5cf8c
                continue;
Packit Service c5cf8c
Packit Service c5cf8c
            MPIR_Datatype_get_ptr(mpi_maxloc_names[i].dtype, datatype_ptr);
Packit Service c5cf8c
            if (!datatype_ptr) {
Packit Service c5cf8c
                MPIR_ERR_SETFATALANDJUMP(mpi_errno, MPI_ERR_INTERN, "**typeinitminmaxloc");
Packit Service c5cf8c
            }
Packit Service c5cf8c
            MPL_strncpy(datatype_ptr->name, mpi_maxloc_names[i].name, MPI_MAX_OBJECT_NAME);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        needsInit = 0;
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    /* empty statement */ ;
Packit Service c5cf8c
    MPID_THREAD_CS_EXIT(POBJ, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
}
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Type_get_name
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
   MPI_Type_get_name - Get the print name for a datatype
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
. datatype - datatype whose name is to be returned (handle)
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
+ type_name - the name previously stored on the datatype, or a empty string
Packit Service c5cf8c
  if no such name exists (string)
Packit Service c5cf8c
- resultlen - length of returned name (integer)
Packit Service c5cf8c
Packit Service c5cf8c
.N ThreadSafeNoUpdate
Packit Service c5cf8c
Packit Service c5cf8c
.N NULL
Packit Service c5cf8c
Packit Service c5cf8c
.N Fortran
Packit Service c5cf8c
Packit Service c5cf8c
.N Errors
Packit Service c5cf8c
.N MPI_SUCCESS
Packit Service c5cf8c
.N MPI_ERR_TYPE
Packit Service c5cf8c
.N MPI_ERR_ARG
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Type_get_name(MPI_Datatype datatype, char *type_name, int *resultlen)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_Datatype *datatype_ptr = NULL;
Packit Service c5cf8c
    static int setup = 0;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_TYPE_GET_NAME);
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_TYPE_GET_NAME);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters, especially handles needing to be converted */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
    /* Note that MPI_DATATYPE_NULL is invalid input to this routine;
Packit Service c5cf8c
     * it must not return a string for MPI_DATATYPE_NULL.  Instead,
Packit Service c5cf8c
     * it must return an error indicating an invalid datatype argument */
Packit Service c5cf8c
Packit Service c5cf8c
    /* Convert MPI object handles to object pointers */
Packit Service c5cf8c
    MPIR_Datatype_get_ptr(datatype, datatype_ptr);
Packit Service c5cf8c
Packit Service c5cf8c
    /* Validate parameters and objects (post conversion) */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        MPID_BEGIN_ERROR_CHECKS;
Packit Service c5cf8c
        {
Packit Service c5cf8c
            /* Validate datatype_ptr */
Packit Service c5cf8c
            MPIR_Datatype_valid_ptr(datatype_ptr, mpi_errno);
Packit Service c5cf8c
            if (mpi_errno)
Packit Service c5cf8c
                goto fn_fail;
Packit Service c5cf8c
            /* If datatype_ptr is not valid, it will be reset to null */
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNULL(type_name, "type_name", mpi_errno);
Packit Service c5cf8c
            MPIR_ERRTEST_ARGNULL(resultlen, "resultlen", mpi_errno);
Packit Service c5cf8c
        }
Packit Service c5cf8c
        MPID_END_ERROR_CHECKS;
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif /* HAVE_ERROR_CHECKING */
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... body of routine ...  */
Packit Service c5cf8c
Packit Service c5cf8c
    /* If this is the first call, initialize all of the predefined names */
Packit Service c5cf8c
    if (!setup) {
Packit Service c5cf8c
        mpi_errno = MPIR_Datatype_init_names();
Packit Service c5cf8c
        if (mpi_errno != MPI_SUCCESS)
Packit Service c5cf8c
            goto fn_fail;
Packit Service c5cf8c
        setup = 1;
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* Include the null in MPI_MAX_OBJECT_NAME */
Packit Service c5cf8c
    MPL_strncpy(type_name, datatype_ptr->name, MPI_MAX_OBJECT_NAME);
Packit Service c5cf8c
    *resultlen = (int) strlen(type_name);
Packit Service c5cf8c
Packit Service c5cf8c
    /* ... end of body of routine ... */
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_TYPE_GET_NAME);
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
    /* --BEGIN ERROR HANDLING-- */
Packit Service c5cf8c
#ifdef HAVE_ERROR_CHECKING
Packit Service c5cf8c
    {
Packit Service c5cf8c
        mpi_errno =
Packit Service c5cf8c
            MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER,
Packit Service c5cf8c
                                 "**mpi_type_get_name", "**mpi_type_get_name %D %p %p", datatype,
Packit Service c5cf8c
                                 type_name, resultlen);
Packit Service c5cf8c
    }
Packit Service c5cf8c
#endif
Packit Service c5cf8c
    mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
    /* --END ERROR HANDLING-- */
Packit Service c5cf8c
}