Blame src/mpi/attr/comm_delete_attr.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
#include "attr.h"
Packit 0848f5
Packit 0848f5
/* -- Begin Profiling Symbol Block for routine MPI_Comm_delete_attr */
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_Comm_delete_attr = PMPI_Comm_delete_attr
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_Comm_delete_attr  MPI_Comm_delete_attr
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_Comm_delete_attr as PMPI_Comm_delete_attr
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_Comm_delete_attr(MPI_Comm comm, int comm_keyval) __attribute__((weak,alias("PMPI_Comm_delete_attr")));
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_Comm_delete_attr
Packit 0848f5
#define MPI_Comm_delete_attr PMPI_Comm_delete_attr
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPIR_Comm_delete_attr_impl
Packit 0848f5
#undef FCNAME
Packit 0848f5
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit 0848f5
int MPIR_Comm_delete_attr_impl(MPID_Comm *comm_ptr, MPID_Keyval *keyval_ptr)
Packit 0848f5
{
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPID_Attribute *p, **old_p;
Packit 0848f5
         
Packit 0848f5
    /* Look for attribute.  They are ordered by keyval handle */
Packit 0848f5
Packit 0848f5
    old_p = &comm_ptr->attributes;
Packit 0848f5
    p     = comm_ptr->attributes;
Packit 0848f5
    while (p) {
Packit 0848f5
	if (p->keyval->handle == keyval_ptr->handle) {
Packit 0848f5
	    break;
Packit 0848f5
	}
Packit 0848f5
	old_p = &p->next;
Packit 0848f5
	p     = p->next;
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* We can't unlock yet, because we must not free the attribute until
Packit 0848f5
       we know whether the delete function has returned with a 0 status
Packit 0848f5
       code */
Packit 0848f5
Packit 0848f5
    if (p) {
Packit 0848f5
        int in_use;
Packit 0848f5
Packit 0848f5
        /* Run the delete function, if any, and then free the
Packit 0848f5
	   attribute storage.  Note that due to an ambiguity in the
Packit 0848f5
	   standard, if the usr function returns something other than
Packit 0848f5
	   MPI_SUCCESS, we should either return the user return code,
Packit 0848f5
	   or an mpich error code.  The precedent set by the Intel
Packit 0848f5
	   test suite says we should return the user return code.  So
Packit 0848f5
	   we must not ERR_POP here. */
Packit 0848f5
	mpi_errno = MPIR_Call_attr_delete( comm_ptr->handle, p );
Packit 0848f5
        if (mpi_errno) goto fn_fail;
Packit 0848f5
        
Packit 0848f5
        /* We found the attribute.  Remove it from the list */
Packit 0848f5
        *old_p = p->next;
Packit 0848f5
        /* Decrement the use of the keyval */
Packit 0848f5
        MPIR_Keyval_release_ref( p->keyval, &in_use);
Packit 0848f5
        if (!in_use) {
Packit 0848f5
            MPIU_Handle_obj_free( &MPID_Keyval_mem, p->keyval );
Packit 0848f5
        }
Packit 0848f5
        MPID_Attr_free(p);
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
 fn_exit:
Packit 0848f5
    return mpi_errno;
Packit 0848f5
 fn_fail:
Packit 0848f5
    goto fn_exit;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
#undef FUNCNAME
Packit 0848f5
#define FUNCNAME MPI_Comm_delete_attr
Packit 0848f5
#undef FCNAME
Packit 0848f5
#define FCNAME MPL_QUOTE(FUNCNAME)
Packit 0848f5
/*@
Packit 0848f5
   MPI_Comm_delete_attr - Deletes an attribute value associated with a key on 
Packit 0848f5
   a  communicator
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
+ comm - communicator to which attribute is attached (handle) 
Packit 0848f5
- comm_keyval - The key value of the deleted attribute (integer) 
Packit 0848f5
Packit 0848f5
.N ThreadSafe
Packit 0848f5
Packit 0848f5
.N Fortran
Packit 0848f5
Packit 0848f5
.N Errors
Packit 0848f5
.N MPI_SUCCESS
Packit 0848f5
.N MPI_ERR_COMM
Packit 0848f5
.N MPI_ERR_PERM_KEY
Packit 0848f5
Packit 0848f5
.seealso MPI_Comm_set_attr, MPI_Comm_create_keyval
Packit 0848f5
@*/
Packit 0848f5
int MPI_Comm_delete_attr(MPI_Comm comm, int comm_keyval)
Packit 0848f5
{
Packit 0848f5
    int mpi_errno = MPI_SUCCESS;
Packit 0848f5
    MPID_Comm *comm_ptr = NULL;
Packit 0848f5
    MPID_Keyval *keyval_ptr;
Packit 0848f5
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_COMM_DELETE_ATTR);
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_COMM_DELETE_ATTR);
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
	    MPIR_ERRTEST_KEYVAL(comm_keyval, MPID_COMM, "communicator", mpi_errno);
Packit 0848f5
	    MPIR_ERRTEST_KEYVAL_PERM(comm_keyval, mpi_errno);
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
    MPID_Keyval_get_ptr( comm_keyval, keyval_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
            /* Validate keyval_ptr */
Packit 0848f5
	    MPID_Keyval_valid_ptr( keyval_ptr, mpi_errno );
Packit 0848f5
            if (mpi_errno) goto fn_fail;
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_Comm_delete_attr_impl(comm_ptr, keyval_ptr);
Packit 0848f5
    if (mpi_errno) 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_COMM_DELETE_ATTR);
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_comm_delete_attr",
Packit 0848f5
	    "**mpi_comm_delete_attr %C %d", comm, comm_keyval);
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
}