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"
29 int Coll_scatter_ompi_binomial::scatter(void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
30 MPI_Datatype rdtype, int root, MPI_Comm comm)
41 ompi_coll_tree_t* bmtree;
43 MPI_Aint sextent, slb, strue_lb, strue_extent;
44 MPI_Aint rextent, rlb, rtrue_lb, rtrue_extent;
50 "Coll_scatter_ompi_binomial::scatter rank %d", rank);
52 /* create the binomial tree */
54 // COLL_TUNED_UPDATE_IN_ORDER_BMTREE( comm, tuned_module, root );
55 bmtree = ompi_coll_tuned_topo_build_in_order_bmtree( comm, root);//ompi_ data->cached_in_order_bmtree;
57 sdtype->extent(&slb, &sextent);
58 sdtype->extent(&strue_lb, &strue_extent);
59 rdtype->extent(&rlb, &rextent);
60 rdtype->extent(&rtrue_lb, &rtrue_extent);
62 vrank = (rank - root + size) % size;
66 /* root on 0, just use the send buffer */
68 if (rbuf != MPI_IN_PLACE) {
69 /* local copy to rbuf */
70 err = Datatype::copy(sbuf, scount, sdtype, rbuf, rcount, rdtype);
71 if (MPI_SUCCESS != err) {
77 /* root is not on 0, allocate temp buffer for send */
78 tempbuf = (char*)smpi_get_tmp_sendbuffer(strue_extent + (scount * size - 1) * sextent);
79 if (NULL == tempbuf) {
87 /* and rotate data so they will eventually in the right place */
88 err = Datatype::copy((char*)sbuf + sextent * root * scount, scount * (size - root), sdtype, ptmp,
89 scount * (size - root), sdtype);
90 if (MPI_SUCCESS != err) {
95 err = Datatype::copy((char*)sbuf, scount * root, sdtype, ptmp + sextent * scount * (size - root), scount * root,
97 if (MPI_SUCCESS != err) {
102 if (rbuf != MPI_IN_PLACE) {
103 /* local copy to rbuf */
104 err = Datatype::copy(ptmp, scount, sdtype, rbuf, rcount, rdtype);
105 if (MPI_SUCCESS != err) {
112 } else if (not(vrank % 2)) {
113 /* non-root, non-leaf nodes, allocate temp buffer for recv
114 * the most we need is rcount*size/2 */
115 tempbuf = (char*)smpi_get_tmp_recvbuffer(rtrue_extent + (rcount * size - 1) * rextent);
116 if (NULL == tempbuf) {
122 ptmp = tempbuf - rlb;
129 /* leaf nodes, just use rbuf */
133 if (not(vrank % 2)) {
135 /* recv from parent on non-root */
136 Request::recv(ptmp, rcount * size, rdtype, bmtree->tree_prev, COLL_TAG_SCATTER, comm, &status);
137 /* local copy to rbuf */
138 Datatype::copy(ptmp, scount, sdtype, rbuf, rcount, rdtype);
140 /* send to children on all non-leaf */
141 for (i = 0; i < bmtree->tree_nextsize; i++) {
142 int mycount = 0, vkid;
143 /* figure out how much data I have to send to this child */
144 vkid = (bmtree->tree_next[i] - root + size) % size;
145 mycount = vkid - vrank;
146 if (mycount > (size - vkid))
147 mycount = size - vkid;
150 Request::send(ptmp + total_send * sextent, mycount, sdtype, bmtree->tree_next[i], COLL_TAG_SCATTER, comm);
152 total_send += mycount;
156 /* recv from parent on leaf nodes */
157 Request::recv(ptmp, rcount, rdtype, bmtree->tree_prev, COLL_TAG_SCATTER, comm, &status);
161 smpi_free_tmp_buffer(tempbuf);
162 // not FIXME : store the tree, as done in ompi, instead of calculating it each time ?
171 XBT_DEBUG("%s:%4d\tError occurred %d, rank %2d", __FILE__, line, err, rank);
176 * Linear functions are copied from the BASIC coll module
177 * they do not segment the message and are simple implementations
178 * but for some small number of nodes and/or small data sizes they
179 * are just as fast as tuned/tree based segmenting operations
180 * and as such may be selected by the decision functions
181 * These are copied into this module due to the way we select modules
182 * in V1. i.e. in V2 we will handle this differently and so will not
183 * have to duplicate code.
184 * JPG following the examples from other coll_tuned implementations. Dec06.
187 /* copied function (with appropriate renaming) starts here */
191 * Function: - basic scatter operation
192 * Accepts: - same arguments as MPI_Scatter()
193 * Returns: - MPI_SUCCESS or error code
195 int Coll_scatter_ompi_basic_linear::scatter(void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount,
196 MPI_Datatype rdtype, int root, MPI_Comm comm)
198 int i, rank, size, err;
207 /* If not root, receive data. */
210 Request::recv(rbuf, rcount, rdtype, root,
212 comm, MPI_STATUS_IGNORE);
216 /* I am the root, loop sending data. */
218 err = sdtype->extent(&lb, &incr);
219 if (MPI_SUCCESS != err) {
220 return MPI_ERR_OTHER;
224 for (i = 0, ptmp = (char *) sbuf; i < size; ++i, ptmp += incr) {
226 /* simple optimization */
229 if (MPI_IN_PLACE != rbuf) {
231 Datatype::copy(ptmp, scount, sdtype, rbuf, rcount,
235 Request::send(ptmp, scount, sdtype, i,
239 if (MPI_SUCCESS != err) {