Debian Codegraph @

src/mpi/coll/iallgatherv/iallgatherv_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 #include "iallgatherv.h"cxx . . $ `<file>/src/mpi/coll/iallgatherv/iallgatherv.h`/
8
9 /* XXX The code has work around to deal with a known failure with a ICC version
10 * 2019.0.105 build with the following configuration:
11 * ./configure -C --disable-perftest --disable-ft-tests --with-fwrapname=mpigf \
12 --with-filesystem=ufs+nfs --enable-timer-type=linux86_cycle --enable-romio \
13 --with-mpe=no --with-smpcoll=yes --with-assert-level=0 --enable-shared \
14 --enable-static --enable-error-messages=yes --enable-visibility --enable-large-tests \
15 --enable-strict --enable-collalgo-tests --with-ch4-posix-eager-modules=fbox \
16 --enable-g=none --enable-error-checking=no --enable-fast=all,O3 --disable-debuginfo \
17 --with-device=ch4:ofi:sockets --enable-handle-allocation=default --enable-threads=multiple \
18 --without-valgrind --enable-timing=none --enable-ch4-direct=auto \
19 --with-ch4-netmod-ofi-args= --enable-thread-cs=global --with-libfabric=embedded \
20 MPICHLIB_CFLAGS="-O3 -Wall -ggdb -ggdb -mtune=generic -std=gnu99 -Wcheck -Wall -w3 \
21 -wd869 -wd280 -wd593 -wd2259 -wd981" MPICHLIB_CXXFLAGS="-O3 -Wall -ggdb -ggdb \
22 -mtune=generic -Wcheck -Wall -w3 -wd869 -wd280 -wd593 -wd2259 -wd981" \
23 MPICHLIB_FCFLAGS="-O3 -Wall -ggdb -ggdb -mtune=generic -w" MPICHLIB_F77FLAGS="-O3 \
24 -Wall -ggdb -ggdb -mtune=generic -w" MPICHLIB_LDFLAGS="-O3 -L/usr/lib64 -O0" \
25 CC=icc LDFLAGS=" -Wl,-z,muldefs -Wl,-z,now" CXX=icpc FC=ifort F77=ifort --disable-checkerrors
26 */
27
28 int
29 MPIR_TSP_Iallgatherv_sched_intra_bruckscxx . . $ MPIR_TSP_Iallgatherv_sched_intra_brucks(34045fb2b82f2bed).(const void *sendbuf, MPI_Aintcxx . . $ MPI_Aint# sendcount,
30 MPI_Datatypecxx . . $ MPI_Datatype# sendtype, void *recvbuf,
31 const MPI_Aintcxx . . $ MPI_Aint# recvcounts[], const MPI_Aintcxx . . $ MPI_Aint# displs[],
32 MPI_Datatypecxx . . $ MPI_Datatype# recvtype, MPIR_Commcxx . . $ MPIR_Comm# * comm,
33 int k, MPIR_TSP_sched_tcxx . . $ MPIR_TSP_sched_t# sched)
34 {
35 int i, j, l;
36 int nphases = 0;
37 int n_invtcs = 0;
38 int src, dst, p_of_k = 0; /* largest power of k that is (strictly) smaller than 'size' */
39 int total_recvcount = 0;
40 int delta = 1;
41
42 int is_inplace, rank, size, max;
43 MPI_Aintcxx . . $ MPI_Aint# sendtype_extent, sendtype_lb;
44 MPI_Aintcxx . . $ MPI_Aint# recvtype_extent, recvtype_lb;
45 MPI_Aintcxx . . $ MPI_Aint# sendtype_true_extent, recvtype_true_extent;
46
47 int tag;
48 int *recv_id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
49 MPI_Aintcxx . . $ MPI_Aint# *recv_index = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
50 int *scount_lookup = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
51 MPIR_CHKLMEM_DECLcxx . . $ `src/include/mpir_mem.h:108:9`!();
52 void *tmp_recvbuf = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
53 int **s_counts = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
54 int **r_counts = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
55 int tmp_sum = 0;
56 int idx = 0, vtx_id;
57 int prev_delta = 0;
58 int count_length, top_count, bottom_count, left_count;
59 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
60
61 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
62
63 /* For correctness, transport based collectives need to get the
64 * tag from the same pool as schedule based collectives */
65 mpi_errno = MPIR_Sched_next_tagcxx . . $ `src/mpid/ch4/include/mpid_sched.h:12:9`!(comm, &tag);
66 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
67
68 is_inplace = (sendbuf == MPI_IN_PLACEcxx . . $ `src/include/mpi.h:555:9`!);
69 MPIR_COMM_RANK_SIZEcxx . . $ `src/include/mpir_comm.h:412:9`!(comm, rank, size);
70 max = size - 1;
71
72 if (is_inplace) {
73 sendcount = recvcounts[rank];
74 sendtype = recvtype;
75 }
76
77 /* Get datatype info of sendtype and recvtype */
78 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(sendtype, sendtype_extent);
79 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(sendtype, &sendtype_lb, &sendtype_true_extent);
80 sendtype_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(sendtype_extent, sendtype_true_extent);
81
82 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(recvtype, recvtype_extent);
83 MPIR_Type_get_true_extent_implcxx . . $ MPIR_Type_get_true_extent_impl(76a2ea8aac5bbe77).(recvtype, &recvtype_lb, &recvtype_true_extent);
84 recvtype_extent = MPL_MAXcxx . . $ `src/mpl/include/mpl_base.h:105:9`!(recvtype_extent, recvtype_true_extent);
85
86 while (max) {
87 nphases++;
88 max /= k;
89 }
90
91 /* Check if size is power of k */
92 if (MPL_ipowcxx . . $ MPL_ipow(9b79fb6aee4c0440).(k, nphases) == size)
93 p_of_k = 1;
94
95 /* if nphases=0 then no recv_id needed */
96 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(recv_id, sizeof(int) * nphases * (k - 1));
97 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(scount_lookup, sizeof(int) * nphases);
98
99 /* To store the index to receive in various phases and steps within */
100 MPIR_CHKLMEM_MALLOCcxx . . $ `src/include/mpir_mem.h:118:9`!(recv_index, sizeof(MPI_Aint) * nphases * (k - 1));
101
102 for (i = 0; i < size; i++)
103 total_recvcount += recvcounts[i];
104
105 if (rank == 0)
106 tmp_recvbuf = recvbuf;
107 else
108 tmp_recvbuf = MPIR_TSP_sched_malloccxx . . $ MPIR_TSP_sched_malloc(7cf5f2fc6057a0cc).(total_recvcount * recvtype_extent, sched);
109 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!tmp_recvbuf, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
110
111
112 r_counts = (int **) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(int *) * nphases, MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
113 if (nphases > 0)
114 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!r_counts, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
115
116 s_counts = (int **) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(int *) * nphases, MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
117 if (nphases > 0)
118 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!s_counts, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
119
120 for (i = 0; i < nphases; i++) {
121 r_counts[i] = (int *) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(int) * (k - 1), MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
122 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!r_counts[i], mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
123 s_counts[i] = (int *) MPL_malloccxx . . $ MPL_malloc(47e2c277390bf45).(sizeof(int) * (k - 1), MPL_MEM_COLLcxx . . $ MPL_MEM_COLL.);
124 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!s_counts[i], mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
125 }
126
127 MPI_Aintcxx . . $ MPI_Aint# index_sum;
128 index_sum = recvcounts[rank]; /* because in initially you copy your own data to the top of recv_buf */
129 if (nphases > 0)
130 recv_index[idx++] = index_sum;
131
132 delta = 1;
133 for (i = 0; i < nphases; i++) {
134 scount_lookup[i] = (i == 0) ? 0 : scount_lookup[i - 1];
135 for (l = prev_delta; l < delta; l++) {
136 scount_lookup[i] += recvcounts[(rank + l) % size];
137 }
138 prev_delta = delta;
139 delta *= k;
140 }
141
142 delta = 1;
143 /* The least s_count for any send will be their own sendcount(=recvcounts[rank])
144 * We add all the r_counts received from neighbours during the previous phase */
145 for (i = 0; i < nphases; i++) {
146 for (j = 1; j < k; j++) {
147 r_counts[i][j - 1] = 0;
148 s_counts[i][j - 1] = 0;
149 src = (int) (rank + delta * j) % size;
150 if ((i == nphases - 1) && (!p_of_k)) {
151 left_count = size - delta * j;
152 count_length = MPL_MINcxx . . $ `src/mpl/include/mpl_base.h:106:9`!(delta, left_count);
153 } else {
154 count_length = delta;
155 }
156 /* Calculate r_counts and s_counts for the data you'll receive and send in
157 * the next steps(phase, [0, 1, ..,(k-1)]) */
158 tmp_sum = 0;
159 /* XXX We use a temporary variable to hold the sum instead of directly
160 * accumulating in r_counts[i][j-1]. Using r_counts[i][j-1] does not
161 * compile properly for a certain build. The same issue happens with
162 * s_counts[i][j - 1] after we use the tmp_sum for r_counts[i][j - 1].
163 * Details of the configuration are at the top of the file. */
164 for (l = 0; l < count_length; l++) {
165 tmp_sum += recvcounts[(src + l) % size];
166 }
167 r_counts[i][j - 1] = tmp_sum;
168
169 if (count_length != delta) {
170 tmp_sum = 0;
171 for (l = 0; l < count_length; l++) {
172 tmp_sum += recvcounts[(rank + l) % size];
173 }
174 s_counts[i][j - 1] = tmp_sum;
175 } else {
176 s_counts[i][j - 1] = scount_lookup[i];
177 }
178
179 /* Helps point to correct recv location in tmp_recvbuf */
180 index_sum += r_counts[i][j - 1];
181 if (idx < nphases * (k - 1))
182 recv_index[idx++] = index_sum;
183
184 }
185 delta *= k;
186 }
187
188 /* Step1: copy own data from sendbuf to top of recvbuf */
189 if (is_inplace && rank != 0)
190 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) recvbuf + displs[rank] * recvtype_extent,
191 recvcounts[rank], recvtype, tmp_recvbuf,
192 recvcounts[rank], recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
193 else if (!is_inplace)
194 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(sendbuf, sendcount, sendtype, tmp_recvbuf,
195 recvcounts[rank], recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
196
197 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
198
199 mpi_errno = MPIR_TSP_sched_fencecxx . . $ MPIR_TSP_sched_fence(dedf1e9b1c614a07).(sched);
200 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
201
202 idx = 0;
203 delta = 1;
204 for (i = 0; i < nphases; i++) {
205 for (j = 1; j < k; j++) {
206 /* If the first location exceeds comm size, nothing is to be sent */
207 if (MPL_ipowcxx . . $ MPL_ipow(9b79fb6aee4c0440).(k, i) * j >= size)
208 break;
209
210 dst = (int) (size + (rank - delta * j)) % size;
211 src = (int) (rank + delta * j) % size;
212 /* Recv at the exact location */
213 mpi_errno =
214 MPIR_TSP_sched_irecvcxx . . $ MPIR_TSP_sched_irecv(2270ed5ad98bfa2b).((char *) tmp_recvbuf + recv_index[idx] * recvtype_extent,
215 r_counts[i][j - 1], recvtype, src, tag, comm, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
216 &vtx_id);
217 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
218
219 recv_id[idx] = vtx_id;
220 idx++;
221
222 /* Send from the start of recv till the count amount of data */
223 mpi_errno =
224 MPIR_TSP_sched_isendcxx . . $ MPIR_TSP_sched_isend(29099b4ae230c868).(tmp_recvbuf, s_counts[i][j - 1], recvtype, dst, tag, comm,
225 sched, n_invtcs, recv_id, &vtx_id);
226 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
227 }
228 n_invtcs += (k - 1);
229 delta *= k;
230 }
231 mpi_errno = MPIR_TSP_sched_fencecxx . . $ MPIR_TSP_sched_fence(dedf1e9b1c614a07).(sched);
232 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
233
234 /* No shift required for rank 0 */
235 if (rank != 0) {
236 idx = 0;
237 if (MPII_Iallgatherv_is_displs_orderedcxx . . $ MPII_Iallgatherv_is_displs_ordered(742aadb20c5b1124).(size, recvcounts, displs)) {
238 /* Calculate idx(same as count) till 0th rank's data */
239 for (i = 0; i < (size - rank); i++)
240 idx += recvcounts[(rank + i) % size];
241
242 bottom_count = idx;
243 top_count = total_recvcount - idx;
244 mpi_errno =
245 MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) tmp_recvbuf + bottom_count * recvtype_extent,
246 top_count, recvtype, recvbuf, top_count, recvtype, sched,
247 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
248 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
249
250 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).(tmp_recvbuf, bottom_count, recvtype,
251 (char *) recvbuf + top_count * recvtype_extent,
252 bottom_count, recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
253 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
254 } else {
255 for (i = 0; i < size; i++) {
256 src = (rank + i) % size; /* Rank whose data it is copying */
257 idx += (i == 0) ? 0 : recvcounts[(rank + i - 1) % size];
258 mpi_errno = MPIR_TSP_sched_localcopycxx . . $ MPIR_TSP_sched_localcopy(e23c285a5816c4b9).((char *) tmp_recvbuf + idx * recvtype_extent,
259 recvcounts[src], recvtype,
260 (char *) recvbuf +
261 displs[src] * recvtype_extent, recvcounts[src],
262 recvtype, sched, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &vtx_id);
263 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
264 }
265 }
266 }
267
268 for (i = 0; i < nphases; i++) {
269 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(r_counts[i]);
270 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(s_counts[i]);
271 }
272 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(r_counts);
273 MPL_freecxx . . $ `src/mpl/include/mpl_trmem.h:308:9`!(s_counts);
274
275 fn_exit:
276 MPIR_CHKLMEM_FREEALLcxx . . $ `src/include/mpir_mem.h:129:9`!();
277 MPIR_FUNC_ENTERcxx . . $ `src/include/mpir_func.h:57:9`!;
278 return mpi_errno;
279 fn_fail:
280 goto fn_exit;
281 }