Debian Codegraph @

src/mpi/coll/iallgather/iallgather_tsp_recexch.c

raw symbols SCIP
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "mpiimpl.h"cxx . . $ `<file>/src/include/mpiimpl.h`/
7 #include "recexchalgo.h"cxx . . $ `<file>/src/mpi/coll/algorithms/recexchalgo/recexchalgo.h`/
8
9 static int MPIR_TSP_Iallgather_sched_intra_recexch_data_exchangecxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_data_exchange(bb1217bfe2f14ab2).(int rank, int nranks, int k,
10 int p_of_k, int log_pofk, int T,
11 void *recvbuf,
12 MPI_Datatypecxx . . $ MPI_Datatype# recvtype,
13 MPI_Aintcxx . . $ MPI_Aint# recv_extent,
14 MPI_Aintcxx . . $ MPI_Aint# recvcount, int tag,
15 MPIR_Commcxx . . $ MPIR_Comm# * comm,
16 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
17 {
18 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
19 int partner, offset, count, vtx_id;
20 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
21
22 /* get the partner with whom I should exchange data */
23 partner = MPII_Recexchalgo_reverse_digits_step2cxx . . $ MPII_Recexchalgo_reverse_digits_step2(2326284602b0bb2d).(rank, nranks, k);
24 if (rank != partner) {
25 /* calculate offset and count of the data to be sent to the partner */
26 MPII_Recexchalgo_get_count_and_offsetcxx . . $ MPII_Recexchalgo_get_count_and_offset(38f85d30b56b1458).(rank, 0, k, nranks, &count, &offset);
27 MPI_Aintcxx . . $ MPI_Aint# send_offset = offset * recv_extent * recvcount;
28 MPL_DBG_MSG_FMTcxx . . $ `src/mpl/include/mpl_dbg.h:100:9`!(MPIR_DBG_COLL, VERBOSE,
29 (MPL_DBG_FDEST, "data exchange with %d send_offset %d count %d", partner,
30 send_offset, count));
31 /* send my data to partner */
32 mpi_errno =
33 MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(((char *) recvbuf + send_offset), count * recvcount, recvtype,
34 partner, tag, comm, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
35
36 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
37
38 /* calculate offset and count of the data to be received from the partner */
39 MPII_Recexchalgo_get_count_and_offsetcxx . . $ MPII_Recexchalgo_get_count_and_offset(38f85d30b56b1458).(partner, 0, k, nranks, &count, &offset);
40 MPI_Aintcxx . . $ MPI_Aint# recv_offset = offset * recv_extent * recvcount;
41 MPL_DBG_MSG_FMTcxx . . $ `src/mpl/include/mpl_dbg.h:100:9`!(MPIR_DBG_COLL, VERBOSE,
42 (MPL_DBG_FDEST, "data exchange with %d recv_offset %d count %d", partner,
43 recv_offset, count));
44 /* recv data from my partner */
45 mpi_errno =
46 MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).(((char *) recvbuf + recv_offset), count * recvcount, recvtype,
47 partner, tag, comm, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
48 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
49 }
50
51 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
52
53 fn_exit:
54 return mpi_errno;
55 fn_fail:
56 goto fn_exit;
57 }
58
59
60 static int MPIR_TSP_Iallgather_sched_intra_recexch_step1cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step1(350b4535767051b5).(int step1_sendto, int *step1_recvfrom,
61 int step1_nrecvs, int is_inplace, int rank,
62 int tag, const void *sendbuf,
63 void *recvbuf, MPI_Aintcxx . . $ MPI_Aint# recv_extent,
64 MPI_Aintcxx . . $ MPI_Aint# recvcount, MPI_Datatypecxx . . $ MPI_Datatype# recvtype,
65 int n_invtcs, int *invtx, MPIR_Commcxx . . $ MPIR_Comm# * comm,
66 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
67 {
68 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
69 int i;
70 int vtx_id;
71 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
72
73 if (step1_sendto != -1) { /* non-participating rank sends the data to a partcipating rank */
74 void *buf_to_send;
75 MPI_Aintcxx . . $ MPI_Aint# send_offset = rank * recv_extent * recvcount;
76 if (is_inplace)
77 buf_to_send = ((char *) recvbuf + send_offset);
78 else
79 buf_to_send = (void *) sendbuf;
80 mpi_errno =
81 MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(buf_to_send, recvcount, recvtype, step1_sendto, tag, comm, sched,
82 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
83 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
84 } else {
85 for (i = 0; i < step1_nrecvs; i++) { /* participating rank gets the data from non-participating rank */
86 MPI_Aintcxx . . $ MPI_Aint# recv_offset = step1_recvfrom[i] * recv_extent * recvcount;
87 mpi_errno = MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).(((char *) recvbuf + recv_offset), recvcount, recvtype,
88 step1_recvfrom[i], tag, comm, sched, n_invtcs, invtx,
89 &vtx_id);
90 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
91 }
92 }
93
94 fn_exit:
95 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
96 return mpi_errno;
97 fn_fail:
98 goto fn_exit;
99 }
100
101
102 static int MPIR_TSP_Iallgather_sched_intra_recexch_step2cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step2(76b786d5e53fdf32).(int step1_sendto, int step2_nphases,
103 int **step2_nbrs, int rank, int nranks,
104 int k, int p_of_k, int log_pofk, int T,
105 int *nrecvs_, int **recv_id_, int tag,
106 void *recvbuf, MPI_Aintcxx . . $ MPI_Aint# recv_extent,
107 MPI_Aintcxx . . $ MPI_Aint# recvcount, MPI_Datatypecxx . . $ MPI_Datatype# recvtype,
108 int is_dist_halving, MPIR_Commcxx . . $ MPIR_Comm# * comm,
109 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
110 {
111 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
112 int phase, i, j, count, nbr, offset, rank_for_offset;
113 int *recv_id = *recv_id_;
114 int nrecvs = 0, vtx_id;
115 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
116
117 if (is_dist_halving == 1) {
118 phase = step2_nphases - 1;
119 } else {
120 phase = 0;
121 }
122
123 for (j = 0; j < step2_nphases && step1_sendto == -1; j++) {
124 /* send data to all the neighbors */
125 for (i = 0; i < k - 1; i++) {
126 nbr = step2_nbrs[phase][i];
127 if (is_dist_halving == 1)
128 rank_for_offset = MPII_Recexchalgo_reverse_digits_step2cxx . . $ MPII_Recexchalgo_reverse_digits_step2(2326284602b0bb2d).(rank, nranks, k);
129 else
130 rank_for_offset = rank;
131 MPII_Recexchalgo_get_count_and_offsetcxx . . $ MPII_Recexchalgo_get_count_and_offset(38f85d30b56b1458).(rank_for_offset, j, k, nranks, &count, &offset);
132 MPI_Aintcxx . . $ MPI_Aint# send_offset = offset * recv_extent * recvcount;
133 mpi_errno =
134 MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(((char *) recvbuf + send_offset), count * recvcount, recvtype,
135 nbr, tag, comm, sched, nrecvs, recv_id, &vtx_id);
136 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
137 MPL_DBG_MSG_FMTcxx . . $ `src/mpl/include/mpl_dbg.h:100:9`!(MPIR_DBG_COLL, VERBOSE,
138 (MPL_DBG_FDEST,
139 "phase %d nbr is %d send offset %d count %d depend on %d", phase,
140 nbr, send_offset, count, ((k - 1) * j)));
141 }
142 /* receive from the neighbors */
143 for (i = 0; i < k - 1; i++) {
144 nbr = step2_nbrs[phase][i];
145 if (is_dist_halving == 1)
146 rank_for_offset = MPII_Recexchalgo_reverse_digits_step2cxx . . $ MPII_Recexchalgo_reverse_digits_step2(2326284602b0bb2d).(nbr, nranks, k);
147 else
148 rank_for_offset = nbr;
149 MPII_Recexchalgo_get_count_and_offsetcxx . . $ MPII_Recexchalgo_get_count_and_offset(38f85d30b56b1458).(rank_for_offset, j, k, nranks, &count, &offset);
150 MPI_Aintcxx . . $ MPI_Aint# recv_offset = offset * recv_extent * recvcount;
151 mpi_errno =
152 MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).(((char *) recvbuf + recv_offset), count * recvcount, recvtype,
153 nbr, tag, comm, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
154
155 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
156
157 recv_id[j * (k - 1) + i] = vtx_id;
158 nrecvs++;
159 MPL_DBG_MSG_FMTcxx . . $ `src/mpl/include/mpl_dbg.h:100:9`!(MPIR_DBG_COLL, VERBOSE,
160 (MPL_DBG_FDEST,
161 "phase %d recv from %d recv offset %d cur_count %d recv returns id[%d] %d",
162 phase, nbr, recv_offset, count, j * (k - 1) + i,
163 recv_id[j * (k - 1) + i]));
164 }
165 if (is_dist_halving == 1)
166 phase--;
167 else
168 phase++;
169 }
170
171 fn_exit:
172 *nrecvs_ = nrecvs;
173 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
174 return mpi_errno;
175 fn_fail:
176 goto fn_exit;
177 }
178
179
180 static int MPIR_TSP_Iallgather_sched_intra_recexch_step3cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step3(b5c1f540157ce9d9).(int step1_sendto, int *step1_recvfrom,
181 int step1_nrecvs, int step2_nphases,
182 void *recvbuf, MPI_Aintcxx . . $ MPI_Aint# recvcount,
183 int nranks, int k, int nrecvs,
184 int *recv_id, int tag,
185 MPI_Datatypecxx . . $ MPI_Datatype# recvtype, MPIR_Commcxx . . $ MPIR_Comm# * comm,
186 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
187 {
188 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
189 int i, vtx_id;
190 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
191
192 if (step1_sendto != -1) {
193 mpi_errno =
194 MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).(recvbuf, recvcount * nranks, recvtype, step1_sendto, tag, comm,
195 sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
196 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
197 }
198
199 for (i = 0; i < step1_nrecvs; i++) {
200 mpi_errno = MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(recvbuf, recvcount * nranks, recvtype, step1_recvfrom[i],
201 tag, comm, sched, nrecvs, recv_id, &vtx_id);
202 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
203 }
204
205 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
206
207 fn_exit:
208 return mpi_errno;
209 fn_fail:
210 goto fn_exit;
211 }
212
213
214 /* Routine to schedule a recursive exchange based allgather. The algorithm is based
215 * on the recursive doubling algorithm described by Thakur et al, "Optimization of
216 * Collective Communication Operations in MPICH", 2005. The recursive doubling
217 * algorithm has been extended for any radix k. A variant of the algorithm called
218 * as distance halving (selected by setting is_dist_halving=1) is based on the
219 * paper, Sack et al, "Faster topology-aware collective algorithms through
220 * non-minimal communication", 2012.
221 * */
222 int MPIR_TSP_Iallgather_sched_intra_recexchcxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch(a7e8e0149b3b4d80).(const void *sendbuf, MPI_Aintcxx . . $ MPI_Aint# sendcount,
223 MPI_Datatypecxx . . $ MPI_Datatype# sendtype, void *recvbuf,
224 MPI_Aintcxx . . $ MPI_Aint# recvcount, MPI_Datatypecxx . . $ MPI_Datatype# recvtype,
225 MPIR_Commcxx . . $ MPIR_Comm# * comm, int is_dist_halving, int k,
226 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
227 {
228 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
229 int is_inplace, i;
230 int nranks, rank;
231 MPI_Aintcxx . . $ MPI_Aint# recv_extent;
232 MPI_Aintcxx . . $ MPI_Aint# recv_lb, true_extent;
233 int step1_sendto = -1, step2_nphases = 0, step1_nrecvs = 0, p_of_k, T;
234 int dtcopy_id, n_invtcs = 0, invtx;
235 int is_instep2, log_pofk;
236 int *step1_recvfrom;
237 int **step2_nbrs;
238 int nrecvs;
239 int *recv_id;
240 int tag;
241 MPIR_CHKLMEM_DECLcxx . . $ `src/include/mpir_mem.h:108:9`!();
242
243 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
244
245 /* For correctness, transport based collectives need to get the
246 * tag from the same pool as schedule based collectives */
247 mpi_errno = MPIR_Sched_next_tagcxx . . $ `src/mpid/ch4/include/mpid_sched.h:12:9`!(comm, &tag);
248 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
249
250 is_inplace = (sendbuf == MPI_IN_PLACEcxx . . $ `src/include/mpi.h:555:9`!);
251 MPIR_COMM_RANK_SIZEcxx . . $ `src/include/mpir_comm.h:412:9`!(comm, rank, nranks);
252
253 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(recvtype, recv_extent);
254 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(recvtype, &recv_lb, &true_extent);
255 recv_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(recv_extent, true_extent);
256
257 /* get the neighbors, the function allocates the required memory */
258 MPII_Recexchalgo_get_neighborscxx . . $ MPII_Recexchalgo_get_neighbors(21383f888eb87359).(rank, nranks, &k, &step1_sendto,
259 &step1_recvfrom, &step1_nrecvs,
260 &step2_nbrs, &step2_nphases, &p_of_k, &T);
261 is_instep2 = (step1_sendto == -1); /* whether this rank participates in Step 2 */
262 log_pofk = step2_nphases;
263 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(recv_id, sizeof(int) * ((step2_nphases * (k - 1)) + 1));
264
265 if (!is_inplace && is_instep2) {
266 /* copy the data to recvbuf but only if you are a rank participating in Step 2 */
267 mpi_errno =
268 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(sendbuf, recvcount, recvtype,
269 (char *) recvbuf + rank * recv_extent * recvcount, recvcount,
270 recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &dtcopy_id);
271 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
272 n_invtcs = 1;
273 invtx = dtcopy_id;
274 } else {
275 n_invtcs = 0;
276 }
277
278 /* Step 1 */
279 MPIR_TSP_Iallgather_sched_intra_recexch_step1cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step1(350b4535767051b5).(step1_sendto, step1_recvfrom, step1_nrecvs,
280 is_inplace, rank, tag, sendbuf, recvbuf,
281 recv_extent, recvcount, recvtype, n_invtcs,
282 &invtx, comm, sched);
283 mpi_errno = MPIR_TSP_sched_fencecxx . . $ MPIR_TSP_sched_fence(dedf1e9b1c614a07).(sched);
284 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
285
286 /* For distance halving algorithm, exchange the data with digit reversed partner
287 * so that finally the data is in the correct order. */
288 if (is_dist_halving == 1) {
289 if (step1_sendto == -1) {
290 MPIR_TSP_Iallgather_sched_intra_recexch_data_exchangecxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_data_exchange(bb1217bfe2f14ab2).(rank, nranks, k, p_of_k, log_pofk,
291 T, recvbuf, recvtype, recv_extent,
292 recvcount, tag, comm, sched);
293 mpi_errno = MPIR_TSP_sched_fencecxx . . $ MPIR_TSP_sched_fence(dedf1e9b1c614a07).(sched);
294 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
295 }
296 }
297
298 /* Step2 */
299 MPIR_TSP_Iallgather_sched_intra_recexch_step2cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step2(76b786d5e53fdf32).(step1_sendto, step2_nphases, step2_nbrs, rank,
300 nranks, k, p_of_k, log_pofk, T, &nrecvs, &recv_id,
301 tag, recvbuf, recv_extent, recvcount, recvtype,
302 is_dist_halving, comm, sched);
303
304 /* Step 3: This is reverse of Step 1. Ranks that participated in Step 2
305 * send the data to non-partcipating ranks */
306 MPIR_TSP_Iallgather_sched_intra_recexch_step3cxx . . $ MPIR_TSP_Iallgather_sched_intra_recexch_step3(b5c1f540157ce9d9).(step1_sendto, step1_recvfrom, step1_nrecvs,
307 step2_nphases, recvbuf, recvcount, nranks, k,
308 nrecvs, recv_id, tag, recvtype, comm, sched);
309
310 /* free the memory */
311 for (i = 0; i < step2_nphases; i++)
312 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(step2_nbrs[i]);
313 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(step2_nbrs);
314 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(step1_recvfrom);
315
316 fn_exit:
317 MPIR_CHKLMEM_FREEALLcxx . . $ `src/include/mpir_mem.h:129:9`!();
318 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
319
320 return mpi_errno;
321 fn_fail:
322 goto fn_exit;
323 }