1 #include "colls_private.h"
3 static int bcast_NTSL_segment_size_in_byte = 8192;
5 /* Non-topology-specific pipelined linear-bcast function
6 0->1, 1->2 ,2->3, ....., ->last node : in a pipeline fashion
8 int smpi_coll_tuned_bcast_NTSL(void *buf, int count, MPI_Datatype datatype,
9 int root, MPI_Comm comm)
11 int tag = COLL_TAG_BCAST;
14 MPI_Request *send_request_array;
15 MPI_Request *recv_request_array;
16 MPI_Status *send_status_array;
17 MPI_Status *recv_status_array;
21 extent = smpi_datatype_get_extent(datatype);
23 rank = smpi_comm_rank(comm);
24 size = smpi_comm_size(comm);
26 /* source node and destination nodes (same through out the functions) */
27 int to = (rank + 1) % size;
28 int from = (rank + size - 1) % size;
30 /* segment is segment size in number of elements (not bytes) */
31 int segment = bcast_NTSL_segment_size_in_byte / extent;
34 int pipe_length = count / segment;
36 /* use for buffer offset for sending and receiving data = segment size in byte */
37 int increment = segment * extent;
39 /* if the input size is not divisible by segment size =>
40 the small remainder will be done with native implementation */
41 int remainder = count % segment;
43 /* if root is not zero send to rank zero first
44 this can be modified to make it faster by using logical src, dst.
48 smpi_mpi_send(buf, count, datatype, 0, tag, comm);
49 } else if (rank == 0) {
50 smpi_mpi_recv(buf, count, datatype, root, tag, comm, &status);
54 /* when a message is smaller than a block size => no pipeline */
55 if (count <= segment) {
57 smpi_mpi_send(buf, count, datatype, to, tag, comm);
58 } else if (rank == (size - 1)) {
59 request = smpi_mpi_irecv(buf, count, datatype, from, tag, comm);
60 smpi_mpi_wait(&request, &status);
62 request = smpi_mpi_irecv(buf, count, datatype, from, tag, comm);
63 smpi_mpi_wait(&request, &status);
64 smpi_mpi_send(buf, count, datatype, to, tag, comm);
72 (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request));
74 (MPI_Request *) xbt_malloc((size + pipe_length) * sizeof(MPI_Request));
76 (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status));
78 (MPI_Status *) xbt_malloc((size + pipe_length) * sizeof(MPI_Status));
82 for (i = 0; i < pipe_length; i++) {
83 send_request_array[i] = smpi_mpi_isend((char *) buf + (i * increment), segment, datatype, to,
86 smpi_mpi_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] = smpi_mpi_irecv((char *) buf + (i * increment), segment, datatype, from,
95 smpi_mpi_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] = smpi_mpi_irecv((char *) buf + (i * increment), segment, datatype, from,
104 for (i = 0; i < pipe_length; i++) {
105 smpi_mpi_wait(&recv_request_array[i], &status);
106 send_request_array[i] = smpi_mpi_isend((char *) buf + (i * increment), segment, datatype, to,
109 smpi_mpi_waitall((pipe_length), send_request_array, send_status_array);
112 free(send_request_array);
113 free(recv_request_array);
114 free(send_status_array);
115 free(recv_status_array);
118 /* when count is not divisible by block size, use default BCAST for the remainder */
119 if ((remainder != 0) && (count > segment)) {
120 XBT_WARN("MPI_bcast_arrival_NTSL use default MPI_bcast.");
121 smpi_mpi_bcast((char *) buf + (pipe_length * increment), remainder, datatype,