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 #include "rma.h"
10 
11 /* -- Begin Profiling Symbol Block for routine MPI_Win_unlock */
12 #if defined(HAVE_PRAGMA_WEAK)
13 #pragma weak MPI_Win_unlock = PMPI_Win_unlock
14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
15 #pragma _HP_SECONDARY_DEF PMPI_Win_unlock  MPI_Win_unlock
16 #elif defined(HAVE_PRAGMA_CRI_DUP)
17 #pragma _CRI duplicate MPI_Win_unlock as PMPI_Win_unlock
18 #endif
19 /* -- End Profiling Symbol Block */
20 
21 /* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
22    the MPI routines */
23 #ifndef MPICH_MPI_FROM_PMPI
24 #undef MPI_Win_unlock
25 #define MPI_Win_unlock PMPI_Win_unlock
26 
27 #endif
28 
29 #undef FUNCNAME
30 #define FUNCNAME MPI_Win_unlock
31 
32 /*@
33    MPI_Win_unlock - Completes an RMA access epoch at the target process
34 
35    Input Parameters:
36 + rank - rank of window (nonnegative integer)
37 - win - window object (handle)
38 
39 .N ThreadSafe
40 
41 .N Fortran
42 
43 .N Errors
44 .N MPI_SUCCESS
45 .N MPI_ERR_RANK
46 .N MPI_ERR_WIN
47 .N MPI_ERR_OTHER
48 
49 .seealso: MPI_Win_lock
50 @*/
MPI_Win_unlock(int rank,MPI_Win win)51 int MPI_Win_unlock(int rank, MPI_Win win)
52 {
53     static const char FCNAME[] = "MPI_Win_unlock";
54     int mpi_errno = MPI_SUCCESS;
55     MPID_Win *win_ptr = NULL;
56     MPID_MPI_STATE_DECL(MPID_STATE_MPI_WIN_UNLOCK);
57 
58     MPIR_ERRTEST_INITIALIZED_ORDIE();
59 
60     MPIU_THREAD_CS_ENTER(ALLFUNC,);
61     MPID_MPI_FUNC_ENTER(MPID_STATE_MPI_WIN_UNLOCK);
62 
63     /* Validate parameters, especially handles needing to be converted */
64 #   ifdef HAVE_ERROR_CHECKING
65     {
66         MPID_BEGIN_ERROR_CHECKS;
67         {
68 	    MPIR_ERRTEST_WIN(win, mpi_errno);
69         }
70         MPID_END_ERROR_CHECKS;
71     }
72 #   endif /* HAVE_ERROR_CHECKING */
73 
74     /* Convert MPI object handles to object pointers */
75     MPID_Win_get_ptr( win, win_ptr );
76 
77     /* Validate parameters and objects (post conversion) */
78 #   ifdef HAVE_ERROR_CHECKING
79     {
80         MPID_BEGIN_ERROR_CHECKS;
81         {
82 	    MPID_Comm * comm_ptr;
83 
84             /* Validate win_ptr */
85             MPID_Win_valid_ptr( win_ptr, mpi_errno );
86 	    /* If win_ptr is not valid, it will be reset to null */
87             if (mpi_errno) goto fn_fail;
88 
89 	    comm_ptr = win_ptr->comm_ptr;
90             MPIR_ERRTEST_SEND_RANK(comm_ptr, rank, mpi_errno);
91 	    /* Test that the rank we are unlocking is the rank that we locked */
92 	    if (win_ptr->lockRank != rank) {
93 		if (win_ptr->lockRank < 0) {
94 		    MPIU_ERR_SET(mpi_errno,MPI_ERR_RANK,"**winunlockwithoutlock");
95 		}
96 		else {
97 		    MPIU_ERR_SET2(mpi_errno,MPI_ERR_RANK,
98 		    "**mismatchedlockrank",
99  		    "**mismatchedlockrank %d %d", rank, win_ptr->lockRank );
100 		}
101 		if (mpi_errno) goto fn_fail;
102 	    }
103         }
104         MPID_END_ERROR_CHECKS;
105     }
106 #   endif /* HAVE_ERROR_CHECKING */
107 
108     /* ... body of routine ...  */
109 
110     mpi_errno = MPIU_RMA_CALL(win_ptr,Win_unlock(rank, win_ptr));
111     if (mpi_errno != MPI_SUCCESS) goto fn_fail;
112     /* Clear the lockRank on success with the unlock */
113     /* FIXME: Should this always be cleared, even on failure? */
114     win_ptr->lockRank = MPID_WIN_STATE_UNLOCKED;
115 
116     /* ... end of body of routine ... */
117 
118   fn_exit:
119     MPID_MPI_FUNC_EXIT(MPID_STATE_MPI_WIN_UNLOCK);
120     MPIU_THREAD_CS_EXIT(ALLFUNC,);
121     return mpi_errno;
122 
123   fn_fail:
124     /* --BEGIN ERROR HANDLING-- */
125 #   ifdef HAVE_ERROR_CHECKING
126     {
127 	mpi_errno = MPIR_Err_create_code(
128 	    mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_win_unlock",
129 	    "**mpi_win_unlock %d %W", rank, win);
130     }
131 #   endif
132     mpi_errno = MPIR_Err_return_win( win_ptr, FCNAME, mpi_errno );
133     goto fn_exit;
134     /* --END ERROR HANDLING-- */
135 }
136 
137