1 #include "colls_private.h"
2 /* IMPLEMENTED BY PITCH PATARASUK
3 Non-topoloty-specific (however, number of cores/node need to be changed)
4 all-reduce operation designed for smp clusters
5 It uses 2-layer communication: binomial for both intra-communication
8 /* change number of core per smp-node
9 we assume that number of core per process will be the same for all implementations */
15 Use -DMPICH2 if this code does not compile.
16 MPICH1 code also work on MPICH2 on our cluster and the performance are similar.
17 This code assume commutative and associative reduce operator (MPI_SUM, MPI_MAX, etc).
20 //#include <star-reduction.c>
23 This fucntion performs all-reduce operation as follow.
24 1) binomial_tree reduce inside each SMP node
25 2) binomial_tree reduce intra-communication between root of each SMP node
26 3) binomial_tree bcast intra-communication between root of each SMP node
27 4) binomial_tree bcast inside each SMP node
29 int smpi_coll_tuned_allreduce_smp_binomial(void *send_buf, void *recv_buf,
30 int count, MPI_Datatype dtype,
31 MPI_Op op, MPI_Comm comm)
37 int num_core = NUM_CORE;
40 comm_size=smpi_comm_size(comm);
41 rank=smpi_comm_rank(comm);
43 smpi_datatype_extent(dtype, &lb, &extent);
44 tmp_buf = (void *) xbt_malloc(count * extent);
46 /* compute intra and inter ranking */
47 int intra_rank, inter_rank;
48 intra_rank = rank % num_core;
49 inter_rank = rank / num_core;
51 /* size of processes participate in intra communications =>
52 should be equal to number of machines */
53 int inter_comm_size = (comm_size + num_core - 1) / num_core;
55 /* copy input buffer to output buffer */
56 smpi_mpi_sendrecv(send_buf, count, dtype, rank, tag,
57 recv_buf, count, dtype, rank, tag, comm, &status);
59 /* start binomial reduce intra communication inside each SMP node */
61 while (mask < num_core) {
62 if ((mask & intra_rank) == 0) {
63 src = (inter_rank * num_core) + (intra_rank | mask);
64 if (src < comm_size) {
65 smpi_mpi_recv(tmp_buf, count, dtype, src, tag, comm, &status);
66 smpi_op_apply(op, tmp_buf, recv_buf, &count, &dtype);
69 dst = (inter_rank * num_core) + (intra_rank & (~mask));
70 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
76 /* start binomial reduce inter-communication between each SMP nodes:
77 each node only have one process that can communicate to other nodes */
78 if (intra_rank == 0) {
80 while (mask < inter_comm_size) {
81 if ((mask & inter_rank) == 0) {
82 src = (inter_rank | mask) * num_core;
83 if (src < comm_size) {
84 smpi_mpi_recv(tmp_buf, count, dtype, src, tag, comm, &status);
85 smpi_op_apply(op, tmp_buf, recv_buf, &count, &dtype);
88 dst = (inter_rank & (~mask)) * num_core;
89 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
96 /* start binomial broadcast inter-communication between each SMP nodes:
97 each node only have one process that can communicate to other nodes */
98 if (intra_rank == 0) {
100 while (mask < inter_comm_size) {
101 if (inter_rank & mask) {
102 src = (inter_rank - mask) * num_core;
103 smpi_mpi_recv(recv_buf, count, dtype, src, tag, comm, &status);
111 if (inter_rank < inter_comm_size) {
112 dst = (inter_rank + mask) * num_core;
113 if (dst < comm_size) {
114 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
121 /* start binomial broadcast intra-communication inside each SMP nodes */
122 int num_core_in_current_smp = num_core;
123 if (inter_rank == (inter_comm_size - 1)) {
124 num_core_in_current_smp = comm_size - (inter_rank * num_core);
127 while (mask < num_core_in_current_smp) {
128 if (intra_rank & mask) {
129 src = (inter_rank * num_core) + (intra_rank - mask);
130 smpi_mpi_recv(recv_buf, count, dtype, src, tag, comm, &status);
138 dst = (inter_rank * num_core) + (intra_rank + mask);
139 if (dst < comm_size) {
140 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);