Debian Codegraph @

src/mpi/coll/iallgather/iallgather_intra_sched_recursive_doubling.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 /* helper callbacks and associated state structures */
9 struct shared_statecxx . . $ shared_state# {
10 int recvtypecxx . . $ shared_state#recvtype.;
11 int recvcountcxx . . $ shared_state#recvcount.;
12 MPI_Aintcxx . . $ MPI_Aint# curr_countcxx . . $ shared_state#curr_count.;
13 MPI_Aintcxx . . $ MPI_Aint# last_recv_countcxx . . $ shared_state#last_recv_count.;
14 MPI_Statuscxx . . $ MPI_Status# statuscxx . . $ shared_state#status.;
15 };
16 static int get_countcxx . . $ get_count(3ac0abbfd560c8f1).(MPIR_Commcxx . . $ MPIR_Comm# * comm, int tag, void *state)
17 {
18 struct shared_statecxx . . $ shared_state# *ss = state;
19 MPI_Aintcxx . . $ MPI_Aint# recv_count;
20 MPIR_Get_count_implcxx . . $ MPIR_Get_count_impl(4737dea3b1ffa25f).(&ss->statuscxx . . $ shared_state#status., ss->recvtypecxx . . $ shared_state#recvtype., &recv_count);
21 ss->last_recv_countcxx . . $ shared_state#last_recv_count. = recv_count;
22 ss->curr_countcxx . . $ shared_state#curr_count. += ss->last_recv_countcxx . . $ shared_state#last_recv_count.;
23 return MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
24 }
25
26 static int reset_shared_statecxx . . $ reset_shared_state(3ac0abbfd560c8f1).(MPIR_Commcxx . . $ MPIR_Comm# * comm, int tag, void *state)
27 {
28 struct shared_statecxx . . $ shared_state# *ss = state;
29 ss->curr_countcxx . . $ shared_state#curr_count. = ss->recvcountcxx . . $ shared_state#recvcount.;
30
31 return MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
32 }
33
34 /*
35 * Recursive Doubling Algorithm:
36 *
37 * Restrictions: power-of-two no. of processes
38 *
39 * Cost = lgp.alpha + n.((p-1)/p).beta
40 *
41 * TODO: On TCP, we may want to use recursive doubling instead of the
42 * Bruck's algorithm in all cases because of the pairwise-exchange
43 * property of recursive doubling (see Benson et al paper in Euro
44 * PVM/MPI 2003).
45 */
46 int MPIR_Iallgather_intra_sched_recursive_doublingcxx . . $ MPIR_Iallgather_intra_sched_recursive_doubling(c41cc56d95858bf1).(const void *sendbuf, MPI_Aintcxx . . $ MPI_Aint# sendcount,
47 MPI_Datatypecxx . . $ MPI_Datatype# sendtype, void *recvbuf,
48 MPI_Aintcxx . . $ MPI_Aint# recvcount, MPI_Datatypecxx . . $ MPI_Datatype# recvtype,
49 MPIR_Commcxx . . $ MPIR_Comm# * comm_ptr, MPIR_Sched_tcxx . . $ MPIR_Sched_t# s)
50 {
51 int mpi_errno = MPI_SUCCESScxx . . $ `src/include/mpi.h:655:9`!;
52 struct shared_statecxx . . $ shared_state# *ss = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
53 int comm_size, rank;
54 int i, j, k;
55 int mask, tmp_mask, dst;
56 int dst_tree_root, my_tree_root, tree_root;
57 MPI_Aintcxx . . $ MPI_Aint# recvtype_extent;
58
59 MPIR_COMM_RANK_SIZEcxx . . $ `src/include/mpir_comm.h:412:9`!(comm_ptr, rank, comm_size);
60
61 #ifdef HAVE_ERROR_CHECKINGcxx . . $ `src/include/mpichconf.h:269:9`!
62 /* Currently this algorithm can only handle power-of-2 comm_size.
63 * Non power-of-2 comm_size is still experimental */
64 MPIR_Assertcxx . . $ `src/include/mpir_assert.h:39:9`!(!(comm_size & (comm_size - 1)));
65 #endif /* HAVE_ERROR_CHECKING */
66
67 MPIR_Datatype_get_extent_macrocxx . . $ `src/include/mpir_datatype.h:462:9`!(recvtype, recvtype_extent);
68
69 /* copy local data into recvbuf */
70 if (sendbuf != MPI_IN_PLACEcxx . . $ `src/include/mpi.h:555:9`!) {
71 mpi_errno = MPIR_Sched_copycxx . . $ `src/mpid/ch4/include/mpid_sched.h:27:9`!(sendbuf, sendcount, sendtype,
72 ((char *) recvbuf + rank * recvcount * recvtype_extent),
73 recvcount, recvtype, s);
74 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
75 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
76 }
77
78 ss = MPIR_Sched_alloc_statecxx . . $ `src/mpid/ch4/include/mpid_sched.h:18:9`!(s, sizeof(struct shared_statecxx . . $ shared_state#));
79 MPIR_ERR_CHKANDJUMPcxx . . $ `src/include/mpir_err.h:1034:9`!(!ss, mpi_errno, MPI_ERR_OTHERcxx . . $ `src/include/mpi.h:679:9`!, "**nomem");
80 ss->curr_countcxx . . $ shared_state#curr_count. = recvcount;
81 ss->recvtypecxx . . $ shared_state#recvtype. = recvtype;
82 ss->recvcountcxx . . $ shared_state#recvcount. = recvcount;
83
84 mask = 0x1;
85 i = 0;
86 while (mask < comm_size) {
87 dst = rank ^ mask;
88
89 /* find offset into send and recv buffers. zero out
90 * the least significant "i" bits of rank and dst to
91 * find root of src and dst subtrees. Use ranks of
92 * roots as index to send from and recv into buffer */
93
94 dst_tree_root = dst >> i;
95 dst_tree_root <<= i;
96
97 my_tree_root = rank >> i;
98 my_tree_root <<= i;
99
100 MPI_Aintcxx . . $ MPI_Aint# send_offset, recv_offset;
101 send_offset = my_tree_root * recvcount * recvtype_extent;
102 recv_offset = dst_tree_root * recvcount * recvtype_extent;
103
104 if (dst < comm_size) {
105 mpi_errno = MPIR_Sched_send_defercxx . . $ `src/mpid/ch4/include/mpid_sched.h:22:9`!(((char *) recvbuf + send_offset),
106 &ss->curr_countcxx . . $ shared_state#curr_count., recvtype, dst, comm_ptr, s);
107 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
108 /* send-recv, no sched barrier here */
109 mpi_errno = MPIR_Sched_recv_statuscxx . . $ `src/mpid/ch4/include/mpid_sched.h:25:9`!(((char *) recvbuf + recv_offset),
110 ((comm_size - dst_tree_root) * recvcount),
111 recvtype, dst, comm_ptr, &ss->statuscxx . . $ shared_state#status., s);
112 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
113 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
114
115 mpi_errno = MPIR_Sched_cbcxx . . $ `src/mpid/ch4/include/mpid_sched.h:10:9`!(&get_countcxx . . $ get_count(3ac0abbfd560c8f1)., ss, s);
116 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
117 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
118 }
119
120 /* if some processes in this process's subtree in this step
121 * did not have any destination process to communicate with
122 * because of non-power-of-two, we need to send them the
123 * data that they would normally have received from those
124 * processes. That is, the haves in this subtree must send to
125 * the havenots. We use a logarithmic recursive-halfing algorithm
126 * for this. */
127
128 /* This part of the code will not currently be
129 * executed because we are not using recursive
130 * doubling for non power of two. Mark it as experimental
131 * so that it doesn't show up as red in the coverage
132 * tests. */
133 /* --BEGIN EXPERIMENTAL-- */
134 if (dst_tree_root + mask > comm_size) {
135 int nprocs_completed = comm_size - my_tree_root - mask;
136 /* nprocs_completed is the number of processes in this
137 * subtree that have all the data. Send data to others
138 * in a tree fashion. First find root of current tree
139 * that is being divided into two. k is the number of
140 * least-significant bits in this process's rank that
141 * must be zeroed out to find the rank of the root */
142 j = mask;
143 k = 0;
144 while (j) {
145 j >>= 1;
146 k++;
147 }
148 k--;
149
150 MPI_Aintcxx . . $ MPI_Aint# offset;
151 offset = recvcount * (my_tree_root + mask) * recvtype_extent;
152 tmp_mask = mask >> 1;
153
154 while (tmp_mask) {
155 dst = rank ^ tmp_mask;
156
157 tree_root = rank >> k;
158 tree_root <<= k;
159
160 /* send only if this proc has data and destination
161 * doesn't have data. at any step, multiple processes
162 * can send if they have the data */
163 if ((dst > rank) && (rank < tree_root + nprocs_completed)
164 && (dst >= tree_root + nprocs_completed)) {
165 /* last_recv_count was set in the previous
166 * receive. that's the amount of data to be
167 * sent now. */
168 mpi_errno = MPIR_Sched_send_defercxx . . $ `src/mpid/ch4/include/mpid_sched.h:22:9`!(((char *) recvbuf + offset),
169 &ss->last_recv_countcxx . . $ shared_state#last_recv_count.,
170 recvtype, dst, comm_ptr, s);
171 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
172 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
173 }
174 /* recv only if this proc. doesn't have data and sender
175 * has data */
176 else if ((dst < rank) &&
177 (dst < tree_root + nprocs_completed) &&
178 (rank >= tree_root + nprocs_completed)) {
179 /* nprocs_completed is also equal to the
180 * no. of processes whose data we don't have */
181 mpi_errno = MPIR_Sched_recv_statuscxx . . $ `src/mpid/ch4/include/mpid_sched.h:25:9`!(((char *) recvbuf + offset),
182 ((comm_size -
183 (my_tree_root + mask)) * recvcount),
184 recvtype, dst, comm_ptr, &ss->statuscxx . . $ shared_state#status., s);
185 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
186 mpi_errno = MPIR_Sched_cbcxx . . $ `src/mpid/ch4/include/mpid_sched.h:10:9`!(&get_countcxx . . $ get_count(3ac0abbfd560c8f1)., ss, s);
187 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
188 MPIR_SCHED_BARRIERcxx . . $ `src/include/mpir_nbc.h:93:9`!(s);
189 }
190
191 tmp_mask >>= 1;
192 k--;
193 }
194 }
195 /* --END EXPERIMENTAL-- */
196
197 mask <<= 1;
198 i++;
199 }
200
201 mpi_errno = MPIR_Sched_cbcxx . . $ `src/mpid/ch4/include/mpid_sched.h:10:9`!(reset_shared_statecxx . . $ reset_shared_state(3ac0abbfd560c8f1)., ss, s);
202 MPIR_ERR_CHECKcxx . . $ `src/include/mpir_err.h:810:9`!(mpi_errno);
203
204 fn_exit:
205 return mpi_errno;
206 fn_fail:
207 goto fn_exit;
208 }