GCC Code Coverage Report


Directory: src/
File: src/xt_redist_repeat.c
Date: 2024-11-08 09:02:52
Exec Total Coverage
Lines: 36 42 85.7%
Branches: 8 12 66.7%

Line Branch Exec Source
1 /**
2 * @file xt_redist_repeat.c
3 *
4 * @copyright Copyright (C) 2016 Jörg Behrens <behrens@dkrz.de>
5 * Moritz Hanke <hanke@dkrz.de>
6 * Thomas Jahns <jahns@dkrz.de>
7 *
8 * @author Jörg Behrens <behrens@dkrz.de>
9 * Moritz Hanke <hanke@dkrz.de>
10 * Thomas Jahns <jahns@dkrz.de>
11 */
12 /*
13 * Keywords:
14 * Maintainer: Jörg Behrens <behrens@dkrz.de>
15 * Moritz Hanke <hanke@dkrz.de>
16 * Thomas Jahns <jahns@dkrz.de>
17 * URL: https://dkrz-sw.gitlab-pages.dkrz.de/yaxt/
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met:
22 *
23 * Redistributions of source code must retain the above copyright notice,
24 * this list of conditions and the following disclaimer.
25 *
26 * Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 *
30 * Neither the name of the DKRZ GmbH nor the names of its contributors
31 * may be used to endorse or promote products derived from this software
32 * without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
36 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
37 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
38 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 */
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49
50 #include <assert.h>
51 #include <limits.h>
52 #include <stdlib.h>
53
54 #include <mpi.h>
55
56 #include "core/core.h"
57 #include "core/ppm_xfuncs.h"
58 #include "xt/xt_mpi.h"
59 #include "xt_mpi_internal.h"
60 #include "xt/xt_redist_repeat.h"
61 #include "xt/xt_redist_single_array_base.h"
62 #include "ensure_array_size.h"
63 #include "xt/xt_redist.h"
64 #include "xt_redist_internal.h"
65 #include "xt_config_internal.h"
66
67
68
69 static const char filename[] = "xt_redist_repeat.c";
70
71 static void
72 158 generate_msg_infos(struct Xt_redist_msg *restrict msgs,
73 MPI_Aint extent, const int *displacements, Xt_redist redist,
74 int num_repetitions, MPI_Comm comm,
75 enum xt_msg_direction direction)
76 {
77 158 int *restrict ranks = NULL;
78 158 size_t num_ranks
79 158 = (size_t)xt_redist_get_msg_ranks(redist, direction, &ranks);
80
2/2
✓ Branch 0 taken 766 times.
✓ Branch 1 taken 158 times.
924 for (size_t i = 0; i < num_ranks; ++i) {
81 MPI_Datatype datatype
82 766 = xt_redist_get_MPI_Datatype(redist, ranks[i], direction, false);
83 MPI_Aint curr_lb, curr_extent;
84 MPI_Datatype datatype_with_extent;
85
86 // adjust extent of datatype to match the displacements
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 766 times.
766 xt_mpi_call(MPI_Type_get_extent(datatype, &curr_lb, &curr_extent), comm);
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 766 times.
766 xt_mpi_call(MPI_Type_create_resized(datatype, curr_lb, extent,
89 &datatype_with_extent), comm);
90
91 766 msgs[i].rank = ranks[i];
92 766 msgs[i].datatype
93 766 = xt_mpi_generate_datatype(displacements, num_repetitions,
94 datatype_with_extent, comm);
95 766 MPI_Type_free(&datatype_with_extent);
96 }
97 158 free(ranks);
98 158 }
99
100 Xt_redist
101 xt_redist_repeat_asym_new(Xt_redist redist, MPI_Aint src_extent,
102 MPI_Aint dst_extent, int num_repetitions,
103 const int src_displacements[num_repetitions],
104 const int dst_displacements[num_repetitions])
105 {
106 return xt_redist_repeat_asym_custom_new(
107 redist, src_extent, dst_extent, num_repetitions,
108 src_displacements, dst_displacements, (Xt_config)&xt_default_config);
109 }
110
111 Xt_redist
112 79 xt_redist_repeat_asym_custom_new(Xt_redist redist, MPI_Aint src_extent,
113 MPI_Aint dst_extent, int num_repetitions,
114 const int src_displacements[num_repetitions],
115 const int dst_displacements[num_repetitions],
116 Xt_config config)
117 79 {
118 // ensure that yaxt is initialized
119
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
79 assert(xt_initialized());
120
121 int tag_offset;
122 79 MPI_Comm comm
123 79 = xt_mpi_comm_smart_dup(xt_redist_get_MPI_Comm(redist), &tag_offset);
124
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79 times.
79 if (num_repetitions < 1)
126 Xt_abort(comm, "ERROR: invalid number of repetitions (Xt_redist_repeat)\n",
127 filename, __LINE__);
128
129 int nmsg[2];
130
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 79 times.
237 for (int i = 0; i < 2; ++i)
131 158 nmsg[i] = redist->vtable->get_num_msg(redist, (enum xt_msg_direction)i);
132 79 size_t num_messages = (size_t)nmsg[SEND] + (size_t)nmsg[RECV];
133 79 struct Xt_redist_msg *msgs = xmalloc(sizeof (*msgs) * num_messages);
134
135 79 generate_msg_infos(msgs, src_extent, src_displacements,
136 redist, num_repetitions, comm, SEND);
137
138 79 generate_msg_infos(msgs+nmsg[0], dst_extent, dst_displacements,
139 redist, num_repetitions, comm, RECV);
140
141 79 struct Xt_config_ config_ = *config;
142 79 config_.flags |= exch_no_dt_dup;
143
144 79 Xt_redist result = xt_redist_single_array_base_custom_new(
145 79 nmsg[SEND], nmsg[RECV], msgs, msgs+nmsg[SEND], comm, &config_);
146 79 free(msgs);
147 79 xt_mpi_comm_smart_dedup(&comm, tag_offset);
148 79 return result;
149 }
150
151 Xt_redist xt_redist_repeat_new(Xt_redist redist, MPI_Aint src_extent,
152 MPI_Aint dst_extent, int num_repetitions,
153 const int displacements[num_repetitions]) {
154 return xt_redist_repeat_asym_custom_new(
155 redist, src_extent, dst_extent, num_repetitions, displacements,
156 displacements, (Xt_config)&xt_default_config);
157 }
158
159 76 Xt_redist xt_redist_repeat_custom_new(Xt_redist redist, MPI_Aint src_extent,
160 MPI_Aint dst_extent, int num_repetitions,
161 const int displacements[num_repetitions],
162 Xt_config config)
163 76 {
164 76 return xt_redist_repeat_asym_custom_new(
165 redist, src_extent, dst_extent, num_repetitions, displacements,
166 displacements, config);
167 }
168
169 /*
170 * Local Variables:
171 * c-basic-offset: 2
172 * coding: utf-8
173 * indent-tabs-mode: nil
174 * show-trailing-whitespace: t
175 * require-trailing-newline: t
176 * End:
177 */
178