rget.c 5.88 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
3
4
5
6
7
8
9
/*
 *
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */

#include "mpiimpl.h"

10
/* -- Begin Profiling Symbol Block for routine MPI_Rget */
11
#if defined(HAVE_PRAGMA_WEAK)
12
#pragma weak MPI_Rget = PMPI_Rget
13
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
14
#pragma _HP_SECONDARY_DEF PMPI_Rget  MPI_Rget
15
#elif defined(HAVE_PRAGMA_CRI_DUP)
16
#pragma _CRI duplicate MPI_Rget as PMPI_Rget
17
18
19
20
21
22
#endif
/* -- End Profiling Symbol Block */

/* Define MPICH_MPI_FROM_PMPI if weak symbols are not supported to build
   the MPI routines */
#ifndef MPICH_MPI_FROM_PMPI
23
24
#undef MPI_Rget
#define MPI_Rget PMPI_Rget
25
26
27
28

#endif

#undef FUNCNAME
29
#define FUNCNAME MPI_Rget
30
31

/*@
32
33
34
35
36
37
38
39
40
MPI_Rget - Get data from a memory window on a remote process


'MPI_Rget' is similar to 'MPI_Get', except that it allocates a communication
request object and associates it with the request handle (the argument request)
that can be used to wait or test for completion. The completion of an 'MPI_Rget'
operation indicates that the data is available in the origin buffer. If
origin_addr points to memory attached to a window, then the data becomes
available in the private copy of this window.
41

42
Input Parameters:
43
+ origin_addr - Address of the buffer in which to receive the data
44
45
46
47
48
49
50
51
. origin_count - number of entries in origin buffer (nonnegative integer)
. origin_datatype - datatype of each entry in origin buffer (handle)
. target_rank - rank of target (nonnegative integer)
. target_disp - displacement from window start to the beginning of the
  target buffer (nonnegative integer)
. target_count - number of entries in target buffer (nonnegative integer)
. target_datatype - datatype of each entry in target buffer (handle)
- win - window object used for communication (handle)
52

53
Output Parameters:
54
55
56
57
58
59
60
61
62
63
64
65
66
. request - RMA request (handle)

.N ThreadSafe

.N Fortran

.N Errors
.N MPI_SUCCESS
.N MPI_ERR_ARG
.N MPI_ERR_COUNT
.N MPI_ERR_RANK
.N MPI_ERR_TYPE
.N MPI_ERR_WIN
67
68

.seealso: MPI_Get
69
@*/
70
int MPI_Rget(void *origin_addr, int origin_count, MPI_Datatype
71
72
73
74
            origin_datatype, int target_rank, MPI_Aint target_disp,
            int target_count, MPI_Datatype target_datatype, MPI_Win
            win, MPI_Request *request)
{
75
    static const char FCNAME[] = "MPI_Rget";
76
77
78
    int mpi_errno = MPI_SUCCESS;
    MPID_Win *win_ptr = NULL;
    MPID_Request *request_ptr = NULL;
79
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_RGET);
80
81
82
83

    MPIR_ERRTEST_INITIALIZED_ORDIE();
    
    MPIU_THREAD_CS_ENTER(ALLFUNC,);
84
    MPID_MPI_RMA_FUNC_ENTER(MPID_STATE_MPI_RGET);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

    /* Validate parameters, especially handles needing to be converted */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
            MPIR_ERRTEST_WIN(win, mpi_errno);
        }
        MPID_END_ERROR_CHECKS;
    }
#   endif /* HAVE_ERROR_CHECKING */

    /* Convert MPI object handles to object pointers */
    MPID_Win_get_ptr( win, win_ptr );

    /* Validate parameters and objects (post conversion) */
#   ifdef HAVE_ERROR_CHECKING
    {
        MPID_BEGIN_ERROR_CHECKS;
        {
            MPID_Comm * comm_ptr;
            
            /* Validate win_ptr */
            MPID_Win_valid_ptr( win_ptr, mpi_errno );
            if (mpi_errno) goto fn_fail;

            MPIR_ERRTEST_COUNT(origin_count, mpi_errno);
112
            MPIR_ERRTEST_DATATYPE(origin_datatype, "origin_datatype", mpi_errno);
113
            MPIR_ERRTEST_COUNT(target_count, mpi_errno);
114
            MPIR_ERRTEST_DATATYPE(target_datatype, "target_datatype", mpi_errno);
115
            if (win_ptr->create_flavor != MPI_WIN_FLAVOR_DYNAMIC)
116
                MPIR_ERRTEST_DISP(target_disp, mpi_errno);
117
118
119
120
121
122
123

            if (HANDLE_GET_KIND(origin_datatype) != HANDLE_KIND_BUILTIN)
            {
                MPID_Datatype *datatype_ptr = NULL;
                
                MPID_Datatype_get_ptr(origin_datatype, datatype_ptr);
                MPID_Datatype_valid_ptr(datatype_ptr, mpi_errno);
124
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
125
                MPID_Datatype_committed_ptr(datatype_ptr, mpi_errno);
126
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
127
128
129
130
131
132
133
134
            }

            if (HANDLE_GET_KIND(target_datatype) != HANDLE_KIND_BUILTIN)
            {
                MPID_Datatype *datatype_ptr = NULL;
                
                MPID_Datatype_get_ptr(target_datatype, datatype_ptr);
                MPID_Datatype_valid_ptr(datatype_ptr, mpi_errno);
135
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
136
                MPID_Datatype_committed_ptr(datatype_ptr, mpi_errno);
137
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
            }

            comm_ptr = win_ptr->comm_ptr;
            MPIR_ERRTEST_SEND_RANK(comm_ptr, target_rank, mpi_errno);
            MPIR_ERRTEST_ARGNULL(request,"request",mpi_errno);
        }
        MPID_END_ERROR_CHECKS;
    }
#   endif /* HAVE_ERROR_CHECKING */

    /* ... body of routine ...  */
    
    mpi_errno = MPIU_RMA_CALL(win_ptr,
                              Rget(origin_addr, origin_count, origin_datatype,
                                  target_rank, target_disp, target_count,
                                  target_datatype, win_ptr, &request_ptr));
    if (mpi_errno != MPI_SUCCESS) goto fn_fail;

    *request = request_ptr->handle;

    /* ... end of body of routine ... */

  fn_exit:
161
    MPID_MPI_RMA_FUNC_EXIT(MPID_STATE_MPI_RGET);
162
163
164
165
166
167
168
169
    MPIU_THREAD_CS_EXIT(ALLFUNC,);
    return mpi_errno;

  fn_fail:
    /* --BEGIN ERROR HANDLING-- */
#   ifdef HAVE_ERROR_CHECKING
    {
        mpi_errno = MPIR_Err_create_code(
170
            mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_rget", "**mpi_rget %p %d %D %d %d %d %D %W %p",
171
172
173
174
175
176
177
178
            origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype, win, request);
    }
#   endif
    mpi_errno = MPIR_Err_return_win( win_ptr, FCNAME, mpi_errno );
    goto fn_exit;
    /* --END ERROR HANDLING-- */
}