Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a1446463f0f9f4dd17e8a1af7c032ea94f6000c2
[simgrid.git] / src / smpi / colls / bcast / bcast-flattree-pipeline.cpp
1 /* Copyright (c) 2013-2022. 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
9 int flattree_segment_in_byte = 8192;
10 namespace simgrid::smpi {
11 int bcast__flattree_pipeline(void *buff, int count,
12                              MPI_Datatype data_type, int root,
13                              MPI_Comm comm)
14 {
15   int i, j, rank, num_procs;
16   int tag = COLL_TAG_BCAST;
17
18   MPI_Aint extent;
19   extent = data_type->get_extent();
20
21   int segment = flattree_segment_in_byte / extent;
22   segment =  segment == 0 ? 1 :segment;
23   int pipe_length = count / segment;
24   int increment = segment * extent;
25   if (pipe_length==0) {
26     XBT_INFO("MPI_bcast_flattree_pipeline: pipe_length=0, use default MPI_bcast_flattree.");
27     return bcast__flattree(buff, count, data_type, root, comm);
28   }
29   rank = comm->rank();
30   num_procs = comm->size();
31
32   auto* request_array = new MPI_Request[pipe_length];
33   auto* status_array  = new MPI_Status[pipe_length];
34
35   if (rank != root) {
36     for (i = 0; i < pipe_length; i++) {
37       request_array[i] = Request::irecv((char *)buff + (i * increment), segment, data_type, root, tag, comm);
38     }
39     Request::waitall(pipe_length, request_array, status_array);
40   }
41
42   else {
43     // Root sends data to all others
44     for (j = 0; j < num_procs; j++) {
45       if (j == rank)
46         continue;
47       else {
48         for (i = 0; i < pipe_length; i++) {
49           Request::send((char *)buff + (i * increment), segment, data_type, j, tag, comm);
50         }
51       }
52     }
53
54   }
55
56   delete[] request_array;
57   delete[] status_array;
58   return MPI_SUCCESS;
59 }
60
61 } // namespace simgrid::smpi