Blame src/mpi/attr/comm_create_keyval.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
 * Portions of this code were written by Microsoft. Those portions are
Packit Service c5cf8c
 * Copyright (c) 2007 Microsoft Corporation. Microsoft grants
Packit Service c5cf8c
 * permission to use, reproduce, prepare derivative works, and to
Packit Service c5cf8c
 * redistribute to others. The code is licensed "as is." The User
Packit Service c5cf8c
 * bears the risk of using it. Microsoft gives no express warranties,
Packit Service c5cf8c
 * guarantees or conditions. To the extent permitted by law, Microsoft
Packit Service c5cf8c
 * excludes the implied warranties of merchantability, fitness for a
Packit Service c5cf8c
 * particular purpose and non-infringement.
Packit Service c5cf8c
 */
Packit Service c5cf8c
Packit Service c5cf8c
#include "mpiimpl.h"
Packit Service c5cf8c
#include "attr.h"
Packit Service c5cf8c
Packit Service c5cf8c
/* -- Begin Profiling Symbol Block for routine MPI_Comm_create_keyval */
Packit Service c5cf8c
#if defined(HAVE_PRAGMA_WEAK)
Packit Service c5cf8c
#pragma weak MPI_Comm_create_keyval = PMPI_Comm_create_keyval
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit Service c5cf8c
#pragma _HP_SECONDARY_DEF PMPI_Comm_create_keyval  MPI_Comm_create_keyval
Packit Service c5cf8c
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit Service c5cf8c
#pragma _CRI duplicate MPI_Comm_create_keyval as PMPI_Comm_create_keyval
Packit Service c5cf8c
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit Service c5cf8c
int MPI_Comm_create_keyval(MPI_Comm_copy_attr_function * comm_copy_attr_fn,
Packit Service c5cf8c
                           MPI_Comm_delete_attr_function * comm_delete_attr_fn, int *comm_keyval,
Packit Service c5cf8c
                           void *extra_state)
Packit Service c5cf8c
    __attribute__ ((weak, alias("PMPI_Comm_create_keyval")));
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_Comm_create_keyval
Packit Service c5cf8c
#define MPI_Comm_create_keyval PMPI_Comm_create_keyval
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPIR_Comm_create_keyval_impl
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
int MPIR_Comm_create_keyval_impl(MPI_Comm_copy_attr_function * comm_copy_attr_fn,
Packit Service c5cf8c
                                 MPI_Comm_delete_attr_function * comm_delete_attr_fn,
Packit Service c5cf8c
                                 int *comm_keyval, void *extra_state)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPII_Keyval *keyval_ptr;
Packit Service c5cf8c
Packit Service c5cf8c
    keyval_ptr = (MPII_Keyval *) MPIR_Handle_obj_alloc(&MPII_Keyval_mem);
Packit Service c5cf8c
    MPIR_ERR_CHKANDJUMP(!keyval_ptr, mpi_errno, MPI_ERR_OTHER, "**nomem");
Packit Service c5cf8c
Packit Service c5cf8c
    /* Initialize the attribute dup function */
Packit Service c5cf8c
    if (!MPIR_Process.attr_dup) {
Packit Service c5cf8c
        MPIR_Process.attr_dup = MPIR_Attr_dup_list;
Packit Service c5cf8c
        MPIR_Process.attr_free = MPIR_Attr_delete_list;
Packit Service c5cf8c
    }
Packit Service c5cf8c
Packit Service c5cf8c
    /* The handle encodes the keyval kind.  Modify it to have the correct
Packit Service c5cf8c
     * field */
Packit Service c5cf8c
    keyval_ptr->handle = (keyval_ptr->handle & ~(0x03c00000)) | (MPIR_COMM << 22);
Packit Service c5cf8c
    MPIR_Object_set_ref(keyval_ptr, 1);
Packit Service c5cf8c
    keyval_ptr->was_freed = 0;
Packit Service c5cf8c
    keyval_ptr->kind = MPIR_COMM;
Packit Service c5cf8c
    keyval_ptr->extra_state = extra_state;
Packit Service c5cf8c
    keyval_ptr->copyfn.user_function = comm_copy_attr_fn;
Packit Service c5cf8c
    keyval_ptr->copyfn.proxy = MPII_Attr_copy_c_proxy;
Packit Service c5cf8c
    keyval_ptr->delfn.user_function = comm_delete_attr_fn;
Packit Service c5cf8c
    keyval_ptr->delfn.proxy = MPII_Attr_delete_c_proxy;
Packit Service c5cf8c
Packit Service c5cf8c
    MPIR_OBJ_PUBLISH_HANDLE(*comm_keyval, keyval_ptr->handle);
Packit Service c5cf8c
Packit Service c5cf8c
  fn_exit:
Packit Service c5cf8c
    return mpi_errno;
Packit Service c5cf8c
  fn_fail:
Packit Service c5cf8c
Packit Service c5cf8c
    goto fn_exit;
Packit Service c5cf8c
}
Packit Service c5cf8c
Packit Service c5cf8c
#endif
Packit Service c5cf8c
Packit Service c5cf8c
#undef FUNCNAME
Packit Service c5cf8c
#define FUNCNAME MPI_Comm_create_keyval
Packit Service c5cf8c
#undef FCNAME
Packit Service c5cf8c
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit Service c5cf8c
/*@
Packit Service c5cf8c
   MPI_Comm_create_keyval - Create a new attribute key
Packit Service c5cf8c
Packit Service c5cf8c
Input Parameters:
Packit Service c5cf8c
+ comm_copy_attr_fn - Copy callback function for 'keyval'
Packit Service c5cf8c
. comm_delete_attr_fn - Delete callback function for 'keyval'
Packit Service c5cf8c
- extra_state - Extra state for callback functions
Packit Service c5cf8c
Packit Service c5cf8c
Output Parameters:
Packit Service c5cf8c
. comm_keyval - key value for future access (integer)
Packit Service c5cf8c
Packit Service c5cf8c
Notes:
Packit Service c5cf8c
Key values are global (available for any and all communicators).
Packit Service c5cf8c
Packit Service c5cf8c
Default copy and delete functions are available.  These are
Packit Service c5cf8c
+ MPI_COMM_NULL_COPY_FN   - empty copy function
Packit Service c5cf8c
. MPI_COMM_NULL_DELETE_FN - empty delete function
Packit Service c5cf8c
- MPI_COMM_DUP_FN         - simple dup function
Packit Service c5cf8c
Packit Service c5cf8c
There are subtle differences between C and Fortran that require that the
Packit Service c5cf8c
copy_fn be written in the same language from which 'MPI_Comm_create_keyval'
Packit Service c5cf8c
is called.
Packit Service c5cf8c
This should not be a problem for most users; only programmers using both
Packit Service c5cf8c
Fortran and C in the same program need to be sure that they follow this rule.
Packit Service c5cf8c
Packit Service c5cf8c
.N AttrErrReturn
Packit Service c5cf8c
Packit Service c5cf8c
.N ThreadSafe
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
Packit Service c5cf8c
.seealso MPI_Comm_free_keyval
Packit Service c5cf8c
@*/
Packit Service c5cf8c
int MPI_Comm_create_keyval(MPI_Comm_copy_attr_function * comm_copy_attr_fn,
Packit Service c5cf8c
                           MPI_Comm_delete_attr_function * comm_delete_attr_fn,
Packit Service c5cf8c
                           int *comm_keyval, void *extra_state)
Packit Service c5cf8c
{
Packit Service c5cf8c
    int mpi_errno = MPI_SUCCESS;
Packit Service c5cf8c
    MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_COMM_CREATE_KEYVAL);
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_ENTER(MPID_STATE_MPI_COMM_CREATE_KEYVAL);
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_ERRTEST_ARGNULL(comm_keyval, "comm_keyval", 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
    mpi_errno =
Packit Service c5cf8c
        MPIR_Comm_create_keyval_impl(comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval,
Packit Service c5cf8c
                                     extra_state);
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_COMM_CREATE_KEYVAL);
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_comm_create_keyval", "**mpi_comm_create_keyval %p %p %p %p",
Packit Service c5cf8c
                                 comm_copy_attr_fn, comm_delete_attr_fn, comm_keyval, extra_state);
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
}