|
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 |
|
|
Packit Service |
c5cf8c |
/* -- Begin Profiling Symbol Block for routine MPI_Fetch_and_op */
|
|
Packit Service |
c5cf8c |
#if defined(HAVE_PRAGMA_WEAK)
|
|
Packit Service |
c5cf8c |
#pragma weak MPI_Fetch_and_op = PMPI_Fetch_and_op
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
|
|
Packit Service |
c5cf8c |
#pragma _HP_SECONDARY_DEF PMPI_Fetch_and_op MPI_Fetch_and_op
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_PRAGMA_CRI_DUP)
|
|
Packit Service |
c5cf8c |
#pragma _CRI duplicate MPI_Fetch_and_op as PMPI_Fetch_and_op
|
|
Packit Service |
c5cf8c |
#elif defined(HAVE_WEAK_ATTRIBUTE)
|
|
Packit Service |
c5cf8c |
int MPI_Fetch_and_op(const void *origin_addr, void *result_addr,
|
|
Packit Service |
c5cf8c |
MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
|
|
Packit Service |
c5cf8c |
MPI_Op op, MPI_Win win)
|
|
Packit Service |
c5cf8c |
__attribute__ ((weak, alias("PMPI_Fetch_and_op")));
|
|
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_Fetch_and_op
|
|
Packit Service |
c5cf8c |
#define MPI_Fetch_and_op PMPI_Fetch_and_op
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#undef FUNCNAME
|
|
Packit Service |
c5cf8c |
#define FUNCNAME MPI_Fetch_and_op
|
|
Packit Service |
c5cf8c |
#undef FCNAME
|
|
Packit Service |
c5cf8c |
#define FCNAME MPL_QUOTE(FUNCNAME)
|
|
Packit Service |
c5cf8c |
/*@
|
|
Packit Service |
c5cf8c |
MPI_Fetch_and_op - Perform one-sided read-modify-write.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Accumulate one element of type datatype from the origin buffer (origin_addr) to
|
|
Packit Service |
c5cf8c |
the buffer at offset target_disp, in the target window specified by target_rank
|
|
Packit Service |
c5cf8c |
and win, using the operation op and return in the result buffer result_addr the
|
|
Packit Service |
c5cf8c |
content of the target buffer before the accumulation.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Input Parameters:
|
|
Packit Service |
c5cf8c |
+ origin_addr - initial address of buffer (choice)
|
|
Packit Service |
c5cf8c |
. result_addr - initial address of result buffer (choice)
|
|
Packit Service |
c5cf8c |
. datatype - datatype of the entry in origin, result, and target buffers (handle)
|
|
Packit Service |
c5cf8c |
. target_rank - rank of target (nonnegative integer)
|
|
Packit Service |
c5cf8c |
. target_disp - displacement from start of window to beginning of target buffer (non-negative integer)
|
|
Packit Service |
c5cf8c |
. op - reduce operation (handle)
|
|
Packit Service |
c5cf8c |
- win - window object (handle)
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
Notes:
|
|
Packit Service |
c5cf8c |
This operations is atomic with respect to other "accumulate" operations.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
The generic functionality of 'MPI_Get_accumulate' might limit the performance of
|
|
Packit Service |
c5cf8c |
fetch-and-increment or fetch-and-add calls that might be supported by special
|
|
Packit Service |
c5cf8c |
hardware operations. 'MPI_Fetch_and_op' thus allows for a fast implementation
|
|
Packit Service |
c5cf8c |
of a commonly used subset of the functionality of 'MPI_Get_accumulate'.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
The origin and result buffers (origin_addr and result_addr) must be disjoint.
|
|
Packit Service |
c5cf8c |
Any of the predefined operations for 'MPI_Reduce', as well as 'MPI_NO_OP' or
|
|
Packit Service |
c5cf8c |
'MPI_REPLACE', can be specified as op; user-defined functions cannot be used. The
|
|
Packit Service |
c5cf8c |
datatype argument must be a predefined datatype.
|
|
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_ARG
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_COUNT
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_OP
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_RANK
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_TYPE
|
|
Packit Service |
c5cf8c |
.N MPI_ERR_WIN
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
.seealso: MPI_Get_accumulate
|
|
Packit Service |
c5cf8c |
@*/
|
|
Packit Service |
c5cf8c |
int MPI_Fetch_and_op(const void *origin_addr, void *result_addr,
|
|
Packit Service |
c5cf8c |
MPI_Datatype datatype, int target_rank, MPI_Aint target_disp,
|
|
Packit Service |
c5cf8c |
MPI_Op op, MPI_Win win)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int mpi_errno = MPI_SUCCESS;
|
|
Packit Service |
c5cf8c |
MPIR_Win *win_ptr = NULL;
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_FETCH_AND_OP);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_INITIALIZED_ORDIE();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
Packit Service |
c5cf8c |
MPIR_FUNC_TERSE_RMA_ENTER(MPID_STATE_MPI_FETCH_AND_OP);
|
|
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_WIN(win, 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 |
/* Convert MPI object handles to object pointers */
|
|
Packit Service |
c5cf8c |
MPIR_Win_get_ptr(win, win_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 |
MPIR_Comm *comm_ptr;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Validate win_ptr */
|
|
Packit Service |
c5cf8c |
MPIR_Win_valid_ptr(win_ptr, mpi_errno);
|
|
Packit Service |
c5cf8c |
if (mpi_errno)
|
|
Packit Service |
c5cf8c |
goto fn_fail;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (op != MPI_NO_OP) {
|
|
Packit Service |
c5cf8c |
/* NOTE: when op is MPI_NO_OP, origin_addr is allowed to be NULL.
|
|
Packit Service |
c5cf8c |
* In such case, MPI_Fetch_and_op equals to an atomic GET. */
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(origin_addr, "origin_addr", mpi_errno);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_ARGNULL(result_addr, "result_addr", mpi_errno);
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_DATATYPE(datatype, "datatype", mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!MPIR_DATATYPE_IS_PREDEFINED(datatype)) {
|
|
Packit Service |
c5cf8c |
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_TYPE, "**typenotpredefined");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (win_ptr->create_flavor != MPI_WIN_FLAVOR_DYNAMIC)
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_DISP(target_disp, mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
comm_ptr = win_ptr->comm_ptr;
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_SEND_RANK(comm_ptr, target_rank, mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPIR_ERRTEST_OP_GACC(op, mpi_errno);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (HANDLE_GET_KIND(op) != HANDLE_KIND_BUILTIN) {
|
|
Packit Service |
c5cf8c |
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_OP, "**opnotpredefined");
|
|
Packit Service |
c5cf8c |
}
|
|
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 |
mpi_errno = MPID_Fetch_and_op(origin_addr,
|
|
Packit Service |
c5cf8c |
result_addr, datatype, target_rank, target_disp, op, win_ptr);
|
|
Packit Service |
c5cf8c |
if (mpi_errno != MPI_SUCCESS)
|
|
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_RMA_EXIT(MPID_STATE_MPI_FETCH_AND_OP);
|
|
Packit Service |
c5cf8c |
MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
|
|
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_fetch_and_op", "**mpi_fetch_and_op %p %p %D %d %d %O %W",
|
|
Packit Service |
c5cf8c |
origin_addr, result_addr, datatype, target_rank, target_disp, op,
|
|
Packit Service |
c5cf8c |
win);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
mpi_errno = MPIR_Err_return_win(win_ptr, FCNAME, mpi_errno);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
/* --END ERROR HANDLING-- */
|
|
Packit Service |
c5cf8c |
}
|