Debian Codegraph @

src/mpi/coll/ialltoall/ialltoall_tsp_brucks.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 /*
8 === BEGIN_MPI_T_CVAR_INFO_BLOCK ===
9
10 cvars:
11 - name : MPIR_CVAR_IALLTOALL_BRUCKS_KVAL
12 category : COLLECTIVE
13 type : int
14 default : 2
15 class : none
16 verbosity : MPI_T_VERBOSITY_USER_BASIC
17 scope : MPI_T_SCOPE_ALL_EQ
18 description : >-
19 radix (k) value for generic transport brucks based ialltoall
20
21 - name : MPIR_CVAR_IALLTOALL_BRUCKS_BUFFER_PER_NBR
22 category : COLLECTIVE
23 type : boolean
24 default : 0
25 class : none
26 verbosity : MPI_T_VERBOSITY_USER_BASIC
27 scope : MPI_T_SCOPE_ALL_EQ
28 description : >-
29 If set to true, the tsp based brucks algorithm will allocate
30 dedicated send and receive buffers for every neighbor in the brucks
31 algorithm. Otherwise, it would reuse a single buffer for sending
32 and receiving data to/from neighbors
33
34 === END_MPI_T_CVAR_INFO_BLOCK ===
35 */
36
37
38 /* Brucks Pack, UnPack (PUP) utility function
39 * This functions packs (unpacks) non-contiguous (contiguous)
40 * data from (to) rbuf to (from) pupbuf. It goes to every offset
41 * that has the value "digitval" at the "phase"th digit in the
42 * base k representation of the offset. The argument phase corresponds
43 * to the phase in the brucks algorithm. */
44 static int
45 brucks_sched_pupcxx . . $ brucks_sched_pup(8fb74c63d065ddfb).(int pack, void *rbuf, void *pupbuf, MPI_Datatypecxx . . $ MPI_Datatype# rtype, MPI_Aintcxx . . $ MPI_Aint# count,
46 int phase, int k, int digitval, int comm_size, int *pupsize,
47 MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched, int ninvtcs, int *invtcs, int *sink_id_out)
48 {
49 MPI_Aintcxx . . $ MPI_Aint# type_extent, type_lb, type_true_extent;
50 int pow_k_phase, offset, nconsecutive_occurrences, delta;
51 int *dtcopy_id;
52 int counter;
53 int sink_id, vtx_id;
54 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
55 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
56
57 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(rtype, type_extent);
58 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(rtype, &type_lb, &type_true_extent);
59 type_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(type_extent, type_true_extent);
60
61 pow_k_phase = MPL_ipowcxx . . $ MPL_ipow(9b79fb6aee4c0440).(k, phase);
62 /* first offset where the phase'th bit has value digitval */
63 offset = pow_k_phase * digitval;
64 /* number of consecutive occurrences of digitval */
65 nconsecutive_occurrences = pow_k_phase;
66 /* distance between non-consecutive occurrences of digitval */
67 delta = (k - 1) * pow_k_phase;
68
69 dtcopy_id = MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(int) * comm_size, MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.); /* NOTE: We do not need this much large array - make it more accurate */
70 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(dtcopy_id != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
71 counter = 0;
72 *pupsize = 0; /* points to the first empty location in pupbuf */
73 while (offset < comm_size) {
74 if (pack) {
75 mpi_errno =
76 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) rbuf + offset * count * type_extent, count, rtype,
77 (char *) pupbuf + *pupsize, count, rtype, sched, ninvtcs,
78 invtcs, &vtx_id);
79 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
80 dtcopy_id[counter++] = vtx_id;
81 } else {
82 mpi_errno =
83 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) pupbuf + *pupsize, count, rtype,
84 (char *) rbuf + offset * count * type_extent, count, rtype,
85 sched, ninvtcs, invtcs, &vtx_id);
86 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
87 dtcopy_id[counter++] = vtx_id;
88 }
89
90 offset += 1;
91 nconsecutive_occurrences -= 1;
92
93 if (nconsecutive_occurrences == 0) { /* consecutive occurrences are over */
94 offset += delta;
95 nconsecutive_occurrences = pow_k_phase;
96 }
97
98 *pupsize += count * type_extent; /* NOTE: This may not be extent, it might be type_size - CHECK THIS */
99 }
100
101 mpi_errno = MPIR_TSP_sched_selective_sinkcxx . . $ MPIR_TSP_sched_selective_sink(1ea641a0622712dd).(sched, counter, dtcopy_id, &sink_id);
102 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
103
104 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(dtcopy_id);
105
106 *sink_id_out = sink_id;
107
108 fn_exit:
109 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
110 return mpi_errno;
111 fn_fail:
112 goto fn_exit;
113 }
114
115 int
116 MPIR_TSP_Ialltoall_sched_intra_bruckscxx . . $ MPIR_TSP_Ialltoall_sched_intra_brucks(a7e8e0149b3b4d80).(const void *sendbuf, MPI_Aintcxx . . $ MPI_Aint# sendcount,
117 MPI_Datatypecxx . . $ MPI_Datatype# sendtype, void *recvbuf, MPI_Aintcxx . . $ MPI_Aint# recvcount,
118 MPI_Datatypecxx . . $ MPI_Datatype# recvtype, MPIR_Commcxx . . $ MPIR_Comm# * comm,
119 int k, int buffer_per_phase, MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
120 {
121 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
122 int i, j;
123 int pack_ninvtcs, recv_ninvtcs, unpack_ninvtcs;
124 int *pack_invtcs, *recv_invtcs, *unpack_invtcs;
125 int *invtcs, n_invtcs;
126 int rank, size;
127 int nphases = 0, max;
128 int p_of_k; /* largest power of k that is (strictly) smaller than 'size' */
129 int is_inplace;
130 MPI_Aintcxx . . $ MPI_Aint# s_extent, s_lb, r_extent, r_lb;
131 MPI_Aintcxx . . $ MPI_Aint# s_true_extent, r_true_extent;
132 int delta, src, dst, vtx_id;
133 void ***tmp_sbuf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ***tmp_rbuf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
134 int *packids, *sendids = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *recvids = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *unpackids = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
135 int packsize, num_unpacks_in_last_phase;
136 void *tmp_buf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
137 const void *senddata;
138 int tag;
139 int coll_attr ATTRIBUTEcxx . . $ `src/mpl/include/mpl_base.h:39:9`!((unused)) = 0;
140
141 MPIR_CHKLMEM_DECLcxx . . $ `src/include/mpir_mem.h:108:9`!();
142
143 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
144
145 /* For correctness, transport based collectives need to get the
146 * tag from the same pool as schedule based collectives */
147 mpi_errno = MPIR_Sched_next_tagcxx . . $ `src/mpid/ch4/include/mpid_sched.h:12:9`!(comm, &tag);
148 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
149
150 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(pack_invtcs, sizeof(int) * k);
151 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(recv_invtcs, sizeof(int) * k);
152 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(unpack_invtcs, sizeof(int) * k);
153 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(invtcs, sizeof(int) * 6 * k);
154
155 is_inplace = (sendbuf == MPI_IN_PLACEcxx . . $ `src/include/mpi.h:555:9`!);
156
157 MPIR_COMM_RANK_SIZEcxx . . $ `src/include/mpir_comm.h:412:9`!(comm, rank, size);
158
159 max = size - 1;
160
161 /* calculate the number of bits required to represent a rank in base k */
162 while (max) {
163 nphases++;
164 max /= k;
165 }
166
167 /* calculate largest power of k that is smaller than 'size'.
168 * This is used for allocating temporary space for sending
169 * and receiving data. */
170 p_of_k = 1;
171 for (i = 0; i < nphases - 1; i++) {
172 p_of_k *= k;
173 }
174
175 if (is_inplace) {
176 sendcount = recvcount;
177 sendtype = recvtype;
178 }
179
180 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(sendtype, s_extent);
181 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(sendtype, &s_lb, &s_true_extent);
182 s_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(s_extent, s_true_extent);
183
184 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(recvtype, r_extent);
185 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(recvtype, &r_lb, &r_true_extent);
186 r_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(r_extent, r_true_extent);
187
188 tmp_buf = (void *) MPIR_TSP_sched_malloccxx . . $ MPIR_TSP_sched_malloc(7cf5f2fc6057a0cc).(recvcount * size * r_extent, sched); /* temporary buffer used for rotation
189 * also used as sendbuf when inplace is true */
190 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(tmp_buf != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
191
192 if (is_inplace) {
193 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(recvbuf, size * recvcount, recvtype,
194 tmp_buf, size * recvcount, recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
195 &invtcs[0]);
196 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
197 n_invtcs = 1;
198 senddata = tmp_buf;
199 } else {
200 senddata = sendbuf;
201 n_invtcs = 0;
202 }
203
204 /* Step 1: rotate the data locally */
205 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((void *) ((char *) senddata + rank * sendcount * s_extent),
206 (size - rank) * sendcount, sendtype,
207 recvbuf, (size - rank) * recvcount, recvtype, sched,
208 n_invtcs, invtcs, &vtx_id);
209 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
210 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(senddata, rank * sendcount, sendtype,
211 (void *) ((char *) recvbuf +
212 (size - rank) * recvcount * r_extent),
213 rank * recvcount, recvtype, sched, n_invtcs, invtcs,
214 &vtx_id);
215 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
216 mpi_errno = MPIR_TSP_sched_fencecxx . . $ MPIR_TSP_sched_fence(dedf1e9b1c614a07).(sched);
217 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
218
219 /* Step 2: Allocate buffer space for packing/receiving data for every phase */
220 delta = 1;
221 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(tmp_sbuf, sizeof(void **) * nphases);
222 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(tmp_rbuf, sizeof(void **) * nphases);
223
224 for (i = 0; i < nphases; i++) {
225 tmp_sbuf[i] = (void **) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(void *) * (k - 1), MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
226 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(tmp_sbuf[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
227 tmp_rbuf[i] = (void **) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(void *) * (k - 1), MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
228 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(tmp_rbuf[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
229 for (j = 0; j < k - 1; j++) {
230 if (i == 0 || buffer_per_phase == 1) { /* allocate new memory if buffer_per_phase is set to true */
231 tmp_sbuf[i][j] =
232 (void *) MPIR_TSP_sched_malloccxx . . $ MPIR_TSP_sched_malloc(7cf5f2fc6057a0cc).((int) r_extent * recvcount * p_of_k, sched);
233 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(tmp_sbuf[i][j] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
234 tmp_rbuf[i][j] =
235 (void *) MPIR_TSP_sched_malloccxx . . $ MPIR_TSP_sched_malloc(7cf5f2fc6057a0cc).((int) r_extent * recvcount * p_of_k, sched);
236 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(tmp_rbuf[i][j] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
237 } else { /* reuse memory from first phase, make sure task dependencies are set correctly */
238 tmp_sbuf[i][j] = tmp_sbuf[0][j];
239 tmp_rbuf[i][j] = tmp_rbuf[0][j];
240 }
241 }
242 }
243
244 /* use invtcs in the following manner
245 * 0..k-2 for pack ids
246 * k-1..2k-3 for send ids
247 * 2k-2..3k-4 for recv ids
248 * 3k-3..4k-5 for unpack ids
249 */
250 packids = invtcs;
251 sendids = invtcs + k - 1;
252 recvids = invtcs + 2 * k - 2;
253 unpackids = invtcs + 3 * k - 3;
254 pack_ninvtcs = recv_ninvtcs = 0;
255
256 packsize = 0;
257 num_unpacks_in_last_phase = 0; /* record number of unpacking tasks in last phase for building dependency graph */
258
259 for (i = 0; i < nphases; i++) {
260 num_unpacks_in_last_phase = 0;
261 for (j = 1; j < k; j++) { /* for every non-zero value of digitval */
262 if (MPL_ipowcxx . . $ MPL_ipow(9b79fb6aee4c0440).(k, i) * j >= size) /* if the first location exceeds comm size, nothing is to be sent */
263 break;
264
265 src = (rank - delta * j + size) % size;
266 dst = (rank + delta * j) % size;
267
268 if (i != 0 && buffer_per_phase == 0) { /* this dependency holds only when we don't have dedicated send buffer per phase */
269 pack_invtcs[k - 1] = sendids[j - 1];
270 pack_ninvtcs = k;
271 }
272 mpi_errno = brucks_sched_pupcxx . . $ brucks_sched_pup(8fb74c63d065ddfb).(1, recvbuf, tmp_sbuf[i][j - 1],
273 recvtype, recvcount, i, k, j, size,
274 &packsize, sched, pack_ninvtcs, pack_invtcs,
275 &packids[j - 1]);
276 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
277 *unpack_invtcs = packids[j - 1];
278 unpack_ninvtcs = 1;
279
280 mpi_errno =
281 MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(tmp_sbuf[i][j - 1], packsize, MPIR_BYTE_INTERNALcxx . . $ `src/include/mpichconf.h:778:9`!, dst, tag,
282 comm, sched, 1, &packids[j - 1], &sendids[j - 1]);
283 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
284
285 if (i != 0 && buffer_per_phase == 0) { /* this dependency holds only when we don't have dedicated recv buffer per phase */
286 *recv_invtcs = unpackids[j - 1];
287 recv_ninvtcs = 1;
288 }
289 mpi_errno =
290 MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).(tmp_rbuf[i][j - 1], packsize, MPIR_BYTE_INTERNALcxx . . $ `src/include/mpichconf.h:778:9`!,
291 src, tag, comm, sched, recv_ninvtcs, recv_invtcs,
292 &recvids[j - 1]);
293 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
294
295 *(unpack_invtcs + 1) = recvids[j - 1];
296 unpack_ninvtcs = 2;
297 mpi_errno = brucks_sched_pupcxx . . $ brucks_sched_pup(8fb74c63d065ddfb).(0, recvbuf, tmp_rbuf[i][j - 1], recvtype,
298 recvcount, i, k, j, size,
299 &packsize, sched, unpack_ninvtcs, unpack_invtcs,
300 &unpackids[j - 1]);
301 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
302 num_unpacks_in_last_phase++;
303 }
304 MPIR_Localcopycxx . . $ MPIR_Localcopy(cf422982ceb8df2).(unpackids, sizeof(int) * (k - 1), MPIR_BYTE_INTERNALcxx . . $ `src/include/mpichconf.h:778:9`!,
305 pack_invtcs, sizeof(int) * (k - 1), MPIR_BYTE_INTERNALcxx . . $ `src/include/mpichconf.h:778:9`!);
306 pack_ninvtcs = k - 1;
307
308 delta *= k;
309 }
310
311 /* Step 3: rotate the buffer */
312 /* TODO: MPICH implementation does some lower_bound adjustment
313 * here for derived datatypes, I am skipping that for now,
314 * will come back to it later on - will require adding API
315 * for getting true_lb */
316 mpi_errno =
317 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((void *) ((char *) recvbuf + (rank + 1) * recvcount * r_extent),
318 (size - rank - 1) * recvcount, recvtype, tmp_buf,
319 (size - rank - 1) * recvcount, recvtype, sched,
320 num_unpacks_in_last_phase, unpackids, &invtcs[0]);
321 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
322
323 mpi_errno =
324 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(recvbuf, (rank + 1) * recvcount, recvtype,
325 (void *) ((char *) tmp_buf +
326 (size - rank - 1) * recvcount * r_extent),
327 (rank + 1) * recvcount, recvtype, sched, num_unpacks_in_last_phase,
328 unpackids, &invtcs[1]);
329 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
330
331 /* invert the buffer now to get the result in desired order */
332 for (i = 0; i < size; i++) {
333 mpi_errno =
334 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) tmp_buf + i * recvcount * r_extent, recvcount,
335 recvtype,
336 (void *) ((char *) recvbuf +
337 (size - i - 1) * recvcount * r_extent), recvcount,
338 recvtype, sched, 2, invtcs, &vtx_id);
339 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
340 }
341
342 fn_exit:
343 for (i = 0; i < nphases; i++) {
344 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(tmp_sbuf[i]);
345 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(tmp_rbuf[i]);
346 }
347 MPIR_CHKLMEM_FREEALLcxx . . $ `src/include/mpir_mem.h:129:9`!();
348
349 MPIR_FUNC_EXITcxx . . $ `src/include/mpir_func.h:58:9`!;
350
351 return mpi_errno;
352 fn_fail:
353 goto fn_exit;
354 }