Logo AND Algorithmique Numérique Distribuée

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