1 /* Copyright (c) 2013-2022. 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"
8 namespace simgrid::smpi {
9 int bcast__SMP_binomial(void *buf, int count,
10 MPI_Datatype datatype, int root,
17 int tag = COLL_TAG_BCAST;
22 if(comm->get_leaders_comm()==MPI_COMM_NULL){
26 if (comm->is_uniform()){
27 num_core = comm->get_intra_comm()->size();
29 //implementation buggy in this case
30 return bcast__mpich(buf, count, datatype, root, comm);
33 int to_intra, to_inter;
34 int from_intra, from_inter;
35 int inter_rank = rank / num_core;
36 int inter_size = (size - 1) / num_core + 1;
37 int intra_rank = rank % num_core;
38 int intra_size = num_core;
39 if (((rank / num_core) * num_core) == ((size / num_core) * num_core))
40 intra_size = size - (rank / num_core) * num_core;
42 // if root is not zero send to rank zero first
45 Request::send(buf, count, datatype, 0, tag, comm);
47 Request::recv(buf, count, datatype, root, tag, comm, &status);
49 //FIRST STEP node 0 send to every root-of-each-SMP with binomial tree
51 //printf("node %d inter_rank = %d, inter_size = %d\n",rank,inter_rank, inter_size);
53 if (intra_rank == 0) {
55 while (mask < inter_size) {
56 if (inter_rank & mask) {
57 from_inter = (inter_rank - mask) * num_core;
58 //printf("Node %d recv from node %d when mask is %d\n", rank, from_inter, mask);
59 Request::recv(buf, count, datatype, from_inter, tag, comm, &status);
66 //printf("My rank = %d my mask = %d\n", rank,mask);
69 if (inter_rank < inter_size) {
70 to_inter = (inter_rank + mask) * num_core;
71 if (to_inter < size) {
72 //printf("Node %d send to node %d when mask is %d\n", rank, to_inter, mask);
73 Request::send(buf, count, datatype, to_inter, tag, comm);
79 // SECOND STEP every root-of-each-SMP send to all children with binomial tree
80 // base is a rank of root-of-each-SMP
81 int base = (rank / num_core) * num_core;
83 while (mask < intra_size) {
84 if (intra_rank & mask) {
85 from_intra = base + (intra_rank - mask);
86 //printf("Node %d recv from node %d when mask is %d\n", rank, from_inter, mask);
87 Request::recv(buf, count, datatype, from_intra, tag, comm, &status);
95 //printf("My rank = %d my mask = %d\n", rank,mask);
98 if (intra_rank < intra_size) {
99 to_intra = base + (intra_rank + mask);
100 if (to_intra < size) {
101 //printf("Node %d send to node %d when mask is %d\n", rank, to_inter, mask);
102 Request::send(buf, count, datatype, to_intra, tag, comm);
111 } // namespace simgrid::smpi