Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move collective algorithms to separate folders
[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
9 int
10 smpi_coll_tuned_bcast_flattree(void *buff, int count, MPI_Datatype data_type,
11                                int root, MPI_Comm comm)
12 {
13   MPI_Request *req_ptr;
14   MPI_Request *reqs;
15
16   int i, rank, num_procs;
17   int tag = COLL_TAG_BCAST;
18
19   rank = comm->rank();
20   num_procs = comm->size();
21
22   if (rank != root) {
23     Request::recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
24   }
25
26   else {
27     reqs = (MPI_Request *) xbt_malloc((num_procs - 1) * sizeof(MPI_Request));
28     req_ptr = reqs;
29
30     // Root sends data to all others
31     for (i = 0; i < num_procs; i++) {
32       if (i == rank)
33         continue;
34       *(req_ptr++) = Request::isend(buff, count, data_type, i, tag, comm);
35     }
36
37     // wait on all requests
38     Request::waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
39
40     free(reqs);
41   }
42   return MPI_SUCCESS;
43 }