1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2005 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2009 Sun Microsystmes, Inc. All rights reserved.
14 * Copyright (c) 2013-2015 Los Alamos National Security, LLC. All rights
15 * reserved.
16 * Copyright (c) 2015 Research Organization for Information Science
17 * and Technology (RIST). All rights reserved.
18 * $COPYRIGHT$
19 *
20 * Additional copyrights may follow
21 *
22 * $HEADER$
23 */
24 #include "ompi_config.h"
25 #include <stdio.h>
26 #include "ompi/mpi/c/bindings.h"
27 #include "ompi/runtime/params.h"
28 #include "ompi/communicator/communicator.h"
29 #include "ompi/errhandler/errhandler.h"
30 #include "ompi/win/win.h"
31 #include "ompi/mca/osc/osc.h"
32 #include "ompi/op/op.h"
33 #include "ompi/datatype/ompi_datatype.h"
34 #include "ompi/datatype/ompi_datatype_internal.h"
35 #include "ompi/memchecker.h"
36
37 #if OMPI_BUILD_MPI_PROFILING
38 #if OPAL_HAVE_WEAK_SYMBOLS
39 #pragma weak MPI_Accumulate = PMPI_Accumulate
40 #endif
41 #define MPI_Accumulate PMPI_Accumulate
42 #endif
43
44 static const char FUNC_NAME[] = "MPI_Accumulate";
45
46 int MPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
47 int target_rank, MPI_Aint target_disp, int target_count,
48 MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
49 {
50 int rc;
51 ompi_win_t *ompi_win = (ompi_win_t*) win;
52
53 MEMCHECKER(
54 memchecker_datatype(origin_datatype);
55 memchecker_datatype(target_datatype);
56 memchecker_call(&opal_memchecker_base_isdefined, (void *) origin_addr, origin_count, origin_datatype);
57 );
58
59 if (MPI_PARAM_CHECK) {
60 rc = OMPI_SUCCESS;
61
62 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
63
64 if (ompi_win_invalid(win)) {
65 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_WIN, FUNC_NAME);
66 } else if (origin_count < 0 || target_count < 0) {
67 rc = MPI_ERR_COUNT;
68 } else if (ompi_win_peer_invalid(win, target_rank) &&
69 (MPI_PROC_NULL != target_rank)) {
70 rc = MPI_ERR_RANK;
71 } else if (MPI_OP_NULL == op || MPI_NO_OP == op) {
72 rc = MPI_ERR_OP;
73 } else if (!ompi_op_is_intrinsic(op)) {
74 rc = MPI_ERR_OP;
75 } else if ( MPI_WIN_FLAVOR_DYNAMIC != win->w_flavor && target_disp < 0 ) {
76 rc = MPI_ERR_DISP;
77 } else {
78 OMPI_CHECK_DATATYPE_FOR_ONE_SIDED(rc, origin_datatype, origin_count);
79 if (OMPI_SUCCESS == rc) {
80 OMPI_CHECK_DATATYPE_FOR_ONE_SIDED(rc, target_datatype, target_count);
81 }
82 if (OMPI_SUCCESS == rc) {
83 /* While technically the standard probably requires that the
84 datatypes used with MPI_REPLACE conform to all the rules
85 for other reduction operators, we don't require such
86 behavior, as checking for it is expensive here and we don't
87 care in implementation.. */
88 if (op != &ompi_mpi_op_replace.op && op != &ompi_mpi_op_no_op.op) {
89 ompi_datatype_t *op_check_dt, *origin_check_dt;
90 char *msg;
91
92 /* ACCUMULATE, unlike REDUCE, can use with derived
93 datatypes with predefinied operations, with some
94 restrictions outlined in MPI-3:11.3.4. The derived
95 datatype must be composed entierly from one predefined
96 datatype (so you can do all the construction you want,
97 but at the bottom, you can only use one datatype, say,
98 MPI_INT). If the datatype at the target isn't
99 predefined, then make sure it's composed of only one
100 datatype, and check that datatype against
101 ompi_op_is_valid(). */
102 origin_check_dt = ompi_datatype_get_single_predefined_type_from_args(origin_datatype);
103 op_check_dt = ompi_datatype_get_single_predefined_type_from_args(target_datatype);
104
105 if( !((origin_check_dt == op_check_dt) & (NULL != op_check_dt)) ) {
106 OMPI_ERRHANDLER_RETURN(MPI_ERR_ARG, win, MPI_ERR_ARG, FUNC_NAME);
107 }
108
109 /* check to make sure primitive type is valid for
110 reduction. Should do this on the target, but
111 then can't get the errcode back for this
112 call */
113 if (!ompi_op_is_valid(op, op_check_dt, &msg, FUNC_NAME)) {
114 int ret = OMPI_ERRHANDLER_INVOKE(win, MPI_ERR_OP, msg);
115 free(msg);
116 return ret;
117 }
118 }
119 }
120 }
121 OMPI_ERRHANDLER_CHECK(rc, win, rc, FUNC_NAME);
122 }
123
124 if (MPI_PROC_NULL == target_rank) {
125 return MPI_SUCCESS;
126 }
127
128 OPAL_CR_ENTER_LIBRARY();
129
130 rc = ompi_win->w_osc_module->osc_accumulate(origin_addr,
131 origin_count,
132 origin_datatype,
133 target_rank,
134 target_disp,
135 target_count,
136 target_datatype,
137 op, win);
138 OMPI_ERRHANDLER_RETURN(rc, win, rc, FUNC_NAME);
139 }