Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tesh files to test all new collectives
[simgrid.git] / src / smpi / colls / bcast-flattree.c
1 #include "colls.h"
2
3 int
4 smpi_coll_tuned_bcast_flattree(void *buff, int count, MPI_Datatype data_type,
5                                int root, MPI_Comm comm)
6 {
7   MPI_Request *req_ptr;
8   MPI_Request *reqs;
9
10   int i, rank, num_procs;
11   int tag = 1;
12
13   MPI_Comm_rank(comm, &rank);
14   MPI_Comm_size(comm, &num_procs);
15
16   if (rank != root) {
17     MPI_Recv(buff, count, data_type, root, tag, comm, MPI_STATUS_IGNORE);
18   }
19
20   else {
21     reqs = (MPI_Request *) malloc((num_procs - 1) * sizeof(MPI_Request));
22     req_ptr = reqs;
23
24     // Root sends data to all others
25     for (i = 0; i < num_procs; i++) {
26       if (i == rank)
27         continue;
28       MPI_Isend(buff, count, data_type, i, tag, comm, req_ptr++);
29     }
30
31     // wait on all requests
32     MPI_Waitall(num_procs - 1, reqs, MPI_STATUSES_IGNORE);
33
34     free(reqs);
35   }
36   return MPI_SUCCESS;
37 }