Logo AND Algorithmique Numérique Distribuée

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