1 /* Copyright (c) 2013-2021. 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
16 int bcast__NTSL_Isend(void *buf, int count, MPI_Datatype datatype,
17 int root, MPI_Comm comm)
19 int tag = COLL_TAG_BCAST;
25 extent = datatype->get_extent();
30 /* source node and destination nodes (same through out the functions) */
31 int to = (rank + 1) % size;
32 int from = (rank + size - 1) % size;
34 /* segment is segment size in number of elements (not bytes) */
35 int segment = bcast_NTSL_segment_size_in_byte / extent;
36 segment = segment == 0 ? 1 :segment;
38 int pipe_length = count / segment;
40 /* use for buffer offset for sending and receiving data = segment size in byte */
41 int increment = segment * extent;
43 /* if the input size is not divisible by segment size =>
44 the small remainder will be done with native implementation */
45 int remainder = count % segment;
47 /* if root is not zero send to rank zero first
48 this can be modified to make it faster by using logical src, dst.
52 Request::send(buf, count, datatype, 0, tag, comm);
53 } else if (rank == 0) {
54 Request::recv(buf, count, datatype, root, tag, comm, &status);
58 /* when a message is smaller than a block size => no pipeline */
59 if (count <= segment) {
61 Request::send(buf, count, datatype, to, tag, comm);
62 } else if (rank == (size - 1)) {
63 request = Request::irecv(buf, count, datatype, from, tag, comm);
64 Request::wait(&request, &status);
66 request = Request::irecv(buf, count, datatype, from, tag, comm);
67 Request::wait(&request, &status);
68 Request::send(buf, count, datatype, to, tag, comm);
75 auto* send_request_array = new MPI_Request[size + pipe_length];
76 auto* recv_request_array = new MPI_Request[size + pipe_length];
77 auto* send_status_array = new MPI_Status[size + pipe_length];
78 auto* recv_status_array = new MPI_Status[size + pipe_length];
82 for (i = 0; i < pipe_length; i++) {
83 send_request_array[i] = Request::isend((char *) buf + (i * increment), segment, datatype, to,
86 Request::waitall((pipe_length), send_request_array, send_status_array);
89 /* last node only receive data */
90 else if (rank == (size - 1)) {
91 for (i = 0; i < pipe_length; i++) {
92 recv_request_array[i] = Request::irecv((char *) buf + (i * increment), segment, datatype, from,
95 Request::waitall((pipe_length), recv_request_array, recv_status_array);
98 /* intermediate nodes relay (receive, then send) data */
100 for (i = 0; i < pipe_length; i++) {
101 recv_request_array[i] = Request::irecv((char *) buf + (i * increment), segment, datatype, from,
104 for (i = 0; i < pipe_length; i++) {
105 Request::wait(&recv_request_array[i], &status);
106 send_request_array[i] = Request::isend((char *) buf + (i * increment), segment, datatype, to,
109 Request::waitall((pipe_length), send_request_array, send_status_array);
112 delete[] send_request_array;
113 delete[] recv_request_array;
114 delete[] send_status_array;
115 delete[] recv_status_array;
118 if ((remainder != 0) && (count > segment)) {
119 XBT_INFO("MPI_bcast_NTSL_Isend_nb: count is not divisible by block size, use default MPI_bcast for remainder.");
120 colls::bcast((char*)buf + (pipe_length * increment), remainder, datatype, root, comm);