3 int bcast_NTSB_segment_size_in_byte = 8192;
5 int smpi_coll_tuned_bcast_NTSB(void *buf, int count, MPI_Datatype datatype,
6 int root, MPI_Comm comm)
13 MPI_Request *send_request_array;
14 MPI_Request *recv_request_array;
15 MPI_Status *send_status_array;
16 MPI_Status *recv_status_array;
19 MPI_Type_extent(datatype, &extent);
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22 MPI_Comm_size(MPI_COMM_WORLD, &size);
24 /* source node and destination nodes (same through out the functions) */
25 int from = (rank - 1) / 2;
26 int to_left = rank * 2 + 1;
27 int to_right = rank * 2 + 2;
33 /* segment is segment size in number of elements (not bytes) */
34 int segment = bcast_NTSB_segment_size_in_byte / extent;
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 */
49 MPI_Send(buf, count, datatype, 0, tag, comm);
50 } else if (rank == 0) {
51 MPI_Recv(buf, count, datatype, root, tag, comm, &status);
55 /* when a message is smaller than a block size => no pipeline */
56 if (count <= segment) {
60 /* case root has only a left child */
62 MPI_Send(buf, count, datatype, to_left, tag, comm);
64 /* case root has both left and right children */
66 MPI_Send(buf, count, datatype, to_left, tag, comm);
67 MPI_Send(buf, count, datatype, to_right, tag, comm);
71 /* case: leaf ==> receive only */
72 else if (to_left == -1) {
73 MPI_Recv(buf, count, datatype, from, tag, comm, &status);
76 /* case: intermidiate node with only left child ==> relay message */
77 else if (to_right == -1) {
78 MPI_Recv(buf, count, datatype, from, tag, comm, &status);
79 MPI_Send(buf, count, datatype, to_left, tag, comm);
82 /* case: intermidiate node with both left and right children ==> relay message */
84 MPI_Recv(buf, count, datatype, from, tag, comm, &status);
85 MPI_Send(buf, count, datatype, to_left, tag, comm);
86 MPI_Send(buf, count, datatype, to_right, tag, comm);
94 (MPI_Request *) malloc(2 * (size + pipe_length) * sizeof(MPI_Request));
96 (MPI_Request *) malloc((size + pipe_length) * sizeof(MPI_Request));
98 (MPI_Status *) malloc(2 * (size + pipe_length) * sizeof(MPI_Status));
100 (MPI_Status *) malloc((size + pipe_length) * sizeof(MPI_Status));
106 /* case root has only a left child */
107 if (to_right == -1) {
108 for (i = 0; i < pipe_length; i++) {
109 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_left,
110 tag + i, comm, &send_request_array[i]);
112 MPI_Waitall((pipe_length), send_request_array, send_status_array);
114 /* case root has both left and right children */
116 for (i = 0; i < pipe_length; i++) {
117 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_left,
118 tag + i, comm, &send_request_array[i]);
119 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_right,
120 tag + i, comm, &send_request_array[i + pipe_length]);
122 MPI_Waitall((2 * pipe_length), send_request_array, send_status_array);
126 /* case: leaf ==> receive only */
127 else if (to_left == -1) {
128 for (i = 0; i < pipe_length; i++) {
129 MPI_Irecv((char *) buf + (i * increment), segment, datatype, from,
130 tag + i, comm, &recv_request_array[i]);
132 MPI_Waitall((pipe_length), recv_request_array, recv_status_array);
135 /* case: intermidiate node with only left child ==> relay message */
136 else if (to_right == -1) {
137 for (i = 0; i < pipe_length; i++) {
138 MPI_Irecv((char *) buf + (i * increment), segment, datatype, from,
139 tag + i, comm, &recv_request_array[i]);
141 for (i = 0; i < pipe_length; i++) {
142 MPI_Wait(&recv_request_array[i], &status);
143 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_left,
144 tag + i, comm, &send_request_array[i]);
146 MPI_Waitall(pipe_length, send_request_array, send_status_array);
149 /* case: intermidiate node with both left and right children ==> relay message */
151 for (i = 0; i < pipe_length; i++) {
152 MPI_Irecv((char *) buf + (i * increment), segment, datatype, from,
153 tag + i, comm, &recv_request_array[i]);
155 for (i = 0; i < pipe_length; i++) {
156 MPI_Wait(&recv_request_array[i], &status);
157 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_left,
158 tag + i, comm, &send_request_array[i]);
159 MPI_Isend((char *) buf + (i * increment), segment, datatype, to_right,
160 tag + i, comm, &send_request_array[i + pipe_length]);
162 MPI_Waitall((2 * pipe_length), send_request_array, send_status_array);
165 free(send_request_array);
166 free(recv_request_array);
167 free(send_status_array);
168 free(recv_status_array);
171 /* when count is not divisible by block size, use default BCAST for the remainder */
172 if ((remainder != 0) && (count > segment)) {
173 MPI_Bcast((char *) buf + (pipe_length * increment), remainder, datatype,