1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 #include "mpiimpl.h"
7 
8 /* -- Begin Profiling Symbol Block for routine MPI_Win_flush_local */
9 #if defined(HAVE_PRAGMA_WEAK)
10 #pragma weak MPI_Win_flush_local = PMPI_Win_flush_local
11 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
12 #pragma _HP_SECONDARY_DEF PMPI_Win_flush_local  MPI_Win_flush_local
13 #elif defined(HAVE_PRAGMA_CRI_DUP)
14 #pragma _CRI duplicate MPI_Win_flush_local as PMPI_Win_flush_local
15 #elif defined(HAVE_WEAK_ATTRIBUTE)
16 int MPI_Win_flush_local(int rank, MPI_Win win)
17     __attribute__ ((weak, alias("PMPI_Win_flush_local")));
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_flush_local
25 #define MPI_Win_flush_local PMPI_Win_flush_local
26 
27 #endif
28 
29 /*@
30 MPI_Win_flush_local - Complete locally all outstanding RMA operations at the
31 given target
32 
33 
34 Locally completes at the origin all outstanding RMA operations initiated by the
35 calling process to the target process specified by rank on the specified
36 window. For example, after this routine completes, the user may reuse any
37 buffers provided to put, get, or accumulate operations.
38 
39 Input Parameters:
40 + rank - rank of window (nonnegative integer)
41 - win - window object (handle)
42 
43 .N ThreadSafe
44 
45 .N Fortran
46 
47 .N Errors
48 .N MPI_SUCCESS
49 .N MPI_ERR_RANK
50 .N MPI_ERR_WIN
51 .N MPI_ERR_OTHER
52 
53 .seealso: MPI_Win_flush MPI_Win_flush_all MPI_Win_flush_local_all MPI_Win_lock MPI_Win_lock_all
54 @*/
MPI_Win_flush_local(int rank,MPI_Win win)55 int MPI_Win_flush_local(int rank, MPI_Win win)
56 {
57     int mpi_errno = MPI_SUCCESS;
58     MPIR_Win *win_ptr = NULL;
59     MPIR_FUNC_TERSE_STATE_DECL(MPID_STATE_MPI_WIN_FLUSH_LOCAL);
60 
61     MPIR_ERRTEST_INITIALIZED_ORDIE();
62 
63     MPID_THREAD_CS_ENTER(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
64     MPIR_FUNC_TERSE_ENTER(MPID_STATE_MPI_WIN_FLUSH_LOCAL);
65 
66     /* Validate parameters, especially handles needing to be converted */
67 #ifdef HAVE_ERROR_CHECKING
68     {
69         MPID_BEGIN_ERROR_CHECKS;
70         {
71             MPIR_ERRTEST_WIN(win, mpi_errno);
72         }
73         MPID_END_ERROR_CHECKS;
74     }
75 #endif /* HAVE_ERROR_CHECKING */
76 
77     /* Convert MPI object handles to object pointers */
78     MPIR_Win_get_ptr(win, win_ptr);
79 
80     /* Validate parameters and objects (post conversion) */
81 #ifdef HAVE_ERROR_CHECKING
82     {
83         MPID_BEGIN_ERROR_CHECKS;
84         {
85             MPIR_Comm *comm_ptr;
86 
87             /* Validate win_ptr */
88             MPIR_Win_valid_ptr(win_ptr, mpi_errno);
89             if (mpi_errno)
90                 goto fn_fail;
91 
92             comm_ptr = win_ptr->comm_ptr;
93             MPIR_ERRTEST_SEND_RANK(comm_ptr, rank, mpi_errno);
94 
95             /* TODO: Validate that the given window is in passive mode */
96             /* TODO: Validate that the given rank is locked */
97         }
98         MPID_END_ERROR_CHECKS;
99     }
100 #endif /* HAVE_ERROR_CHECKING */
101 
102     /* Return immediately for dummy process */
103     if (rank == MPI_PROC_NULL) {
104         goto fn_exit;
105     }
106 
107     /* ... body of routine ...  */
108 
109     mpi_errno = MPID_Win_flush_local(rank, win_ptr);
110     if (mpi_errno != MPI_SUCCESS)
111         goto fn_fail;
112 
113     /* ... end of body of routine ... */
114 
115   fn_exit:
116     MPIR_FUNC_TERSE_EXIT(MPID_STATE_MPI_WIN_FLUSH_LOCAL);
117     MPID_THREAD_CS_EXIT(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
118     return mpi_errno;
119 
120   fn_fail:
121     /* --BEGIN ERROR HANDLING-- */
122 #ifdef HAVE_ERROR_CHECKING
123     {
124         mpi_errno =
125             MPIR_Err_create_code(mpi_errno, MPIR_ERR_RECOVERABLE, __func__, __LINE__, MPI_ERR_OTHER,
126                                  "**mpi_win_flush_local", "**mpi_win_flush_local %d %W", rank, win);
127     }
128 #endif
129     mpi_errno = MPIR_Err_return_win(win_ptr, __func__, mpi_errno);
130     goto fn_exit;
131     /* --END ERROR HANDLING-- */
132 }
133