raccumulate.c 6.34 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_Raccumulate */
11
#if defined(HAVE_PRAGMA_WEAK)
12
#pragma weak MPI_Raccumulate = PMPI_Raccumulate
13
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
14
#pragma _HP_SECONDARY_DEF PMPI_Raccumulate  MPI_Raccumulate
15
#elif defined(HAVE_PRAGMA_CRI_DUP)
16
#pragma _CRI duplicate MPI_Raccumulate as PMPI_Raccumulate
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_Raccumulate
#define MPI_Raccumulate PMPI_Raccumulate
25
26
27
28

#endif

#undef FUNCNAME
29
#define FUNCNAME MPI_Raccumulate
30
31

/*@
32
33
34
35
36
37
38
39
40
41
MPI_Raccumulate - Accumulate data into the target process using remote memory
access and return a request handle for the operation.


'MPI_Raccumulate' is similar to 'MPI_Accumulate', 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_Raccumulate' operation indicates that the origin buffer is
free to be updated. It does not indicate that the operation has completed at
the target window.
42

43
Input Parameters:
44
45
46
47
48
49
50
51
52
53
+ origin_addr - initial address of buffer (choice)
. origin_count - number of entries in buffer (nonnegative integer)
. origin_datatype - datatype of each buffer entry (handle)
. target_rank - rank of target (nonnegative integer)
. target_disp - displacement from start of window to beginning of target
  buffer (nonnegative integer)
. target_count - number of entries in target buffer (nonnegative integer)
. target_datatype - datatype of each entry in target buffer (handle)
. op - predefined reduce operation (handle)
- win - window object (handle)
54

55
Output Parameters:
56
57
. request - RMA request (handle)

58
59
Notes:
The basic components of both the origin and target datatype must be the same
60
61
62
63
64
65
66
67
68
69
70
predefined datatype (e.g., all 'MPI_INT' or all 'MPI_DOUBLE_PRECISION').

.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
71
72

.seealso: MPI_Accumulate
73
@*/
74
int MPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype
75
76
77
78
79
                   origin_datatype, int target_rank, MPI_Aint
                   target_disp, int target_count, MPI_Datatype
                   target_datatype, MPI_Op op, MPI_Win win,
                   MPI_Request *request) 
{
80
    static const char FCNAME[] = "MPI_Raccumulate";
81
82
83
    int mpi_errno = MPI_SUCCESS;
    MPID_Win *win_ptr = NULL;
    MPID_Request *request_ptr = NULL;
84
    MPID_MPI_STATE_DECL(MPID_STATE_MPI_RACCUMULATE);
85
86
87
88

    MPIR_ERRTEST_INITIALIZED_ORDIE();
    
    MPIU_THREAD_CS_ENTER(ALLFUNC,);
89
    MPID_MPI_RMA_FUNC_ENTER(MPID_STATE_MPI_RACCUMULATE);
90
91
92
93
94
95
96
97
98
99

    /* 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;
    }
100
#   endif /* HAVE_ERROR_CHECKING */
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    
    /* 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);
117
            MPIR_ERRTEST_DATATYPE(origin_datatype, "origin_datatype", mpi_errno);
118
            MPIR_ERRTEST_COUNT(target_count, mpi_errno);
119
            MPIR_ERRTEST_DATATYPE(target_datatype, "target_datatype", mpi_errno);
120
            if (win_ptr->create_flavor != MPI_WIN_FLAVOR_DYNAMIC)
121
                MPIR_ERRTEST_DISP(target_disp, mpi_errno);
122
123
124
125
126
127
128

            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);
129
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
130
                MPID_Datatype_committed_ptr(datatype_ptr, mpi_errno);
131
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
132
133
134
135
136
137
138
139
            }

            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);
140
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
141
                MPID_Datatype_committed_ptr(datatype_ptr, mpi_errno);
142
                if (mpi_errno != MPI_SUCCESS) goto fn_fail;
143
144
145
146
            }

            comm_ptr = win_ptr->comm_ptr;
            MPIR_ERRTEST_SEND_RANK(comm_ptr, target_rank, mpi_errno);
147
            MPIR_ERRTEST_OP_ACC(op, mpi_errno);
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
            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,Raccumulate(origin_addr, origin_count, 
                                         origin_datatype,
                                         target_rank, target_disp, target_count,
                                         target_datatype, op, win_ptr, &request_ptr));
    if (mpi_errno != MPI_SUCCESS) goto fn_fail;

    *request = request_ptr->handle;

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

  fn_exit:
167
    MPID_MPI_RMA_FUNC_EXIT(MPID_STATE_MPI_RACCUMULATE);
168
169
170
171
172
173
174
175
    MPIU_THREAD_CS_EXIT(ALLFUNC,);
    return mpi_errno;

  fn_fail:
    /* --BEGIN ERROR HANDLING-- */
#   ifdef HAVE_ERROR_CHECKING
    {
        mpi_errno = MPIR_Err_create_code(
176
177
            mpi_errno, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_OTHER, "**mpi_raccumulate",
            "**mpi_raccumulate %p %d %D %d %d %d %D %O %W %p", origin_addr, origin_count, origin_datatype,
178
179
180
181
182
183
184
185
            target_rank, target_disp, target_count, target_datatype, op, win, request);
    }
#   endif
    mpi_errno = MPIR_Err_return_win( win_ptr, FCNAME, mpi_errno );
    goto fn_exit;
    /* --END ERROR HANDLING-- */
}