Yet Another eXchange Tool 0.11.1
Loading...
Searching...
No Matches
xt-ddt-profile.c
Go to the documentation of this file.
1
13/*
14 * Keywords:
15 * Maintainer: Jörg Behrens <behrens@dkrz.de>
16 * Moritz Hanke <hanke@dkrz.de>
17 * Thomas Jahns <jahns@dkrz.de>
18 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are
22 * met:
23 *
24 * Redistributions of source code must retain the above copyright notice,
25 * this list of conditions and the following disclaimer.
26 *
27 * Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in the
29 * documentation and/or other materials provided with the distribution.
30 *
31 * Neither the name of the DKRZ GmbH nor the names of its contributors
32 * may be used to endorse or promote products derived from this software
33 * without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
36 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
37 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
38 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
39 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 */
47#ifdef HAVE_CONFIG_H
48#include <config.h>
49#endif
50
51#include <stdio.h>
52#include <stdlib.h>
53#include <string.h>
54
55#include <mpi.h>
56
57static FILE *dt_out = NULL;
58
59static void init_instr(void) __attribute__((constructor));
60
61static void init_instr(void)
62{
63 static const char rank_vars[][24]
64 = { { "MPI_LOCALRANKID" } , { "PMI_RANK" }, { 0 } };
65 enum {
66 nrank_vars = sizeof (rank_vars) / sizeof (rank_vars[0]) - 1,
67 };
68 const char *rank_str;
69 for (size_t i = 0; i < nrank_vars; ++i) {
70 if ((rank_str = getenv(rank_vars[i])))
71 goto found_rank;
72 }
73 rank_str = "unknown";
74found_rank:
75 ;
76 static const char dt_pfx[] = "dt_log.",
77 dt_sfx[] = ".txt";
78 size_t pfx_size = sizeof (dt_pfx), sfx_size = sizeof (dt_sfx),
79 rank_str_len = strlen(rank_str);
80 char dt_log_fn[pfx_size + sfx_size - 1 + rank_str_len];
81 memcpy(dt_log_fn, dt_pfx, pfx_size - 1);
82 memcpy(dt_log_fn+pfx_size-1, rank_str, rank_str_len);
83 memcpy(dt_log_fn+pfx_size-1+rank_str_len, dt_sfx, sfx_size);
84 dt_out = fopen(dt_log_fn, "w");
85 setlinebuf(dt_out);
86}
87
88
89int
90MPI_Type_dup(MPI_Datatype oldtype, MPI_Datatype *newtype)
91{
92 fprintf(dt_out, "MPI_Type_dup(%jd);\n", (intmax_t)oldtype);
93 int rc = PMPI_Type_dup(oldtype, newtype);
94 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
95 return rc;
96}
97
98int
99MPI_Type_contiguous(int count, MPI_Datatype oldtype,
100 MPI_Datatype *newtype)
101{
102 fprintf(dt_out, "MPI_Type_contiguous(%d, %jd);\n", count, (intmax_t)oldtype);
103 int rc = PMPI_Type_contiguous(count, oldtype, newtype);
104 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
105 return rc;
106}
107
108int
109MPI_Type_vector(int count, int blocklength, int stride,
110 MPI_Datatype oldtype, MPI_Datatype *newtype)
111{
112 fprintf(dt_out, "MPI_Type_vector(%d, %d, %d, %jd);\n",
113 count, blocklength, stride, (intmax_t)oldtype);
114 int rc = PMPI_Type_vector(count, blocklength, stride, oldtype, newtype);
115 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
116 return rc;
117}
118
119int
120MPI_Type_hvector(int count, int blocklength, MPI_Aint stride,
121 MPI_Datatype oldtype, MPI_Datatype *newtype)
122{
123 fprintf(dt_out, "MPI_Type_hvector(%d, %d, %jd, %jd);\n",
124 count, blocklength, (intmax_t)stride, (intmax_t)oldtype);
125 int rc = PMPI_Type_hvector(count, blocklength, stride, oldtype, newtype);
126 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
127 return rc;
128}
129
130int
131MPI_Type_create_hvector(int count, int blocklength,
132 MPI_Aint stride, MPI_Datatype oldtype,
133 MPI_Datatype *newtype)
134{
135 fprintf(dt_out, "MPI_Type_create_hvector(%d, %d, %jd, %jd);\n",
136 count, blocklength, (intmax_t)stride, (intmax_t)oldtype);
137 int rc = PMPI_Type_create_hvector(count, blocklength, stride, oldtype, newtype);
138 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
139 return rc;
140}
141
142
143int
145 XT_MPI2_CONST int array_of_blocklengths[],
146 XT_MPI2_CONST int array_of_displacements[],
147 MPI_Datatype oldtype,
148 MPI_Datatype *newtype)
149{
150 fprintf(dt_out, "MPI_Type_indexed(%d, (int){\n", count);
151 for (int i = 0; i < count; ++i)
152 fprintf(dt_out, " %d,\n", array_of_blocklengths[i]);
153 fputs("}, (int[]){\n", dt_out);
154 for (int i = 0; i < count; ++i)
155 fprintf(dt_out, " %d,\n", array_of_displacements[i]);
156 fprintf(dt_out, "}, %jd);\n", (intmax_t)oldtype);
157 int rc = PMPI_Type_indexed(count, array_of_blocklengths,
158 array_of_displacements, oldtype, newtype);
159 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
160 return rc;
161}
162
163int
165 int array_of_blocklengths[],
166 MPI_Aint array_of_displacements[],
167 MPI_Datatype oldtype,
168 MPI_Datatype *newtype)
169{
170 fprintf(dt_out, "MPI_Type_hindexed(%d, (int[]){\n", count);
171 for (int i = 0; i < count; ++i)
172 fprintf(dt_out, " %d,\n", array_of_blocklengths[i]);
173 fputs("}, (MPI_Aint[]){\n", dt_out);
174 for (int i = 0; i < count; ++i)
175 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_displacements[i]);
176 fprintf(dt_out, "}, %jd);\n", (intmax_t)oldtype);
177 int rc = PMPI_Type_hindexed(count, array_of_blocklengths,
178 array_of_displacements, oldtype, newtype);
179 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
180 return rc;
181}
182
183
184int
186 XT_MPI2_CONST int array_of_blocklengths[],
187 XT_MPI2_CONST MPI_Aint array_of_displacements[],
188 MPI_Datatype oldtype, MPI_Datatype *newtype)
189{
190 fprintf(dt_out, "MPI_Type_create_hindexed(%d, (int){\n", count);
191 for (int i = 0; i < count; ++i)
192 fprintf(dt_out, " %d,\n", array_of_blocklengths[i]);
193 fputs("}, (MPI_Aint[]){\n", dt_out);
194 for (int i = 0; i < count; ++i)
195 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_displacements[i]);
196 fprintf(dt_out, "}, %jd);\n", (intmax_t)oldtype);
197 int rc = PMPI_Type_create_hindexed(count, array_of_blocklengths,
198 array_of_displacements, oldtype,
199 newtype);
200 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
201 return rc;
202}
203
204int
205MPI_Type_create_indexed_block(int count, int blocklength,
206 XT_MPI2_CONST int array_of_displacements[],
207 MPI_Datatype oldtype, MPI_Datatype *newtype)
208{
209 fprintf(dt_out, "MPI_Type_create_indexed_block(%d, %d, (int){\n", count, blocklength);
210 for (int i = 0; i < count; ++i)
211 fprintf(dt_out, " %d,\n", array_of_displacements[i]);
212 fprintf(dt_out, "}, %jd);\n", (intmax_t)oldtype);
213 int rc = PMPI_Type_create_indexed_block(count, blocklength,
214 array_of_displacements,
215 oldtype, newtype);
216 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
217 return rc;
218}
219
220#if MPI_VERSION >= 3
221int
223 int count, int blocklength, XT_MPI2_CONST MPI_Aint array_of_displacements[],
224 MPI_Datatype oldtype, MPI_Datatype *newtype)
225{
226 fprintf(dt_out, "MPI_Type_create_indexed_block(%d, %d, (MPI_Aint){\n", count, blocklength);
227 for (int i = 0; i < count; ++i)
228 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_displacements[i]);
229 fprintf(dt_out, "}, %jd);\n", (intmax_t)oldtype);
230 int rc = PMPI_Type_create_hindexed_block(count, blocklength,
231 array_of_displacements,
232 oldtype, newtype);
233 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
234 return rc;
235}
236#endif
237
238int
239MPI_Type_create_resized(MPI_Datatype oldtype, MPI_Aint lb,
240 MPI_Aint extent, MPI_Datatype *newtype)
241{
242 fprintf(dt_out, "MPI_Type_create_resized(%jd, %jd, %jd);\n",
243 (intmax_t)oldtype, (intmax_t)lb, (intmax_t)extent);
244 int rc = PMPI_Type_create_resized(oldtype, lb, extent, newtype);
245 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
246 return rc;
247}
248
249
250int
251MPI_Type_struct(int count, int *array_of_blocklengths,
252 MPI_Aint *array_of_displacements, MPI_Datatype *array_of_types,
253 MPI_Datatype *newtype)
254{
255 fprintf(dt_out, "MPI_Type_struct(%d, (int){\n", count);
256 for (int i = 0; i < count; ++i)
257 fprintf(dt_out, " %d,\n", array_of_blocklengths[i]);
258 fputs("}, (MPI_Aint[]){\n", dt_out);
259 for (int i = 0; i < count; ++i)
260 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_displacements[i]);
261 fputs("}, (MPI_Datatype[]){\n", dt_out);
262 for (int i = 0; i < count; ++i)
263 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_types[i]);
264 fputs("});\n", dt_out);
265 int rc = PMPI_Type_struct(
266 count, array_of_blocklengths, array_of_displacements,
267 array_of_types, newtype);
268 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
269 return rc;
270}
271
272int
273MPI_Type_create_struct(int count, XT_MPI2_CONST int array_of_block_lengths[],
274 XT_MPI2_CONST MPI_Aint array_of_displacements[],
275 XT_MPI2_CONST MPI_Datatype array_of_types[],
276 MPI_Datatype *newtype)
277{
278 fprintf(dt_out, "MPI_Type_create_struct(%d, (int){\n", count);
279 for (int i = 0; i < count; ++i)
280 fprintf(dt_out, " %d,\n", array_of_block_lengths[i]);
281 fputs("}, (MPI_Aint[]){\n", dt_out);
282 for (int i = 0; i < count; ++i)
283 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_displacements[i]);
284 fputs("}, (MPI_Datatype[]){\n", dt_out);
285 for (int i = 0; i < count; ++i)
286 fprintf(dt_out, " %jd,\n", (intmax_t)array_of_types[i]);
287 fputs("});\n", dt_out);
288 int rc = PMPI_Type_create_struct(
289 count, array_of_block_lengths, array_of_displacements,
290 array_of_types, newtype);
291 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
292 return rc;
293}
294
295int
296MPI_Type_create_darray(int size, int rank, int ndims,
297 XT_MPI2_CONST int gsize_array[], XT_MPI2_CONST int distrib_array[],
298 XT_MPI2_CONST int darg_array[], XT_MPI2_CONST int psize_array[],
299 int order, MPI_Datatype oldtype,
300 MPI_Datatype *newtype)
301{
302 int rc = PMPI_Type_create_darray(
303 size, rank, ndims, gsize_array, distrib_array, darg_array, psize_array,
304 order, oldtype, newtype);
305 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
306 return rc;
307}
308
309int
311 XT_MPI2_CONST int size_array[],
312 XT_MPI2_CONST int subsize_array[],
313 XT_MPI2_CONST int start_array[],
314 int order,
315 MPI_Datatype oldtype,
316 MPI_Datatype *newtype)
317{
318 int rc = PMPI_Type_create_subarray(ndims, size_array, subsize_array,
319 start_array, order, oldtype, newtype);
320 fprintf(dt_out, "%jd\n", (intmax_t)(*newtype));
321 return rc;
322}
323
324
325int
326MPI_Type_free(MPI_Datatype *datatype)
327{
328 fprintf(dt_out, "MPI_Type_free(&%jd);\n", (intmax_t)(*datatype));
329 int rc = PMPI_Type_free(datatype);
330 return rc;
331}
332
333int
334MPI_Type_commit(MPI_Datatype *datatype)
335{
336 fprintf(dt_out, "MPI_Type_commit(&%jd);\n", (intmax_t)(*datatype));
337 int rc = PMPI_Type_commit(datatype);
338 return rc;
339}
340
341/*
342 * Local Variables:
343 * c-basic-offset: 2
344 * coding: utf-8
345 * indent-tabs-mode: nil
346 * show-trailing-whitespace: t
347 * require-trailing-newline: t
348 * End:
349 */
#define __attribute__(x)
Definition core.h:82
int MPI_Type_create_struct(int count, XT_MPI2_CONST int array_of_block_lengths[], XT_MPI2_CONST MPI_Aint array_of_displacements[], XT_MPI2_CONST MPI_Datatype array_of_types[], MPI_Datatype *newtype)
int MPI_Type_struct(int count, int *array_of_blocklengths, MPI_Aint *array_of_displacements, MPI_Datatype *array_of_types, MPI_Datatype *newtype)
int MPI_Type_create_hvector(int count, int blocklength, MPI_Aint stride, MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_create_resized(MPI_Datatype oldtype, MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype)
int MPI_Type_create_indexed_block(int count, int blocklength, XT_MPI2_CONST int array_of_displacements[], MPI_Datatype oldtype, MPI_Datatype *newtype)
static FILE * dt_out
int MPI_Type_contiguous(int count, MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_free(MPI_Datatype *datatype)
int MPI_Type_create_subarray(int ndims, XT_MPI2_CONST int size_array[], XT_MPI2_CONST int subsize_array[], XT_MPI2_CONST int start_array[], int order, MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_create_darray(int size, int rank, int ndims, XT_MPI2_CONST int gsize_array[], XT_MPI2_CONST int distrib_array[], XT_MPI2_CONST int darg_array[], XT_MPI2_CONST int psize_array[], int order, MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_indexed(int count, XT_MPI2_CONST int array_of_blocklengths[], XT_MPI2_CONST int array_of_displacements[], MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_hvector(int count, int blocklength, MPI_Aint stride, MPI_Datatype oldtype, MPI_Datatype *newtype)
static void init_instr(void)
int MPI_Type_create_hindexed(int count, XT_MPI2_CONST int array_of_blocklengths[], XT_MPI2_CONST MPI_Aint array_of_displacements[], MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_dup(MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_vector(int count, int blocklength, int stride, MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_hindexed(int count, int array_of_blocklengths[], MPI_Aint array_of_displacements[], MPI_Datatype oldtype, MPI_Datatype *newtype)
int MPI_Type_commit(MPI_Datatype *datatype)
#define MPI_Type_create_hindexed_block