Blame src/mpi/attr/attr_get.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2001 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_Attr_get */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_Attr_get = PMPI_Attr_get
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_Attr_get  MPI_Attr_get
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_Attr_get as PMPI_Attr_get
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_Attr_get(MPI_Comm comm, int keyval, void *attribute_val, int *flag) __attribute__((weak,alias("PMPI_Attr_get")));
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_Attr_get
Packit 0848f5
#define MPI_Attr_get PMPI_Attr_get
Packit 0848f5
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_Attr_get
Packit 0848f5
Packit 0848f5
/*@
Packit 0848f5
Packit 0848f5
MPI_Attr_get - Retrieves attribute value by key
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
+ comm - communicator to which attribute is attached (handle) 
Packit 0848f5
- keyval - key value (integer) 
Packit 0848f5
Packit 0848f5
Output Parameters:
Packit 0848f5
+ attribute_val - attribute value, unless 'flag' = false
Packit 0848f5
- flag -  true if an attribute value was extracted;  false if no attribute is
Packit 0848f5
  associated with the key 
Packit 0848f5
Packit 0848f5
Notes:
Packit 0848f5
    Attributes must be extracted from the same language as they were inserted  
Packit 0848f5
    in with 'MPI_ATTR_PUT'.  The notes for C and Fortran below explain why.
Packit 0848f5
Packit 0848f5
Notes for C:
Packit 0848f5
    Even though the 'attribute_val' argument is declared as 'void *', it is
Packit 0848f5
    really the address of a void pointer (i.e., a 'void **').  Using
Packit 0848f5
    a 'void *', however, is more in keeping with C idiom and allows the
Packit 0848f5
    pointer to be passed without additional casts.
Packit 0848f5
Packit 0848f5
Packit 0848f5
.N ThreadSafe
Packit 0848f5
Packit 0848f5
.N Deprecated
Packit 0848f5
   The replacement for this routine is 'MPI_Comm_get_attr'.
Packit 0848f5
Packit 0848f5
.N Fortran
Packit 0848f5
Packit 0848f5
    The 'attribute_val' in Fortran is a pointer to a Fortran integer, not
Packit 0848f5
    a pointer to a 'void *'.  
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_ERR_COMM
Packit 0848f5
.N MPI_ERR_KEYVAL
Packit 0848f5
Packit 0848f5
.seealso MPI_Attr_put, MPI_Keyval_create, MPI_Attr_delete, MPI_Comm_get_attr
Packit 0848f5
@*/
Packit 0848f5
int MPI_Attr_get(MPI_Comm comm, int keyval, void *attribute_val, int *flag)
Packit 0848f5
{
Packit 0848f5
    static const char FCNAME[] = "MPI_Attr_get";
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPID_Comm *comm_ptr = NULL;
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_ATTR_GET);
Packit 0848f5
Packit 0848f5
    MPIR_ERRTEST_INITIALIZED_ORDIE();
Packit 0848f5
    
Packit 0848f5
    MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
Packit 0848f5
    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_ATTR_GET);
Packit 0848f5
Packit 0848f5
    /* Validate parameters, especially handles needing to be converted */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS;
Packit 0848f5
        {
Packit 0848f5
	    MPIR_ERRTEST_COMM(comm, mpi_errno);
Packit 0848f5
#           ifdef NEEDS_POINTER_ALIGNMENT_ADJUST
Packit 0848f5
            /* A common user error is to pass the address of a 4-byte
Packit 0848f5
	       int when the address of a pointer (or an address-sized int)
Packit 0848f5
	       should have been used.  We can test for this specific
Packit 0848f5
	       case.  Note that this code assumes sizeof(MPIU_Pint) is 
Packit 0848f5
	       a power of 2. */
Packit 0848f5
            MPIR_ERR_CHKANDJUMP((MPIU_Pint)attribute_val & (sizeof(MPIU_Pint)-1),
Packit 0848f5
                                mpi_errno,MPI_ERR_ARG,"**attrnotptr");
Packit 0848f5
#           endif
Packit 0848f5
        }
Packit 0848f5
        MPID_END_ERROR_CHECKS;
Packit 0848f5
    }
Packit 0848f5
#   endif
Packit 0848f5
    
Packit 0848f5
    /* Convert MPI object handles to object pointers */
Packit 0848f5
    MPID_Comm_get_ptr( comm, comm_ptr );
Packit 0848f5
Packit 0848f5
    /* Validate parameters and objects (post conversion) */
Packit 0848f5
#   ifdef HAVE_ERROR_CHECKING
Packit 0848f5
    {
Packit 0848f5
        MPID_BEGIN_ERROR_CHECKS;
Packit 0848f5
        {
Packit 0848f5
            /* Validate comm_ptr */
Packit 0848f5
            MPID_Comm_valid_ptr( comm_ptr, mpi_errno, TRUE );
Packit 0848f5
	    /* If comm_ptr is not valid, it will be reset to null */
Packit 0848f5
	    MPIR_ERRTEST_ARGNULL(attribute_val, "attribute_val", mpi_errno);
Packit 0848f5
	    MPIR_ERRTEST_ARGNULL(flag, "flag", 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_CommGetAttr( comm, keyval, attribute_val, flag, MPIR_ATTR_PTR);
Packit 0848f5
    if (mpi_errno != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
Packit 0848f5
    /* ... end of body of routine ... */
Packit 0848f5
Packit 0848f5
  fn_exit:
Packit 0848f5
    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_ATTR_GET);
Packit 0848f5
    MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
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, "**mpi_attr_get",
Packit 0848f5
	    "**mpi_attr_get %C %d %p %p", comm, keyval, attribute_val, flag);
Packit 0848f5
    }
Packit 0848f5
#   endif
Packit 0848f5
    mpi_errno = MPIR_Err_return_comm( comm_ptr, FCNAME, mpi_errno );
Packit 0848f5
    goto fn_exit;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
}