Blame src/mpi_t/cvar_handle_alloc.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_handle_alloc */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_T_cvar_handle_alloc = PMPI_T_cvar_handle_alloc
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_T_cvar_handle_alloc  MPI_T_cvar_handle_alloc
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_T_cvar_handle_alloc as PMPI_T_cvar_handle_alloc
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle *handle,
Packit 0848f5
                            int *count) __attribute__((weak,alias("PMPI_T_cvar_handle_alloc")));
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_handle_alloc
Packit 0848f5
#define MPI_T_cvar_handle_alloc PMPI_T_cvar_handle_alloc
Packit 0848f5
Packit 0848f5
/* any non-MPI functions go here, especially non-static ones */
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPIR_T_cvar_handle_alloc_impl
Packit 0848f5
#undef FCNAME
Packit 0848f5
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit 0848f5
int MPIR_T_cvar_handle_alloc_impl(int cvar_index, void *obj_handle, MPI_T_cvar_handle *handle, int *count)
Packit 0848f5
{
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPIR_T_cvar_handle_t *hnd;
Packit 0848f5
Packit 0848f5
    MPIU_CHKPMEM_DECL(1);
Packit 0848f5
Packit 0848f5
    cvar_table_entry_t *cvar = (cvar_table_entry_t *) utarray_eltptr(cvar_table, cvar_index);
Packit 0848f5
Packit 0848f5
    /* Allocate handle memory */
Packit 0848f5
    MPIU_CHKPMEM_MALLOC(hnd, MPIR_T_cvar_handle_t*, sizeof(*hnd), mpi_errno, "control variable handle");
Packit 0848f5
#ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    hnd->kind = MPIR_T_CVAR_HANDLE;
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
    /* It is time to fix addr and count if they are unknown */
Packit 0848f5
    if (cvar->get_count != NULL)
Packit 0848f5
        cvar->get_count(obj_handle, count);
Packit 0848f5
    else
Packit 0848f5
        *count = cvar->count;
Packit 0848f5
Packit 0848f5
    hnd->count = *count;
Packit 0848f5
Packit 0848f5
    if (cvar->get_addr != NULL)
Packit 0848f5
        cvar->get_addr(obj_handle, &(hnd->addr));
Packit 0848f5
    else
Packit 0848f5
        hnd->addr = cvar->addr;
Packit 0848f5
Packit 0848f5
    /* Cache other fields */
Packit 0848f5
    hnd->datatype = cvar->datatype;
Packit 0848f5
    hnd->scope = cvar->scope;
Packit 0848f5
Packit 0848f5
    *handle = hnd;
Packit 0848f5
Packit 0848f5
    MPIU_CHKPMEM_COMMIT();
Packit 0848f5
fn_exit:
Packit 0848f5
    return mpi_errno;
Packit 0848f5
fn_fail:
Packit 0848f5
    MPIU_CHKPMEM_REAP();
Packit 0848f5
    goto fn_exit;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
#endif /* MPICH_MPI_FROM_PMPI */
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_T_cvar_handle_alloc
Packit 0848f5
#undef FCNAME
Packit 0848f5
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit 0848f5
/*@
Packit 0848f5
MPI_T_cvar_handle_alloc - Allocate a handle for a control variable
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
+ cvar_index - index of control variable for which handle is to be allocated (index)
Packit 0848f5
- obj_handle - reference to a handle of the MPI object to which this variable is supposed to be bound (pointer)
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
+ handle - allocated handle (handle)
Packit 0848f5
- count - number of elements used to represent this 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_NOT_INITIALIZED
Packit 0848f5
.N MPI_T_ERR_INVALID_INDEX
Packit 0848f5
.N MPI_T_ERR_INVALID_HANDLE
Packit 0848f5
.N MPI_T_ERR_OUT_OF_HANDLES
Packit 0848f5
@*/
Packit 0848f5
int MPI_T_cvar_handle_alloc(int cvar_index, void *obj_handle, MPI_T_cvar_handle *handle, int *count)
Packit 0848f5
{
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_T_CVAR_HANDLE_ALLOC);
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_HANDLE_ALLOC);
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_CVAR_INDEX(cvar_index, mpi_errno);
Packit 0848f5
            /* obj_handle is ignored if cvar has no binding, so no
Packit 0848f5
               TEST_ARGNULL for it */
Packit 0848f5
            MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
Packit 0848f5
            MPIR_ERRTEST_ARGNULL(count, "count", 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
    mpi_errno = MPIR_T_cvar_handle_alloc_impl(cvar_index, obj_handle, handle, count);
Packit 0848f5
    if (mpi_errno) MPIR_ERR_POP(mpi_errno);
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_HANDLE_ALLOC);
Packit 0848f5
    MPIR_T_THREAD_CS_EXIT();
Packit 0848f5
    return mpi_errno;
Packit 0848f5
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,
Packit 0848f5
            "**mpi_t_cvar_handle_alloc", "**mpi_t_cvar_handle_alloc %d %p %p %p", cvar_index, obj_handle, handle, count);
Packit 0848f5
    }
Packit 0848f5
#   endif
Packit 0848f5
    mpi_errno = MPIR_Err_return_comm(NULL, FCNAME, mpi_errno);
Packit 0848f5
    goto fn_exit;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
}