This source file includes following definitions.
- MPI_Reduce
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include "ompi_config.h"
25 #include <stdio.h>
26
27 #include "ompi/mpi/c/bindings.h"
28 #include "ompi/runtime/params.h"
29 #include "ompi/communicator/communicator.h"
30 #include "ompi/errhandler/errhandler.h"
31 #include "ompi/datatype/ompi_datatype.h"
32 #include "ompi/op/op.h"
33 #include "ompi/memchecker.h"
34 #include "ompi/runtime/ompi_spc.h"
35
36 #if OMPI_BUILD_MPI_PROFILING
37 #if OPAL_HAVE_WEAK_SYMBOLS
38 #pragma weak MPI_Reduce = PMPI_Reduce
39 #endif
40 #define MPI_Reduce PMPI_Reduce
41 #endif
42
43 static const char FUNC_NAME[] = "MPI_Reduce";
44
45
46 int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
47 MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
48 {
49 int err;
50
51 SPC_RECORD(OMPI_SPC_REDUCE, 1);
52
53 MEMCHECKER(
54 memchecker_datatype(datatype);
55 memchecker_comm(comm);
56
57 if(OMPI_COMM_IS_INTRA(comm)) {
58 if(ompi_comm_rank(comm) == root) {
59
60 if (MPI_IN_PLACE == sendbuf) {
61 memchecker_call(&opal_memchecker_base_isdefined, recvbuf, count, datatype);
62 } else {
63 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
64 }
65
66
67 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
68 } else {
69
70 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
71 }
72 } else {
73 if (MPI_ROOT == root) {
74
75 memchecker_call(&opal_memchecker_base_isaddressable, recvbuf, count, datatype);
76 } else if (MPI_PROC_NULL != root) {
77
78 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
79 }
80 }
81 );
82
83 if (MPI_PARAM_CHECK) {
84 char *msg;
85 err = MPI_SUCCESS;
86 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
87 if (ompi_comm_invalid(comm)) {
88 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
89 FUNC_NAME);
90 }
91
92
93
94 else if (MPI_OP_NULL == op || NULL == op) {
95 err = MPI_ERR_OP;
96 } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
97 int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
98 free(msg);
99 return ret;
100 } else if ((ompi_comm_rank(comm) != root && MPI_IN_PLACE == sendbuf) ||
101 (ompi_comm_rank(comm) == root && ((MPI_IN_PLACE == recvbuf) || (sendbuf == recvbuf)))) {
102 err = MPI_ERR_ARG;
103 } else {
104 OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
105 }
106 OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
107
108
109
110 if (!OMPI_COMM_IS_INTRA(comm)) {
111 if (! ((root >= 0 && root < ompi_comm_remote_size(comm)) ||
112 MPI_ROOT == root || MPI_PROC_NULL == root)) {
113 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
114 }
115 }
116
117
118
119 else {
120 if (root < 0 || root >= ompi_comm_size(comm)) {
121 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ROOT, FUNC_NAME);
122 }
123 }
124 }
125
126
127
128
129
130 if (0 == count) {
131 return MPI_SUCCESS;
132 }
133
134 OPAL_CR_ENTER_LIBRARY();
135
136
137
138 OBJ_RETAIN(op);
139 err = comm->c_coll->coll_reduce(sendbuf, recvbuf, count,
140 datatype, op, root, comm,
141 comm->c_coll->coll_reduce_module);
142 OBJ_RELEASE(op);
143 OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
144 }