1 #include "colls_private.h"
3 * implemented by Pitch Patarasuk, 07/01/2007
5 //#include <star-reduction.c>
7 /* change number of core per smp-node
8 we assume that number of core per process will be the same for all implementations */
14 This fucntion performs all-reduce operation as follow.
15 1) binomial_tree reduce inside each SMP node
16 2) reduce-scatter -inter between root of each SMP node
17 3) allgather - inter between root of each SMP node
18 4) binomial_tree bcast inside each SMP node
20 int smpi_coll_tuned_allreduce_smp_rsag_rab(void *sbuf, void *rbuf, int count,
21 MPI_Datatype dtype, MPI_Op op,
26 int tag = COLL_TAG_ALLREDUCE;
29 int num_core = NUM_CORE;
31 comm_size = smpi_comm_size(comm);
32 rank = smpi_comm_rank(comm);
34 extent = smpi_datatype_get_extent(dtype);
35 tmp_buf = (void *) xbt_malloc(count * extent);
37 int intra_rank, inter_rank;
38 intra_rank = rank % num_core;
39 inter_rank = rank / num_core;
41 //printf("node %d intra_rank = %d, inter_rank = %d\n", rank, intra_rank, inter_rank);
43 int inter_comm_size = (comm_size + num_core - 1) / num_core;
45 smpi_mpi_sendrecv(sbuf, count, dtype, rank, tag,
46 rbuf, count, dtype, rank, tag, comm, &status);
48 // SMP_binomial_reduce
50 while (mask < num_core) {
51 if ((mask & intra_rank) == 0) {
52 src = (inter_rank * num_core) + (intra_rank | mask);
53 // if (src < ((inter_rank + 1) * num_core)) {
54 if (src < comm_size) {
55 smpi_mpi_recv(tmp_buf, count, dtype, src, tag, comm, &status);
56 smpi_op_apply(op, tmp_buf, rbuf, &count, &dtype);
57 //printf("Node %d recv from node %d when mask is %d\n", rank, src, mask);
61 dst = (inter_rank * num_core) + (intra_rank & (~mask));
62 smpi_mpi_send(rbuf, count, dtype, dst, tag, comm);
63 //printf("Node %d send to node %d when mask is %d\n", rank, dst, mask);
70 // INTER: reduce-scatter
71 if (intra_rank == 0) {
73 int dst, base_offset, send_base_offset, recv_base_offset, recv_chunk;
74 int curr_count, i, recv_offset, send_offset;
78 recv_chunk = extent * count / (comm_size / num_core);
82 curr_count = count / 2;
88 while (mask < (comm_size / num_core)) {
89 dst = inter_rank ^ mask;
92 send_base_offset = base_offset;
95 if (inter_rank & mask) {
96 recv_base_offset = base_offset + curr_count;
97 send_base_offset = base_offset;
98 base_offset = recv_base_offset;
102 recv_base_offset = base_offset;
103 send_base_offset = base_offset + curr_count;
105 send_offset = send_base_offset * extent;
106 recv_offset = recv_base_offset * extent;
109 // printf("node %d send to %d in phase %d s_offset = %d r_offset = %d count = %d\n",rank,dst,phase, send_offset, recv_offset, curr_count);
111 smpi_mpi_sendrecv((char *)rbuf + send_offset, curr_count, dtype, (dst * num_core), tag,
112 tmp_buf, curr_count, dtype, (dst * num_core), tag,
115 smpi_op_apply(op, tmp_buf, (char *)rbuf + recv_offset, &curr_count, &dtype);
125 int size = (comm_size / num_core) / 2;
128 while (mask < (comm_size / num_core)) {
129 if (inter_rank & mask) {
141 // destination pair for both send and recv
142 dst = inter_rank ^ mask;
145 send_base_offset = base_offset;
146 if (inter_rank & mask) {
147 recv_base_offset = base_offset - i;
150 recv_base_offset = base_offset + i;
152 send_offset = send_base_offset * recv_chunk;
153 recv_offset = recv_base_offset * recv_chunk;
156 //printf("node %d send to %d in phase %d s_offset = %d r_offset = %d count = %d\n",rank,dst,phase, send_offset, recv_offset, curr_count);
158 smpi_mpi_sendrecv((char *)rbuf + send_offset, curr_count, dtype, (dst * num_core), tag,
159 (char *)rbuf + recv_offset, curr_count, dtype, (dst * num_core), tag,
172 // intra SMP binomial bcast
174 int num_core_in_current_smp = num_core;
175 if (inter_rank == (inter_comm_size - 1)) {
176 num_core_in_current_smp = comm_size - (inter_rank * num_core);
178 // printf("Node %d num_core = %d\n",rank, num_core_in_current_smp);
180 while (mask < num_core_in_current_smp) {
181 if (intra_rank & mask) {
182 src = (inter_rank * num_core) + (intra_rank - mask);
183 //printf("Node %d recv from node %d when mask is %d\n", rank, src, mask);
184 smpi_mpi_recv(rbuf, count, dtype, src, tag, comm, &status);
191 //printf("My rank = %d my mask = %d\n", rank,mask);
194 dst = (inter_rank * num_core) + (intra_rank + mask);
195 if (dst < comm_size) {
196 //printf("Node %d send to node %d when mask is %d\n", rank, dst, mask);
197 smpi_mpi_send(rbuf, count, dtype, dst, tag, comm);