|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2011 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 "utlist.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* -- Begin Profiling Symbol Block for routine MPI_T_pvar_handle_alloc */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_T_pvar_handle_alloc = PMPI_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_T_pvar_handle_alloc MPI_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_T_pvar_handle_alloc as PMPI_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index, void *obj_handle,
|
|
Packit Service |
c5cf8c |
MPI_T_pvar_handle * handle, int *count)
|
|
Packit Service |
c5cf8c |
__attribute__ ((weak, alias("PMPI_T_pvar_handle_alloc")));
|
|
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_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
#define MPI_T_pvar_handle_alloc PMPI_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Define storage for the ALL_HANDLES constant */
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_handle_t MPIR_T_pvar_all_handles_obj = {
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
MPIR_T_PVAR_HANDLE, /* pvar handle tag for error checking */
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
0
|
|
Packit Service |
c5cf8c |
};
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_handle_t *const MPI_T_PVAR_ALL_HANDLES = &MPIR_T_pvar_all_handles_obj;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* any non-MPI functions go here, especially non-static ones */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPIR_T_pvar_handle_alloc_impl
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
int MPIR_T_pvar_handle_alloc_impl(MPI_T_pvar_session session, int pvar_index,
|
|
Packit Service |
c5cf8c |
void *obj_handle, MPI_T_pvar_handle * handle, int *count)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
int cnt, extra, bytes;
|
|
Packit Service |
c5cf8c |
int is_sum, is_watermark;
|
|
Packit Service |
c5cf8c |
const pvar_table_entry_t *info;
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_handle_t *hnd;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_CHKPMEM_DECL(1);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
info = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (info->get_count == NULL) {
|
|
Packit Service |
c5cf8c |
cnt = info->count;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
info->get_count(info->addr, obj_handle, &cnt);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
bytes = MPIR_Datatype_get_basic_size(info->datatype);
|
|
Packit Service |
c5cf8c |
is_sum = FALSE;
|
|
Packit Service |
c5cf8c |
is_watermark = FALSE;
|
|
Packit Service |
c5cf8c |
extra = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (info->varclass == MPI_T_PVAR_CLASS_COUNTER ||
|
|
Packit Service |
c5cf8c |
info->varclass == MPI_T_PVAR_CLASS_AGGREGATE || info->varclass == MPI_T_PVAR_CLASS_TIMER) {
|
|
Packit Service |
c5cf8c |
/* Extra memory for accum, offset, current */
|
|
Packit Service |
c5cf8c |
is_sum = TRUE;
|
|
Packit Service |
c5cf8c |
extra = bytes * cnt * 3;
|
|
Packit Service |
c5cf8c |
} else if (info->varclass == MPI_T_PVAR_CLASS_HIGHWATERMARK ||
|
|
Packit Service |
c5cf8c |
info->varclass == MPI_T_PVAR_CLASS_LOWWATERMARK) {
|
|
Packit Service |
c5cf8c |
is_watermark = TRUE;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Allocate memory and bzero it */
|
|
Packit Service |
c5cf8c |
MPIR_CHKPMEM_CALLOC(hnd, MPIR_T_pvar_handle_t *, sizeof(*hnd) + extra,
|
|
Packit Service |
c5cf8c |
mpi_errno, "performance variable handle", MPL_MEM_MPIT);
|
|
Packit Service |
c5cf8c |
#ifdef HAVE_ERROR_CHECKING
|
|
Packit Service |
c5cf8c |
hnd->kind = MPIR_T_PVAR_HANDLE;
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Setup the common fields */
|
|
Packit Service |
c5cf8c |
if (is_sum)
|
|
Packit Service |
c5cf8c |
hnd->flags |= MPIR_T_PVAR_FLAG_SUM;
|
|
Packit Service |
c5cf8c |
else if (is_watermark)
|
|
Packit Service |
c5cf8c |
hnd->flags |= MPIR_T_PVAR_FLAG_WATERMARK;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
hnd->addr = info->addr;
|
|
Packit Service |
c5cf8c |
hnd->datatype = info->datatype;
|
|
Packit Service |
c5cf8c |
hnd->count = cnt;
|
|
Packit Service |
c5cf8c |
hnd->varclass = info->varclass;
|
|
Packit Service |
c5cf8c |
hnd->flags = info->flags;
|
|
Packit Service |
c5cf8c |
hnd->session = session;
|
|
Packit Service |
c5cf8c |
hnd->info = info;
|
|
Packit Service |
c5cf8c |
hnd->obj_handle = obj_handle;
|
|
Packit Service |
c5cf8c |
hnd->get_value = info->get_value;
|
|
Packit Service |
c5cf8c |
hnd->bytes = bytes;
|
|
Packit Service |
c5cf8c |
hnd->count = cnt;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Init pointers to cache buffers for a SUM */
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_sum(hnd)) {
|
|
Packit Service |
c5cf8c |
hnd->accum = (char *) (hnd) + sizeof(*hnd);
|
|
Packit Service |
c5cf8c |
hnd->offset = (char *) (hnd) + sizeof(*hnd) + bytes * cnt;
|
|
Packit Service |
c5cf8c |
hnd->current = (char *) (hnd) + sizeof(*hnd) + bytes * cnt * 2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_continuous(hnd))
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_set_started(hnd);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Set starting value of a continuous SUM */
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_continuous(hnd) && MPIR_T_pvar_is_sum(hnd)) {
|
|
Packit Service |
c5cf8c |
/* Cache current value of a SUM in offset.
|
|
Packit Service |
c5cf8c |
* accum is zero since we called CALLOC before.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
if (hnd->get_value == NULL)
|
|
Packit Service |
c5cf8c |
MPIR_Memcpy(hnd->offset, hnd->addr, bytes * cnt);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
hnd->get_value(hnd->addr, hnd->obj_handle, hnd->count, hnd->offset);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Link a WATERMARK handle to its pvar & set starting value if continuous */
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_watermark(hnd)) {
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_watermark_t *mark = (MPIR_T_pvar_watermark_t *) hnd->addr;
|
|
Packit Service |
c5cf8c |
if (!mark->first_used) {
|
|
Packit Service |
c5cf8c |
/* Use the special handle slot for optimization if available */
|
|
Packit Service |
c5cf8c |
mark->first_used = TRUE;
|
|
Packit Service |
c5cf8c |
MPIR_T_pvar_set_first(hnd);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Set starting value */
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_continuous(hnd)) {
|
|
Packit Service |
c5cf8c |
mark->first_started = TRUE;
|
|
Packit Service |
c5cf8c |
mark->watermark = mark->current;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
mark->first_started = FALSE;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
/* If the special handle slot is unavailable, link it to hlist */
|
|
Packit Service |
c5cf8c |
if (mark->hlist == NULL) {
|
|
Packit Service |
c5cf8c |
hnd->prev2 = hnd;
|
|
Packit Service |
c5cf8c |
mark->hlist = hnd;
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
hnd->prev2 = hnd;
|
|
Packit Service |
c5cf8c |
hnd->next2 = mark->hlist;
|
|
Packit Service |
c5cf8c |
mark->hlist->prev2 = hnd;
|
|
Packit Service |
c5cf8c |
mark->hlist = hnd;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Set starting value */
|
|
Packit Service |
c5cf8c |
if (MPIR_T_pvar_is_continuous(hnd))
|
|
Packit Service |
c5cf8c |
hnd->watermark = mark->current;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Link the handle in its session and return it */
|
|
Packit Service |
c5cf8c |
DL_APPEND(session->hlist, hnd);
|
|
Packit Service |
c5cf8c |
*handle = hnd;
|
|
Packit Service |
c5cf8c |
*count = cnt;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_CHKPMEM_COMMIT();
|
|
Packit Service |
c5cf8c |
fn_exit:
|
|
Packit Service |
c5cf8c |
return mpi_errno;
|
|
Packit Service |
c5cf8c |
fn_fail:
|
|
Packit Service |
c5cf8c |
MPIR_CHKPMEM_REAP();
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif /* MPICH_MPI_FROM_PMPI */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_T_pvar_handle_alloc
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPI_T_pvar_handle_alloc - Allocate a handle for a performance variable
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ session - identifier of performance experiment session (handle)
|
|
Packit Service |
c5cf8c |
. pvar_index - index of performance variable for which handle is to be allocated (integer)
|
|
Packit Service |
c5cf8c |
- obj_handle - reference to a handle of the MPI object to which this variable is supposed to be bound (pointer)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Output Parameters:
|
|
Packit Service |
c5cf8c |
+ handle - allocated handle (handle)
|
|
Packit Service |
c5cf8c |
- count - number of elements used to represent this variable (integer)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N ThreadSafe
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.N Errors
|
|
Packit Service |
c5cf8c |
.N MPI_SUCCESS
|
|
Packit Service |
c5cf8c |
.N MPI_T_ERR_NOT_INITIALIZED
|
|
Packit Service |
c5cf8c |
.N MPI_T_ERR_INVALID_SESSION
|
|
Packit Service |
c5cf8c |
.N MPI_T_ERR_INVALID_INDEX
|
|
Packit Service |
c5cf8c |
.N MPI_T_ERR_OUT_OF_HANDLES
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_T_pvar_handle_alloc(MPI_T_pvar_session session, int pvar_index,
|
|
Packit Service |
c5cf8c |
void *obj_handle, MPI_T_pvar_handle * handle, int *count)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
pvar_table_entry_t *entry;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_T_PVAR_HANDLE_ALLOC);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_MPIT_INITIALIZED(mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_T_THREAD_CS_ENTER();
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_T_PVAR_HANDLE_ALLOC);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate parameters */
|
|
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_PVAR_SESSION(session, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_PVAR_INDEX(pvar_index, mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(count, "count", mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(handle, "handle", mpi_errno);
|
|
Packit Service |
c5cf8c |
/* Do not test obj_handle since it may be NULL when no binding */
|
|
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 |
entry = (pvar_table_entry_t *) utarray_eltptr(pvar_table, pvar_index);
|
|
Packit Service |
c5cf8c |
if (!entry->active) {
|
|
Packit Service |
c5cf8c |
mpi_errno = MPI_T_ERR_INVALID_INDEX;
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_T_pvar_handle_alloc_impl(session, pvar_index, obj_handle, handle, count);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
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_T_PVAR_HANDLE_ALLOC);
|
|
Packit Service |
c5cf8c |
MPIR_T_THREAD_CS_EXIT();
|
|
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_t_pvar_handle_alloc",
|
|
Packit Service |
c5cf8c |
"**mpi_t_pvar_handle_alloc %p %d %p %p %p", session, pvar_index,
|
|
Packit Service |
c5cf8c |
obj_handle, handle, count);
|
|
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 |
}
|