1 /* Copyright (c) 2013-2020. 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. */
7 #include "../colls_private.hpp"
9 /*****************************************************************************
11 Copyright (c) 2006, Ahmad Faraj & Xin Yuan,
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
17 * Redistributions of source code must retain the above copyright notice,
18 this list of conditions and the following disclaimer.
20 * Redistributions in binary form must reproduce the above copyright notice,
21 this list of conditions and the following disclaimer in the documentation
22 and/or other materials provided with the distribution.
24 * Neither the name of the Florida State University nor the names of its
25 contributors may be used to endorse or promote products derived from this
26 software without specific prior written permission.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
29 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
32 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************
40 * Any results obtained from executing this software require the *
41 * acknowledgment and citation of the software and its owners. *
42 * The full citation is given below: *
44 * A. Faraj and X. Yuan. "Automatic Generation and Tuning of MPI *
45 * Collective Communication Routines." The 19th ACM International *
46 * Conference on Supercomputing (ICS), Cambridge, Massachusetts, *
48 *************************************************************************
50 *****************************************************************************/
52 /*****************************************************************************
54 * Function: bcast_binomial_tree
59 buff: send input buffer
60 count: number of elements to send
61 data_type: data type of elements being sent
65 * Descrp: broadcasts using a bionomial tree.
67 * Author: MPIH / modified by Ahmad Faraj
69 ****************************************************************************/
72 int bcast__binomial_tree(void *buff, int count,
73 MPI_Datatype data_type, int root,
76 int src, dst, rank, num_procs, mask, relative_rank;
77 int tag = COLL_TAG_BCAST;
80 num_procs = comm->size();
82 relative_rank = (rank >= root) ? rank - root : rank - root + num_procs;
85 while (mask < num_procs) {
86 if (relative_rank & mask) {
90 Request::recv(buff, count, data_type, src, tag, comm, MPI_STATUS_IGNORE);
98 if (relative_rank + mask < num_procs) {
100 if (dst >= num_procs)
102 Request::send(buff, count, data_type, dst, tag, comm);