1 /* Copyright (c) 2013-2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
9 * University Research and Technology
10 * Corporation. All rights reserved.
11 * Copyright (c) 2004-2006 The University of Tennessee and The University
12 * of Tennessee Research Foundation. All rights
14 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
15 * University of Stuttgart. All rights reserved.
16 * Copyright (c) 2004-2005 The Regents of the University of California.
17 * All rights reserved.
19 * Additional copyrights may follow
23 #include "../colls_private.h"
24 #include "../coll_tuned_topo.h"
31 Coll_scatter_ompi_binomial::scatter(void *sbuf, int scount,
33 void *rbuf, int rcount,
48 ompi_coll_tree_t* bmtree;
50 MPI_Aint sextent, slb, strue_lb, strue_extent;
51 MPI_Aint rextent, rlb, rtrue_lb, rtrue_extent;
57 "Coll_scatter_ompi_binomial::scatter rank %d", rank);
59 /* create the binomial tree */
61 // COLL_TUNED_UPDATE_IN_ORDER_BMTREE( comm, tuned_module, root );
62 bmtree = ompi_coll_tuned_topo_build_in_order_bmtree( comm, root);//ompi_ data->cached_in_order_bmtree;
64 sdtype->extent(&slb, &sextent);
65 sdtype->extent(&strue_lb, &strue_extent);
66 rdtype->extent(&rlb, &rextent);
67 rdtype->extent(&rtrue_lb, &rtrue_extent);
69 vrank = (rank - root + size) % size;
73 /* root on 0, just use the send buffer */
75 if (rbuf != MPI_IN_PLACE) {
76 /* local copy to rbuf */
77 err = Datatype::copy(sbuf, scount, sdtype,
78 rbuf, rcount, rdtype);
79 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
82 /* root is not on 0, allocate temp buffer for send */
83 tempbuf = (char *) smpi_get_tmp_sendbuffer(strue_extent + (scount*size - 1) * sextent);
84 if (NULL == tempbuf) {
85 err = MPI_ERR_OTHER; line = __LINE__; goto err_hndl;
90 /* and rotate data so they will eventually in the right place */
91 err = Datatype::copy((char *) sbuf + sextent*root*scount, scount*(size-root), sdtype,
92 ptmp, scount*(size-root), sdtype);
93 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
96 err = Datatype::copy((char*)sbuf, scount*root, sdtype,
97 ptmp + sextent*scount*(size - root), scount*root, sdtype);
98 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
100 if (rbuf != MPI_IN_PLACE) {
101 /* local copy to rbuf */
102 err = Datatype::copy(ptmp, scount, sdtype,
103 rbuf, rcount, rdtype);
104 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
108 } else if (!(vrank % 2)) {
109 /* non-root, non-leaf nodes, allocate temp buffer for recv
110 * the most we need is rcount*size/2 */
111 tempbuf = (char *) smpi_get_tmp_recvbuffer(rtrue_extent + (rcount*size - 1) * rextent);
112 if (NULL == tempbuf) {
113 err= MPI_ERR_OTHER; line = __LINE__; goto err_hndl;
116 ptmp = tempbuf - rlb;
123 /* leaf nodes, just use rbuf */
124 ptmp = (char *) rbuf;
129 /* recv from parent on non-root */
130 Request::recv(ptmp, rcount*size, rdtype, bmtree->tree_prev,
131 COLL_TAG_SCATTER, comm, &status);
132 /* local copy to rbuf */
133 Datatype::copy(ptmp, scount, sdtype, rbuf, rcount, rdtype);
135 /* send to children on all non-leaf */
136 for (i = 0; i < bmtree->tree_nextsize; i++) {
137 int mycount = 0, vkid;
138 /* figure out how much data I have to send to this child */
139 vkid = (bmtree->tree_next[i] - root + size) % size;
140 mycount = vkid - vrank;
141 if (mycount > (size - vkid))
142 mycount = size - vkid;
145 Request::send(ptmp + total_send*sextent, mycount, sdtype,
146 bmtree->tree_next[i],
150 total_send += mycount;
155 /* recv from parent on leaf nodes */
156 Request::recv(ptmp, rcount, rdtype, bmtree->tree_prev,
157 COLL_TAG_SCATTER, comm, &status);
161 smpi_free_tmp_buffer(tempbuf);
162 //!FIXME : store the tree, as done in ompi, instead of calculating it each time ?
171 XBT_DEBUG( "%s:%4d\tError occurred %d, rank %2d",
172 __FILE__, line, err, rank);
177 * Linear functions are copied from the BASIC coll module
178 * they do not segment the message and are simple implementations
179 * but for some small number of nodes and/or small data sizes they
180 * are just as fast as tuned/tree based segmenting operations
181 * and as such may be selected by the decision functions
182 * These are copied into this module due to the way we select modules
183 * in V1. i.e. in V2 we will handle this differently and so will not
184 * have to duplicate code.
185 * JPG following the examples from other coll_tuned implementations. Dec06.
188 /* copied function (with appropriate renaming) starts here */
192 * Function: - basic scatter operation
193 * Accepts: - same arguments as MPI_Scatter()
194 * Returns: - MPI_SUCCESS or error code
197 Coll_scatter_ompi_basic_linear::scatter(void *sbuf, int scount,
199 void *rbuf, int rcount,
205 int i, rank, size, err;
214 /* If not root, receive data. */
217 Request::recv(rbuf, rcount, rdtype, root,
219 comm, MPI_STATUS_IGNORE);
223 /* I am the root, loop sending data. */
225 err = sdtype->extent(&lb, &incr);
226 if (MPI_SUCCESS != err) {
227 return MPI_ERR_OTHER;
231 for (i = 0, ptmp = (char *) sbuf; i < size; ++i, ptmp += incr) {
233 /* simple optimization */
236 if (MPI_IN_PLACE != rbuf) {
238 Datatype::copy(ptmp, scount, sdtype, rbuf, rcount,
242 Request::send(ptmp, scount, sdtype, i,
246 if (MPI_SUCCESS != err) {