1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2016 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 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) 2014-2015 Research Organization for Information Science
16 * and Technology (RIST). All rights reserved.
17 * Copyright (c) 2017 IBM Corporation. All rights reserved.
18 * $COPYRIGHT$
19 *
20 * Additional copyrights may follow
21 *
22 * $HEADER$
23 */
24
25 #include "ompi_config.h"
26 #include "coll_basic.h"
27
28 #include "mpi.h"
29 #include "ompi/constants.h"
30 #include "ompi/datatype/ompi_datatype.h"
31 #include "ompi/mca/coll/coll.h"
32 #include "ompi/mca/coll/base/coll_tags.h"
33 #include "ompi/mca/pml/pml.h"
34
35
36 /*
37 * alltoall_inter
38 *
39 * Function: - MPI_Alltoall
40 * Accepts: - same as MPI_Alltoall()
41 * Returns: - MPI_SUCCESS or an MPI error code
42 */
43 int
44 mca_coll_basic_alltoall_inter(const void *sbuf, int scount,
45 struct ompi_datatype_t *sdtype,
46 void *rbuf, int rcount,
47 struct ompi_datatype_t *rdtype,
48 struct ompi_communicator_t *comm,
49 mca_coll_base_module_t *module)
50 {
51 int i;
52 int size;
53 int err;
54 int nreqs;
55 char *psnd;
56 char *prcv;
57 MPI_Aint lb;
58 MPI_Aint sndinc;
59 MPI_Aint rcvinc;
60
61 ompi_request_t **req, **sreq, **rreq;
62
63 /* Initialize. */
64
65 size = ompi_comm_remote_size(comm);
66
67 err = ompi_datatype_get_extent(sdtype, &lb, &sndinc);
68 if (OMPI_SUCCESS != err) {
69 return err;
70 }
71 sndinc *= scount;
72
73 err = ompi_datatype_get_extent(rdtype, &lb, &rcvinc);
74 if (OMPI_SUCCESS != err) {
75 return err;
76 }
77 rcvinc *= rcount;
78
79 /* Initiate all send/recv to/from others. */
80 nreqs = size * 2;
81 req = rreq = ompi_coll_base_comm_get_reqs( module->base_data, nreqs);
82 if( NULL == req ) { return OMPI_ERR_OUT_OF_RESOURCE; }
83 sreq = rreq + size;
84
85 prcv = (char *) rbuf;
86 psnd = (char *) sbuf;
87
88 /* Post all receives first */
89 for (i = 0; i < size; i++, ++rreq) {
90 err = MCA_PML_CALL(irecv(prcv + (i * rcvinc), rcount, rdtype, i,
91 MCA_COLL_BASE_TAG_ALLTOALL, comm, rreq));
92 if (OMPI_SUCCESS != err) {
93 ompi_coll_base_free_reqs(req, i + 1);
94 return err;
95 }
96 }
97
98 /* Now post all sends */
99 for (i = 0; i < size; i++, ++sreq) {
100 err = MCA_PML_CALL(isend(psnd + (i * sndinc), scount, sdtype, i,
101 MCA_COLL_BASE_TAG_ALLTOALL,
102 MCA_PML_BASE_SEND_STANDARD, comm, sreq));
103 if (OMPI_SUCCESS != err) {
104 ompi_coll_base_free_reqs(req, i + size + 1);
105 return err;
106 }
107 }
108
109 /* Wait for them all. If there's an error, note that we don't
110 * care what the error was -- just that there *was* an error. The
111 * PML will finish all requests, even if one or more of them fail.
112 * i.e., by the end of this call, all the requests are free-able.
113 * So free them anyway -- even if there was an error, and return
114 * the error after we free everything. */
115 err = ompi_request_wait_all(nreqs, req, MPI_STATUSES_IGNORE);
116 if (OMPI_SUCCESS != err) {
117 ompi_coll_base_free_reqs(req, nreqs);
118 }
119
120 /* All done */
121 return err;
122 }