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-2017 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) 2013 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2015-2018 Research Organization for Information Science
16 * and Technology (RIST). All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23
24 #include "ompi_config.h"
25
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/datatype/ompi_datatype.h"
31 #include "ompi/op/op.h"
32 #include "ompi/memchecker.h"
33 #include "ompi/runtime/ompi_spc.h"
34
35 #if OMPI_BUILD_MPI_PROFILING
36 #if OPAL_HAVE_WEAK_SYMBOLS
37 #pragma weak MPI_Exscan = PMPI_Exscan
38 #endif
39 #define MPI_Exscan PMPI_Exscan
40 #endif
41
42 static const char FUNC_NAME[] = "MPI_Exscan";
43
44
45 int MPI_Exscan(const void *sendbuf, void *recvbuf, int count,
46 MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
47 {
48 int err;
49
50 SPC_RECORD(OMPI_SPC_EXSCAN, 1);
51
52 MEMCHECKER(
53 memchecker_datatype(datatype);
54 memchecker_call(&opal_memchecker_base_isdefined, sendbuf, count, datatype);
55 memchecker_comm(comm);
56 );
57
58 if (MPI_PARAM_CHECK) {
59 char *msg;
60 err = MPI_SUCCESS;
61 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
62 if (ompi_comm_invalid(comm)) {
63 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
64 FUNC_NAME);
65 }
66
67 /* Unrooted operation -- same checks for intracommunicators
68 and intercommunicators */
69 else if (MPI_OP_NULL == op) {
70 err = MPI_ERR_OP;
71 } else if (!ompi_op_is_valid(op, datatype, &msg, FUNC_NAME)) {
72 int ret = OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_OP, msg);
73 free(msg);
74 return ret;
75 } else {
76 OMPI_CHECK_DATATYPE_FOR_SEND(err, datatype, count);
77 }
78 OMPI_ERRHANDLER_CHECK(err, comm, err, FUNC_NAME);
79 }
80
81 /* Do we need to do anything? (MPI says that reductions have to
82 have a count of at least 1, but at least IMB calls reduce with
83 a count of 0 -- blah!) */
84
85 if (0 == count) {
86 return MPI_SUCCESS;
87 }
88
89 OPAL_CR_ENTER_LIBRARY();
90
91 /* Invoke the coll component to perform the back-end operation */
92
93 OBJ_RETAIN(op);
94 err = comm->c_coll->coll_exscan(sendbuf, recvbuf, count,
95 datatype, op, comm,
96 comm->c_coll->coll_exscan_module);
97 OBJ_RELEASE(op);
98 OMPI_ERRHANDLER_RETURN(err, comm, err, FUNC_NAME);
99 }