Blame src/mpi_t/cvar_get_index.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *  (C) 2011 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpiimpl.h"
Packit 0848f5
Packit 0848f5
/* -- Begin Profiling Symbol Block for routine MPI_T_cvar_get_index */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_T_cvar_get_index = PMPI_T_cvar_get_index
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_T_cvar_get_index  MPI_T_cvar_get_index
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_T_cvar_get_index as PMPI_T_cvar_get_index
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_T_cvar_get_index(const char *name, int *cvar_index) __attribute__((weak,alias("PMPI_T_cvar_get_index")));
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 */
Packit 0848f5
#ifndef MPICH_MPI_FROM_PMPI
Packit 0848f5
#undef MPI_T_cvar_get_index
Packit 0848f5
#define MPI_T_cvar_get_index PMPI_T_cvar_get_index
Packit 0848f5
#endif /* MPICH_MPI_FROM_PMPI */
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_T_cvar_get_index
Packit 0848f5
#undef FCNAME
Packit 0848f5
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit 0848f5
/*@
Packit 0848f5
MPI_T_cvar_get_index - Get the index of a control variable
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
. name - name of the control variable (string)
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
. cvar_index - index of the control variable (integer)
Packit 0848f5
Packit 0848f5
.N ThreadSafe
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_T_ERR_INVALID_NAME
Packit 0848f5
.N MPI_T_ERR_NOT_INITIALIZED
Packit 0848f5
@*/
Packit 0848f5
int MPI_T_cvar_get_index(const char *name, int *cvar_index)
Packit 0848f5
{
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_GET_INDEX);
Packit 0848f5
    MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
Packit 0848f5
    MPIR_T_THREAD_CS_ENTER();
Packit 0848f5
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_T_CVAR_GET_INDEX);
Packit 0848f5
Packit 0848f5
    /* Validate parameters */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS
Packit 0848f5
        {
Packit 0848f5
            MPIR_ERRTEST_ARGNULL(name, "name", mpi_errno);
Packit 0848f5
            MPIR_ERRTEST_ARGNULL(cvar_index, "cvar_index", mpi_errno);
Packit 0848f5
        }
Packit 0848f5
        MPID_END_ERROR_CHECKS
Packit 0848f5
    }
Packit 0848f5
#   endif /* HAVE_ERROR_CHECKING */
Packit 0848f5
Packit 0848f5
    /* ... body of routine ...  */
Packit 0848f5
Packit 0848f5
    name2index_hash_t *hash_entry;
Packit 0848f5
Packit 0848f5
    /* Do hash lookup by the name */
Packit 0848f5
    HASH_FIND_STR(cvar_hash, name, hash_entry);
Packit 0848f5
    if (hash_entry != NULL) {
Packit 0848f5
        *cvar_index = hash_entry->idx;
Packit 0848f5
    } else {
Packit 0848f5
        mpi_errno = MPI_T_ERR_INVALID_NAME;
Packit 0848f5
        goto fn_fail;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* ... end of body of routine ... */
Packit 0848f5
Packit 0848f5
fn_exit:
Packit 0848f5
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_T_CVAR_GET_INDEX);
Packit 0848f5
    MPIR_T_THREAD_CS_EXIT();
Packit 0848f5
    return mpi_errno;
Packit 0848f5
Packit 0848f5
fn_fail:
Packit 0848f5
    goto fn_exit;
Packit 0848f5
}