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)
35 int tag = COLL_TAG_ALLREDUCE;
39 int num_core = simcall_host_get_core(SIMIX_host_self());
40 // do we use the default one or the number of cores in the platform ?
41 // if the number of cores is one, the platform may be simulated with 1 node = 1 core
42 if (num_core == 1) num_core = NUM_CORE;
45 comm_size=smpi_comm_size(comm);
46 rank=smpi_comm_rank(comm);
48 smpi_datatype_extent(dtype, &lb, &extent);
49 tmp_buf = (void *) xbt_malloc(count * extent);
51 /* compute intra and inter ranking */
52 int intra_rank, inter_rank;
53 intra_rank = rank % num_core;
54 inter_rank = rank / num_core;
56 /* size of processes participate in intra communications =>
57 should be equal to number of machines */
58 int inter_comm_size = (comm_size + num_core - 1) / num_core;
60 /* copy input buffer to output buffer */
61 smpi_mpi_sendrecv(send_buf, count, dtype, rank, tag,
62 recv_buf, count, dtype, rank, tag, comm, &status);
64 /* start binomial reduce intra communication inside each SMP node */
66 while (mask < num_core) {
67 if ((mask & intra_rank) == 0) {
68 src = (inter_rank * num_core) + (intra_rank | mask);
69 if (src < comm_size) {
70 smpi_mpi_recv(tmp_buf, count, dtype, src, tag, comm, &status);
71 smpi_op_apply(op, tmp_buf, recv_buf, &count, &dtype);
74 dst = (inter_rank * num_core) + (intra_rank & (~mask));
75 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
81 /* start binomial reduce inter-communication between each SMP nodes:
82 each node only have one process that can communicate to other nodes */
83 if (intra_rank == 0) {
85 while (mask < inter_comm_size) {
86 if ((mask & inter_rank) == 0) {
87 src = (inter_rank | mask) * num_core;
88 if (src < comm_size) {
89 smpi_mpi_recv(tmp_buf, count, dtype, src, tag, comm, &status);
90 smpi_op_apply(op, tmp_buf, recv_buf, &count, &dtype);
93 dst = (inter_rank & (~mask)) * num_core;
94 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
101 /* start binomial broadcast inter-communication between each SMP nodes:
102 each node only have one process that can communicate to other nodes */
103 if (intra_rank == 0) {
105 while (mask < inter_comm_size) {
106 if (inter_rank & mask) {
107 src = (inter_rank - mask) * num_core;
108 smpi_mpi_recv(recv_buf, count, dtype, src, tag, comm, &status);
116 if (inter_rank < inter_comm_size) {
117 dst = (inter_rank + mask) * num_core;
118 if (dst < comm_size) {
119 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);
126 /* start binomial broadcast intra-communication inside each SMP nodes */
127 int num_core_in_current_smp = num_core;
128 if (inter_rank == (inter_comm_size - 1)) {
129 num_core_in_current_smp = comm_size - (inter_rank * num_core);
132 while (mask < num_core_in_current_smp) {
133 if (intra_rank & mask) {
134 src = (inter_rank * num_core) + (intra_rank - mask);
135 smpi_mpi_recv(recv_buf, count, dtype, src, tag, comm, &status);
143 dst = (inter_rank * num_core) + (intra_rank + mask);
144 if (dst < comm_size) {
145 smpi_mpi_send(recv_buf, count, dtype, dst, tag, comm);