1 /* Copyright (c) 2013-2022. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "../colls_private.hpp"
9 static int bcast_NTSL_segment_size_in_byte = 8192;
11 /* Non-topology-specific pipelined linear-bcast function
12 0->1, 1->2 ,2->3, ....., ->last node : in a pipeline fashion
14 namespace simgrid::smpi {
15 int bcast__NTSL_Isend(void *buf, int count, MPI_Datatype datatype,
16 int root, MPI_Comm comm)
18 int tag = COLL_TAG_BCAST;
24 extent = datatype->get_extent();
29 /* source node and destination nodes (same through out the functions) */
30 int to = (rank + 1) % size;
31 int from = (rank + size - 1) % size;
33 /* segment is segment size in number of elements (not bytes) */
34 int segment = bcast_NTSL_segment_size_in_byte / extent;
35 segment = segment == 0 ? 1 :segment;
37 int pipe_length = count / segment;
39 /* use for buffer offset for sending and receiving data = segment size in byte */
40 int increment = segment * extent;
42 /* if the input size is not divisible by segment size =>
43 the small remainder will be done with native implementation */
44 int remainder = count % segment;
46 /* if root is not zero send to rank zero first
47 this can be modified to make it faster by using logical src, dst.
51 Request::send(buf, count, datatype, 0, tag, comm);
52 } else if (rank == 0) {
53 Request::recv(buf, count, datatype, root, tag, comm, &status);
57 /* when a message is smaller than a block size => no pipeline */
58 if (count <= segment) {
60 Request::send(buf, count, datatype, to, tag, comm);
61 } else if (rank == (size - 1)) {
62 request = Request::irecv(buf, count, datatype, from, tag, comm);
63 Request::wait(&request, &status);
65 request = Request::irecv(buf, count, datatype, from, tag, comm);
66 Request::wait(&request, &status);
67 Request::send(buf, count, datatype, to, tag, comm);
74 auto* send_request_array = new MPI_Request[size + pipe_length];
75 auto* recv_request_array = new MPI_Request[size + pipe_length];
76 auto* send_status_array = new MPI_Status[size + pipe_length];
77 auto* recv_status_array = new MPI_Status[size + pipe_length];
81 for (i = 0; i < pipe_length; i++) {
82 send_request_array[i] = Request::isend((char *) buf + (i * increment), segment, datatype, to,
85 Request::waitall((pipe_length), send_request_array, send_status_array);
88 /* last node only receive data */
89 else if (rank == (size - 1)) {
90 for (i = 0; i < pipe_length; i++) {
91 recv_request_array[i] = Request::irecv((char *) buf + (i * increment), segment, datatype, from,
94 Request::waitall((pipe_length), recv_request_array, recv_status_array);
97 /* intermediate nodes relay (receive, then send) data */
99 for (i = 0; i < pipe_length; i++) {
100 recv_request_array[i] = Request::irecv((char *) buf + (i * increment), segment, datatype, from,
103 for (i = 0; i < pipe_length; i++) {
104 Request::wait(&recv_request_array[i], &status);
105 send_request_array[i] = Request::isend((char *) buf + (i * increment), segment, datatype, to,
108 Request::waitall((pipe_length), send_request_array, send_status_array);
111 delete[] send_request_array;
112 delete[] recv_request_array;
113 delete[] send_status_array;
114 delete[] recv_status_array;
117 if ((remainder != 0) && (count > segment)) {
118 XBT_INFO("MPI_bcast_NTSL_Isend_nb: count is not divisible by block size, use default MPI_bcast for remainder.");
119 colls::bcast((char*)buf + (pipe_length * increment), remainder, datatype, root, comm);
125 } // namespace simgrid::smpi