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. */
7 #include "../colls_private.h"
10 int Coll_bcast_SMP_binomial::bcast(void *buf, int count,
11 MPI_Datatype datatype, int root,
18 int tag = COLL_TAG_BCAST;
23 if(comm->get_leaders_comm()==MPI_COMM_NULL){
27 if (comm->is_uniform()){
28 num_core = comm->get_intra_comm()->size();
30 //implementation buggy in this case
31 return Coll_bcast_mpich::bcast( buf , count, datatype,
35 int to_intra, to_inter;
36 int from_intra, from_inter;
37 int inter_rank = rank / num_core;
38 int inter_size = (size - 1) / num_core + 1;
39 int intra_rank = rank % num_core;
40 int intra_size = num_core;
41 if (((rank / num_core) * num_core) == ((size / num_core) * num_core))
42 intra_size = size - (rank / num_core) * num_core;
44 // if root is not zero send to rank zero first
47 Request::send(buf, count, datatype, 0, tag, comm);
49 Request::recv(buf, count, datatype, root, tag, comm, &status);
51 //FIRST STEP node 0 send to every root-of-each-SMP with binomial tree
53 //printf("node %d inter_rank = %d, inter_size = %d\n",rank,inter_rank, inter_size);
55 if (intra_rank == 0) {
57 while (mask < inter_size) {
58 if (inter_rank & mask) {
59 from_inter = (inter_rank - mask) * num_core;
60 //printf("Node %d recv from node %d when mask is %d\n", rank, from_inter, mask);
61 Request::recv(buf, count, datatype, from_inter, tag, comm, &status);
68 //printf("My rank = %d my mask = %d\n", rank,mask);
71 if (inter_rank < inter_size) {
72 to_inter = (inter_rank + mask) * num_core;
73 if (to_inter < size) {
74 //printf("Node %d send to node %d when mask is %d\n", rank, to_inter, mask);
75 Request::send(buf, count, datatype, to_inter, tag, comm);
81 // SECOND STEP every root-of-each-SMP send to all children with binomial tree
82 // base is a rank of root-of-each-SMP
83 int base = (rank / num_core) * num_core;
85 while (mask < intra_size) {
86 if (intra_rank & mask) {
87 from_intra = base + (intra_rank - mask);
88 //printf("Node %d recv from node %d when mask is %d\n", rank, from_inter, mask);
89 Request::recv(buf, count, datatype, from_intra, tag, comm, &status);
97 //printf("My rank = %d my mask = %d\n", rank,mask);
100 if (intra_rank < intra_size) {
101 to_intra = base + (intra_rank + mask);
102 if (to_intra < size) {
103 //printf("Node %d send to node %d when mask is %d\n", rank, to_inter, mask);
104 Request::send(buf, count, datatype, to_intra, tag, comm);