Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'tracemgrsplit' into 'master'
[simgrid.git] / src / smpi / colls / bcast / bcast-flattree.cpp
1 /* Copyright (c) 2013-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "../colls_private.hpp"
8 namespace simgrid{
9 namespace smpi{
10 int
11 Coll_bcast_flattree::bcast(void *buff, int count, MPI_Datatype data_type,
12                                int root, MPI_Comm comm)
13 {
14   int i, rank, num_procs;
15   int tag = COLL_TAG_BCAST;
16
17   rank = comm->rank();
18   num_procs = comm->size();
19
20   if (rank != root) {
21     Request::recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
22   }
23
24   else {
25     MPI_Request* reqs    = new MPI_Request[num_procs - 1];
26     MPI_Request* req_ptr = reqs;
27
28     // Root sends data to all others
29     for (i = 0; i < num_procs; i++) {
30       if (i == rank)
31         continue;
32       *(req_ptr++) = Request::isend(buff, count, data_type, i, tag, comm);
33     }
34
35     // wait on all requests
36     Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
37
38     delete[] reqs;
39   }
40   return MPI_SUCCESS;
41 }
42
43 }
44 }