updating repository. Removing .Plo and .Po files that are generated automatically
[openmpi-llc.git] / ompi / mpi / c / accumulate.c
blobfdf1fa86abf2e33d5e5a6e0471af8e4daaee7eca
1 /*
2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * $COPYRIGHT$
14 * Additional copyrights may follow
16 * $HEADER$
18 #include "ompi_config.h"
19 #include <stdio.h>
21 #include "ompi/mpi/c/bindings.h"
22 #include "ompi/win/win.h"
23 #include "ompi/mca/osc/osc.h"
24 #include "ompi/op/op.h"
25 #include "ompi/datatype/datatype.h"
26 #include "ompi/datatype/datatype_internal.h"
28 #if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
29 #pragma weak MPI_Accumulate = PMPI_Accumulate
30 #endif
32 #if OMPI_PROFILING_DEFINES
33 #include "ompi/mpi/c/profile/defines.h"
34 #endif
36 static const char FUNC_NAME[] = "MPI_Accumlate";
39 int MPI_Accumulate(void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
40 int target_rank, MPI_Aint target_disp, int target_count,
41 MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
43 int rc;
44 ompi_win_t *ompi_win = (ompi_win_t*) win;
46 if (target_rank == MPI_PROC_NULL) return MPI_SUCCESS;
48 if (MPI_PARAM_CHECK) {
49 rc = OMPI_SUCCESS;
51 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
53 if (ompi_win_invalid(win)) {
54 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_WIN, FUNC_NAME);
55 } else if (origin_count < 0 || target_count < 0) {
56 rc = MPI_ERR_COUNT;
57 } else if (ompi_win_peer_invalid(win, target_rank)) {
58 rc = MPI_ERR_RANK;
59 } else if (MPI_OP_NULL == op) {
60 rc = MPI_ERR_OP;
61 } else if (!ompi_win_comm_allowed(win)) {
62 rc = MPI_ERR_RMA_SYNC;
63 } else {
64 OMPI_CHECK_DATATYPE_FOR_SEND(rc, origin_datatype, origin_count);
66 OMPI_ERRHANDLER_CHECK(rc, win, rc, FUNC_NAME);
68 /* While technically the standard probably requires that the
69 datatypes used with MPI_REPLACE conform to all the rules
70 for other reduction operators, we don't require such
71 behaivor, as checking for it is expensive here and we don't
72 care in implementation.. */
73 if (op != &ompi_mpi_op_replace) {
74 ompi_datatype_t *op_check_dt;
75 char *msg;
77 /* ACCUMULATE, unlike REDUCE, can use with derived
78 datatypes with predefinied operations, with some
79 restrictions outlined in MPI-2:6.3.4. The derived
80 datatype must be composed entirley from one predefined
81 datatype (so you can do all the construction you want,
82 but at the bottom, you can only use one datatype, say,
83 MPI_INT). If the datatype at the target isn't
84 predefined, then make sure it's composed of only one
85 datatype, and check that datatype against
86 ompi_op_is_valid(). */
87 if (ompi_ddt_is_predefined(target_datatype)) {
88 op_check_dt = target_datatype;
89 } else {
90 int i, index = -1, num_found = 0;
91 uint64_t mask = 1;
93 for (i = 0 ; i < DT_MAX_PREDEFINED ; ++i) {
94 if (target_datatype->bdt_used & mask) {
95 num_found++;
96 index = i;
98 mask *= 2;
100 if (index < 0 || num_found > 1) {
101 /* this is an erroneous datatype. Let
102 ompi_op_is_valid tell the user that */
103 op_check_dt = target_datatype;
104 } else {
105 /* datatype passes muster as far as restrictions
106 in MPI-2:6.3.4. Is the primitive ok with the
107 op? Unfortunately have to cast away
108 constness... */
109 op_check_dt = (ompi_datatype_t*)
110 ompi_ddt_basicDatatypes[index];
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;
121 rc = ompi_win->w_osc_module->osc_accumulate(origin_addr,
122 origin_count,
123 origin_datatype,
124 target_rank,
125 target_disp,
126 target_count,
127 target_datatype,
128 op, win);
129 OMPI_ERRHANDLER_RETURN(rc, win, rc, FUNC_NAME);