Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
another allreduce ported
[simgrid.git] / src / smpi / colls / bcast-flattree-pipeline.c
1 #include "colls.h"
2
3 int flattree_segment_in_byte = 8192;
4
5 int
6 smpi_coll_tuned_bcast_flattree_pipeline(void *buff, int count,
7                                         MPI_Datatype data_type, int root,
8                                         MPI_Comm comm)
9 {
10   int i, j, rank, num_procs;
11   int tag = 1;
12
13   MPI_Aint extent;
14   MPI_Type_extent(data_type, &extent);
15
16   int segment = flattree_segment_in_byte / extent;
17   int pipe_length = count / segment;
18   int increment = segment * extent;
19
20   MPI_Comm_rank(comm, &rank);
21   MPI_Comm_size(comm, &num_procs);
22
23   MPI_Request *request_array;
24   MPI_Status *status_array;
25
26   request_array = (MPI_Request *) malloc(pipe_length * sizeof(MPI_Request));
27   status_array = (MPI_Status *) malloc(pipe_length * sizeof(MPI_Status));
28
29   if (rank != root) {
30     for (i = 0; i < pipe_length; i++) {
31       MPI_Irecv((char *)buff + (i * increment), segment, data_type, root, tag, comm,
32                 &request_array[i]);
33     }
34     MPI_Waitall(pipe_length, request_array, status_array);
35   }
36
37   else {
38     // Root sends data to all others
39     for (j = 0; j < num_procs; j++) {
40       if (j == rank)
41         continue;
42       else {
43         for (i = 0; i < pipe_length; i++) {
44           MPI_Send((char *)buff + (i * increment), segment, data_type, j, tag, comm);
45         }
46       }
47     }
48
49   }
50
51   free(request_array);
52   free(status_array);
53   return MPI_SUCCESS;
54 }