-:    0:Source:/home/MPI/testing/mpich2/mpich2/src/mpi/attr/win_get_attr.c
        -:    0:Graph:win_get_attr.gcno
        -:    0:Data:win_get_attr.gcda
        -:    0:Runs:2039
        -:    0:Programs:429
        -:    1:/* -*- Mode: C; c-basic-offset:4 ; -*- */
        -:    2:/*
        -:    3: *
        -:    4: *  (C) 2001 by Argonne National Laboratory.
        -:    5: *      See COPYRIGHT in top-level directory.
        -:    6: */
        -:    7:
        -:    8:#include "mpiimpl.h"
        -:    9:
        -:   10:/* -- Begin Profiling Symbol Block for routine MPI_Win_get_attr */
        -:   11:#if defined(HAVE_PRAGMA_WEAK)
        -:   12:#pragma weak MPI_Win_get_attr = PMPI_Win_get_attr
        -:   13:#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
        -:   14:#pragma _HP_SECONDARY_DEF PMPI_Win_get_attr  MPI_Win_get_attr
        -:   15:#elif defined(HAVE_PRAGMA_CRI_DUP)
        -:   16:#pragma _CRI duplicate MPI_Win_get_attr as PMPI_Win_get_attr
        -:   17:#endif
        -:   18:/* -- End Profiling Symbol Block */
        -:   19:
        -:   20:/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
        -:   21:   the MPI routines */
        -:   22:#ifndef MPICH_MPI_FROM_PMPI
        -:   23:#undef MPI_Win_get_attr
        -:   24:#define MPI_Win_get_attr PMPI_Win_get_attr
        -:   25:
        -:   26:#undef FUNCNAME
        -:   27:#define FUNCNAME MPIR_WinGetAttr
        -:   28:
        -:   29:int MPIR_WinGetAttr( MPI_Win win, int win_keyval, void *attribute_val, 
        -:   30:		     int *flag, MPIR_AttrType outAttrType )
       64:   31:{
        -:   32:#ifdef HAVE_ERROR_CHECKING
        -:   33:    static const char FCNAME[] = "MPIR_WinGetAttr";
        -:   34:#endif
       64:   35:    int mpi_errno = MPI_SUCCESS;
       64:   36:    MPID_Win *win_ptr = NULL;
       64:   37:    MPIU_THREADPRIV_DECL;
        -:   38:    MPID_MPI_STATE_DECL(MPID_STATE_MPIR_WIN_GET_ATTR);
        -:   39:
       64:   40:    MPIR_ERRTEST_INITIALIZED_ORDIE();
        -:   41:    
       64:   42:    MPIU_THREAD_CS_ENTER(ALLFUNC,);
        -:   43:    MPID_MPI_FUNC_ENTER(MPID_STATE_MPIR_WIN_GET_ATTR);
        -:   44:
        -:   45:    /* Validate parameters, especially handles needing to be converted */
        -:   46:#   ifdef HAVE_ERROR_CHECKING
        -:   47:    {
        -:   48:        MPID_BEGIN_ERROR_CHECKS;
        -:   49:        {
       64:   50:	    MPIR_ERRTEST_WIN(win, mpi_errno);
       64:   51:	    MPIR_ERRTEST_KEYVAL(win_keyval, MPID_WIN, "window", mpi_errno);
        -:   52:#           ifdef NEEDS_POINTER_ALIGNMENT_ADJUST
        -:   53:            /* A common user error is to pass the address of a 4-byte
        -:   54:	       int when the address of a pointer (or an address-sized int)
        -:   55:	       should have been used.  We can test for this specific
        -:   56:	       case.  Note that this code assumes sizeof(MPIR_Pint) is
        -:   57:	       a power of 2. */
        -:   58:	    if ((MPIR_Pint)attribute_val & (sizeof(MPIR_Pint)-1)) {
        -:   59:		MPIU_ERR_SET(mpi_errno,MPI_ERR_ARG,"**attrnotptr");
        -:   60:	    }
        -:   61:#           endif
       64:   62:            if (mpi_errno != MPI_SUCCESS) goto fn_fail;
        -:   63:        }
        -:   64:        MPID_END_ERROR_CHECKS;
        -:   65:    }
        -:   66:#   endif
        -:   67:    
        -:   68:    /* Convert MPI object handles to object pointers */
       64:   69:    MPID_Win_get_ptr( win, win_ptr );
        -:   70:    
        -:   71:    /* Validate parameters and objects (post conversion) */
        -:   72:#   ifdef HAVE_ERROR_CHECKING
        -:   73:    {
        -:   74:	MPID_BEGIN_ERROR_CHECKS;
        -:   75:	{
        -:   76:            /* Validate win_ptr */
       64:   77:            MPID_Win_valid_ptr( win_ptr, mpi_errno );
        -:   78:	    /* If win_ptr is not valid, it will be reset to null */
       64:   79:	    MPIR_ERRTEST_ARGNULL(attribute_val, "attribute_val", mpi_errno);
       64:   80:	    MPIR_ERRTEST_ARGNULL(flag, "flag", mpi_errno);
       64:   81:            if (mpi_errno) goto fn_fail;
        -:   82:	}
        -:   83:	MPID_END_ERROR_CHECKS;
        -:   84:    }
        -:   85:#   endif /* HAVE_ERROR_CHECKING */    
        -:   86:
        -:   87:    /* ... body of routine ...  */
        -:   88:    
        -:   89:    /* Check for builtin attribute */
        -:   90:    /* This code is ok for correct programs, but it would be better
        -:   91:       to copy the values from the per-process block and pass the user
        -:   92:       a pointer to a copy */
        -:   93:    /* Note that if we are called from Fortran, we must return the values,
        -:   94:       not the addresses, of these attributes */
       64:   95:    if (HANDLE_GET_KIND(win_keyval) == HANDLE_KIND_BUILTIN) {
       26:   96:	int attr_idx = win_keyval & 0x0000000f;
       26:   97:	void **attr_val_p = (void **)attribute_val;
        -:   98:#ifdef HAVE_FORTRAN_BINDING
        -:   99:	/* Note that this routine only has a Fortran 90 binding,
        -:  100:	   so the attribute value is an address-sized int */
       26:  101:	MPIR_Pint  *attr_int = (MPIR_Pint *)attribute_val;
        -:  102:#endif
       26:  103:	*flag = 1;
        -:  104:
        -:  105:	/* 
        -:  106:	 * The C versions of the attributes return the address of a 
        -:  107:	 * *COPY* of the value (to prevent the user from changing it)
        -:  108:	 * and the Fortran versions provide the actual value (as a Fint)
        -:  109:	 */
       26:  110:	switch (attr_idx) {
        -:  111:	case 1: /* WIN_BASE */
       21:  112:	    *attr_val_p = win_ptr->base;
       21:  113:	    break;
        -:  114:	case 3: /* SIZE */
        1:  115:	    win_ptr->copySize = win_ptr->size;
        1:  116:	    *attr_val_p = &win_ptr->copySize;
        1:  117:	    break;
        -:  118:	case 5: /* DISP_UNIT */
        1:  119:	    win_ptr->copyDispUnit = win_ptr->disp_unit;
        1:  120:	    *attr_val_p = &win_ptr->copyDispUnit;
        1:  121:	    break;
        -:  122:#ifdef HAVE_FORTRAN_BINDING
        -:  123:	case 2: /* Fortran BASE */
        -:  124:	    /* The Fortran routine that matches this routine should
        -:  125:	       provide an address-sized integer, not an MPI_Fint */
        1:  126:	    *attr_int = MPI_VOID_PTR_CAST_TO_MPI_AINT(win_ptr->base);
        1:  127:	    break;
        -:  128:	case 4: /* Fortran SIZE */
        -:  129:	    /* We do not need to copy because we return the value,
        -:  130:	       not a pointer to the value */
        1:  131:	    *attr_int = win_ptr->size;
        1:  132:	    break;
        -:  133:	case 6: /* Fortran DISP_UNIT */
        -:  134:	    /* We do not need to copy because we return the value,
        -:  135:	       not a pointer to the value */
        1:  136:	    *attr_int = win_ptr->disp_unit;
        -:  137:	    break;
        -:  138:#endif
        -:  139:	}
        -:  140:    }
        -:  141:    else {
       38:  142:	MPID_Attribute *p = win_ptr->attributes;
        -:  143:
       38:  144:	*flag = 0;
       85:  145:	while (p) {
       34:  146:	    if (p->keyval->handle == win_keyval) {
       25:  147:		*flag = 1;
       25:  148:		if (outAttrType == MPIR_ATTR_PTR) {
       21:  149:		    if (p->attrType == MPIR_ATTR_INT) {
        -:  150:			/* This is the tricky case: if the system is
        -:  151:			   bigendian, and we have to return a pointer to
        -:  152:			   an int, then we may need to point to the 
        -:  153:			   correct location in the word. */
        -:  154:#if defined(WORDS_LITTLEENDIAN) || (SIZEOF_VOID_P == SIZEOF_INT)
    #####:  155:			*(void**)attribute_val = &(p->value);
        -:  156:#else
        -:  157:			int *p_loc = (int *)&(p->value);
        -:  158:#if SIZEOF_VOID_P == 2 * SIZEOF_INT
        -:  159:			p_loc++;
        -:  160:#else 
        -:  161:#error Expected sizeof(void*) to be either sizeof(int) or 2*sizeof(int)
        -:  162:#endif
        -:  163:			*(void **)attribute_val = p_loc;
        -:  164:#endif
        -:  165:		    }
       21:  166:		    else if (p->attrType == MPIR_ATTR_AINT) {
    #####:  167:			*(void**)attribute_val = &(p->value);
        -:  168:		    }
        -:  169:		    else {
       21:  170:			*(void**)attribute_val = (void *)(p->value);
        -:  171:		    }
        -:  172:		}
        -:  173:		else
        4:  174:		    *(void**)attribute_val = (void *)(p->value);
        -:  175:		
        -:  176:		break;
        -:  177:	    }
        9:  178:	    p = p->next;
        -:  179:	}
        -:  180:    }
        -:  181:
        -:  182:    /* ... end of body of routine ... */
        -:  183:
        -:  184:#ifdef HAVE_ERROR_CHECKING
       64:  185:  fn_exit:
        -:  186:#endif
        -:  187:    MPID_MPI_FUNC_EXIT(MPID_STATE_MPIR_WIN_GET_ATTR);
       64:  188:    MPIU_THREAD_CS_EXIT(ALLFUNC,);
       64:  189:    return mpi_errno;
        -:  190:
        -:  191:    /* --BEGIN ERROR HANDLING-- */
        -:  192:#   ifdef HAVE_ERROR_CHECKING
    #####:  193:  fn_fail:
        -:  194:    {
    #####:  195:	mpi_errno = MPIR_Err_create_code(
        -:  196:	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, 
        -:  197:	    "**mpir_wingetattr", 
        -:  198:	    "**mpir_wingetattr %W %d %p %p", 
        -:  199:	    win, win_keyval, attribute_val, flag);
        -:  200:    }
    #####:  201:    mpi_errno = MPIR_Err_return_win( win_ptr, FCNAME, mpi_errno );
    #####:  202:    goto fn_exit;
        -:  203:#   endif
        -:  204:    /* --END ERROR HANDLING-- */
        -:  205:}
        -:  206:#endif
        -:  207:
        -:  208:#undef FUNCNAME
        -:  209:#define FUNCNAME MPI_Win_get_attr
        -:  210:
        -:  211:/*@
        -:  212:   MPI_Win_get_attr - Get attribute cached on an MPI window object
        -:  213:
        -:  214:   Input Parameters:
        -:  215:+ win - window to which the attribute is attached (handle) 
        -:  216:- win_keyval - key value (integer) 
        -:  217:
        -:  218:   Output Parameters:
        -:  219:+ attribute_val - attribute value, unless flag is false 
        -:  220:- flag - false if no attribute is associated with the key (logical) 
        -:  221:
        -:  222:   Notes:
        -:  223:   The following attributes are predefined for all MPI Window objects\:
        -:  224:
        -:  225:+ MPI_WIN_BASE - window base address. 
        -:  226:. MPI_WIN_SIZE - window size, in bytes. 
        -:  227:- MPI_WIN_DISP_UNIT - displacement unit associated with the window. 
        -:  228:
        -:  229:.N ThreadSafe
        -:  230:
        -:  231:.N Fortran
        -:  232:
        -:  233:.N Errors
        -:  234:.N MPI_SUCCESS
        -:  235:.N MPI_ERR_WIN
        -:  236:.N MPI_ERR_KEYVAL
        -:  237:.N MPI_ERR_OTHER
        -:  238:@*/
        -:  239:int MPI_Win_get_attr(MPI_Win win, int win_keyval, void *attribute_val, 
        -:  240:		     int *flag)
       53:  241:{
        -:  242:    static const char FCNAME[] = "MPI_Win_get_attr";
       53:  243:    int mpi_errno = MPI_SUCCESS;
       53:  244:    MPID_Win *win_ptr = NULL;
        -:  245:    MPID_MPI_STATE_DECL(MPID_STATE_MPI_WIN_GET_ATTR);
        -:  246:
       53:  247:    MPIR_ERRTEST_INITIALIZED_ORDIE();
        -:  248:    
        -:  249:    MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_WIN_GET_ATTR);
        -:  250:
        -:  251:    /* ... body of routine ...  */
       53:  252:    mpi_errno = MPIR_WinGetAttr( win, win_keyval, attribute_val, flag, 
        -:  253:				 MPIR_ATTR_PTR );
       53:  254:    if (mpi_errno) goto fn_fail;
        -:  255:    /* ... end of body of routine ... */
        -:  256:
       53:  257:  fn_exit:
        -:  258:    MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_WIN_GET_ATTR);
       53:  259:    return mpi_errno;
        -:  260:
        -:  261:    /* --BEGIN ERROR HANDLING-- */
    #####:  262:  fn_fail:
        -:  263:#ifdef HAVE_ERROR_CHECKING
        -:  264:    {
    #####:  265:	mpi_errno = MPIR_Err_create_code(
        -:  266:	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, 
        -:  267:	    "**mpi_win_get_attr", 
        -:  268:	    "**mpi_win_get_attr %W %d %p %p", 
        -:  269:	    win, win_keyval, attribute_val, flag);
        -:  270:    }
    #####:  271:    mpi_errno = MPIR_Err_return_win( win_ptr, FCNAME, mpi_errno );
        -:  272:#endif
    #####:  273:    goto fn_exit;
        -:  274:    /* --END ERROR HANDLING-- */
        -:  275:}