Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ok, I stop trying to please sonar.
[simgrid.git] / src / smpi / colls / bcast / bcast-flattree.cpp
1 /* Copyright (c) 2013-2014. 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.h"
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   MPI_Request *req_ptr;
15   MPI_Request *reqs;
16
17   int i, rank, num_procs;
18   int tag = COLL_TAG_BCAST;
19
20   rank = comm->rank();
21   num_procs = comm->size();
22
23   if (rank != root) {
24     Request::recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
25   }
26
27   else {
28     reqs = (MPI_Request *) xbt_malloc((num_procs - 1) * sizeof(MPI_Request));
29     req_ptr = reqs;
30
31     // Root sends data to all others
32     for (i = 0; i < num_procs; i++) {
33       if (i == rank)
34         continue;
35       *(req_ptr++) = Request::isend(buff, count, data_type, i, tag, comm);
36     }
37
38     // wait on all requests
39     Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
40
41     free(reqs);
42   }
43   return MPI_SUCCESS;
44 }
45
46 }
47 }