1 /* Copyright (c) 2013-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "colls_private.h"
9 int smpi_coll_tuned_allgather_loosely_lr(void *sbuf, int scount,
10 MPI_Datatype stype, void *rbuf,
11 int rcount, MPI_Datatype rtype,
15 int tag = COLL_TAG_ALLGATHER;
16 int i, j, send_offset, recv_offset;
17 int intra_rank, inter_rank, inter_comm_size, intra_comm_size;
18 int inter_dst, inter_src;
20 comm_size = smpi_comm_size(comm);
22 if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
23 smpi_comm_init_smp(comm);
26 if (smpi_comm_is_uniform(comm)){
27 num_core = smpi_comm_size(smpi_comm_get_intra_comm(comm));
30 if(comm_size%num_core)
31 THROWF(arg_error,0, "allgather loosely lr algorithm can't be used with non multiple of NUM_CORE=%d number of processes ! ",num_core);
33 rank = smpi_comm_rank(comm);
34 MPI_Aint rextent, sextent;
35 rextent = smpi_datatype_get_extent(rtype);
36 sextent = smpi_datatype_get_extent(stype);
37 MPI_Request inter_rrequest;
38 MPI_Request rrequest_array[128];
39 MPI_Request srequest_array[128];
40 MPI_Request inter_srequest_array[128];
43 int rrequest_count = 0;
44 int srequest_count = 0;
45 int inter_srequest_count = 0;
49 intra_rank = rank % num_core;
50 inter_rank = rank / num_core;
51 inter_comm_size = (comm_size + num_core - 1) / num_core;
52 intra_comm_size = num_core;
56 //copy corresponding message from sbuf to rbuf
57 recv_offset = rank * rextent * rcount;
58 smpi_mpi_sendrecv(sbuf, scount, stype, rank, tag,
59 (char *)rbuf + recv_offset, rcount, rtype, rank, tag, comm, &status);
62 int inter_send_offset, inter_recv_offset;
66 inter_srequest_count = 0;
68 for (i = 0; i < inter_comm_size; i++) {
70 // inter_communication
72 inter_dst = (rank + intra_comm_size) % comm_size;
73 inter_src = (rank - intra_comm_size + comm_size) % comm_size;
76 ((inter_rank - 1 - i +
77 inter_comm_size) % inter_comm_size) * intra_comm_size + intra_rank;
80 inter_comm_size) % inter_comm_size) * intra_comm_size + intra_rank;
82 inter_send_offset = dst_seg * sextent * scount;
83 inter_recv_offset = src_seg * rextent * rcount;
85 for (j = 0; j < intra_comm_size; j++) {
87 // inter communication
88 if (intra_rank == j) {
89 if (i != inter_comm_size - 1) {
91 inter_rrequest = smpi_mpi_irecv((char *)rbuf + inter_recv_offset, rcount, rtype,
92 inter_src, tag, comm);
93 inter_srequest_array[inter_srequest_count++] = smpi_mpi_isend((char *)rbuf + inter_send_offset, scount, stype,
94 inter_dst, tag, comm);
98 src = inter_rank * intra_comm_size + j;
99 dst = inter_rank * intra_comm_size + j;
103 inter_comm_size) % inter_comm_size) * intra_comm_size + j;
106 inter_comm_size) % inter_comm_size) * intra_comm_size + intra_rank;
108 send_offset = dst_seg * sextent * scount;
109 recv_offset = src_seg * rextent * rcount;
112 if (j != intra_rank) {
114 rrequest_array[rrequest_count++] = smpi_mpi_irecv((char *)rbuf + recv_offset, rcount, rtype, src, tag, comm);
115 srequest_array[srequest_count++] = smpi_mpi_isend((char *)rbuf + send_offset, scount, stype, dst, tag, comm);
121 // wait for inter communication to finish for these rounds (# of round equals num_core)
122 if (i != inter_comm_size - 1) {
123 smpi_mpi_wait(&inter_rrequest, &status);
128 smpi_mpi_waitall(rrequest_count, rrequest_array, MPI_STATUSES_IGNORE);
129 smpi_mpi_waitall(srequest_count, srequest_array, MPI_STATUSES_IGNORE);
130 smpi_mpi_waitall(inter_srequest_count, inter_srequest_array, MPI_STATUSES_IGNORE);