Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / smpi / colls / bcast / bcast-flattree.cpp
1 /* Copyright (c) 2013-2020. 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 bcast__flattree(void *buff, int count, MPI_Datatype data_type,
11                     int root, MPI_Comm comm)
12 {
13   int i, rank, num_procs;
14   int tag = COLL_TAG_BCAST;
15
16   rank = comm->rank();
17   num_procs = comm->size();
18
19   if (rank != root) {
20     Request::recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
21   }
22
23   else {
24     MPI_Request* reqs    = new MPI_Request[num_procs - 1];
25     MPI_Request* req_ptr = reqs;
26
27     // Root sends data to all others
28     for (i = 0; i < num_procs; i++) {
29       if (i == rank)
30         continue;
31       *(req_ptr++) = Request::isend(buff, count, data_type, i, tag, comm);
32     }
33
34     // wait on all requests
35     Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
36
37     delete[] reqs;
38   }
39   return MPI_SUCCESS;
40 }
41
42 }
43 }