1 /* Copyright (c) 2013-2014. 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"
28 smpi_coll_tuned_scatter_ompi_binomial(void *sbuf, int scount,
30 void *rbuf, int rcount,
45 ompi_coll_tree_t* bmtree;
47 MPI_Aint sextent, slb, strue_lb, strue_extent;
48 MPI_Aint rextent, rlb, rtrue_lb, rtrue_extent;
50 size = smpi_comm_size(comm);
51 rank = smpi_comm_rank(comm);
54 "smpi_coll_tuned_scatter_ompi_binomial rank %d", rank);
56 /* create the binomial tree */
58 // COLL_TUNED_UPDATE_IN_ORDER_BMTREE( comm, tuned_module, root );
59 bmtree = ompi_coll_tuned_topo_build_in_order_bmtree( comm, root);//ompi_ data->cached_in_order_bmtree;
61 smpi_datatype_extent(sdtype, &slb, &sextent);
62 smpi_datatype_extent(sdtype, &strue_lb, &strue_extent);
63 smpi_datatype_extent(rdtype, &rlb, &rextent);
64 smpi_datatype_extent(rdtype, &rtrue_lb, &rtrue_extent);
66 vrank = (rank - root + size) % size;
70 /* root on 0, just use the send buffer */
72 if (rbuf != MPI_IN_PLACE) {
73 /* local copy to rbuf */
74 err = smpi_datatype_copy(sbuf, scount, sdtype,
75 rbuf, rcount, rdtype);
76 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
79 /* root is not on 0, allocate temp buffer for send */
80 tempbuf = (char *) malloc(strue_extent + (scount*size - 1) * sextent);
81 if (NULL == tempbuf) {
82 err = MPI_ERR_OTHER; line = __LINE__; goto err_hndl;
87 /* and rotate data so they will eventually in the right place */
88 err = smpi_datatype_copy((char *) sbuf + sextent*root*scount, scount*(size-root), sdtype,
89 ptmp, scount*(size-root), sdtype);
90 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
93 err = smpi_datatype_copy((char*)sbuf, scount*root, sdtype,
94 ptmp + sextent*scount*(size - root), scount*root, sdtype);
95 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
97 if (rbuf != MPI_IN_PLACE) {
98 /* local copy to rbuf */
99 err = smpi_datatype_copy(ptmp, scount, sdtype,
100 rbuf, rcount, rdtype);
101 if (MPI_SUCCESS != err) { line = __LINE__; goto err_hndl; }
105 } else if (!(vrank % 2)) {
106 /* non-root, non-leaf nodes, allocate temp buffer for recv
107 * the most we need is rcount*size/2 */
108 tempbuf = (char *) malloc(rtrue_extent + (rcount*size - 1) * rextent);
109 if (NULL == tempbuf) {
110 err= MPI_ERR_OTHER; line = __LINE__; goto err_hndl;
113 ptmp = tempbuf - rlb;
120 /* leaf nodes, just use rbuf */
121 ptmp = (char *) rbuf;
126 /* recv from parent on non-root */
127 smpi_mpi_recv(ptmp, rcount*size, rdtype, bmtree->tree_prev,
128 COLL_TAG_SCATTER, comm, &status);
129 /* local copy to rbuf */
130 smpi_datatype_copy(ptmp, scount, sdtype, rbuf, rcount, rdtype);
132 /* send to children on all non-leaf */
133 for (i = 0; i < bmtree->tree_nextsize; i++) {
134 int mycount = 0, vkid;
135 /* figure out how much data I have to send to this child */
136 vkid = (bmtree->tree_next[i] - root + size) % size;
137 mycount = vkid - vrank;
138 if (mycount > (size - vkid))
139 mycount = size - vkid;
142 smpi_mpi_send(ptmp + total_send*sextent, mycount, sdtype,
143 bmtree->tree_next[i],
147 total_send += mycount;
152 /* recv from parent on leaf nodes */
153 smpi_mpi_recv(ptmp, rcount, rdtype, bmtree->tree_prev,
154 COLL_TAG_SCATTER, comm, &status);
159 //!FIXME : store the tree, as done in ompi, instead of calculating it each time ?
168 XBT_DEBUG( "%s:%4d\tError occurred %d, rank %2d",
169 __FILE__, line, err, rank);
174 * Linear functions are copied from the BASIC coll module
175 * they do not segment the message and are simple implementations
176 * but for some small number of nodes and/or small data sizes they
177 * are just as fast as tuned/tree based segmenting operations
178 * and as such may be selected by the decision functions
179 * These are copied into this module due to the way we select modules
180 * in V1. i.e. in V2 we will handle this differently and so will not
181 * have to duplicate code.
182 * JPG following the examples from other coll_tuned implementations. Dec06.
185 /* copied function (with appropriate renaming) starts here */
189 * Function: - basic scatter operation
190 * Accepts: - same arguments as MPI_Scatter()
191 * Returns: - MPI_SUCCESS or error code
194 smpi_coll_tuned_scatter_ompi_basic_linear(void *sbuf, int scount,
196 void *rbuf, int rcount,
202 int i, rank, size, err;
208 rank = smpi_comm_rank(comm);
209 size = smpi_comm_size(comm);
211 /* If not root, receive data. */
214 smpi_mpi_recv(rbuf, rcount, rdtype, root,
216 comm, MPI_STATUS_IGNORE);
220 /* I am the root, loop sending data. */
222 err = smpi_datatype_extent(sdtype, &lb, &incr);
223 if (MPI_SUCCESS != err) {
224 return MPI_ERR_OTHER;
228 for (i = 0, ptmp = (char *) sbuf; i < size; ++i, ptmp += incr) {
230 /* simple optimization */
233 if (MPI_IN_PLACE != rbuf) {
235 smpi_datatype_copy(ptmp, scount, sdtype, rbuf, rcount,
239 smpi_mpi_send(ptmp, scount, sdtype, i,
243 if (MPI_SUCCESS != err) {