Yet Another eXchange Tool 0.11.4
Loading...
Searching...
No Matches
xt_redist_repeat.c
Go to the documentation of this file.
1
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"
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
69static const char filename[] = "xt_redist_repeat.c";
70
71static void
72generate_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 int *restrict ranks = NULL;
78 size_t num_ranks
79 = (size_t)xt_redist_get_msg_ranks(redist, direction, &ranks);
80 for (size_t i = 0; i < num_ranks; ++i) {
81 MPI_Datatype datatype
82 = 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 xt_mpi_call(MPI_Type_get_extent(datatype, &curr_lb, &curr_extent), comm);
88 xt_mpi_call(MPI_Type_create_resized(datatype, curr_lb, extent,
89 &datatype_with_extent), comm);
90
91 msgs[i].rank = ranks[i];
92 msgs[i].datatype
93 = xt_mpi_generate_datatype(displacements, num_repetitions,
94 datatype_with_extent, comm);
95 MPI_Type_free(&datatype_with_extent);
96 }
97 free(ranks);
98}
99
101xt_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{
107 redist, src_extent, dst_extent, num_repetitions,
108 src_displacements, dst_displacements, (Xt_config)&xt_default_config);
109}
110
112xt_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{
118 // ensure that yaxt is initialized
119 assert(xt_initialized());
120
121 int tag_offset;
122 MPI_Comm comm
123 = xt_mpi_comm_smart_dup(xt_redist_get_MPI_Comm(redist), &tag_offset);
124
125 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 for (int i = 0; i < 2; ++i)
131 nmsg[i] = redist->vtable->get_num_msg(redist, (enum xt_msg_direction)i);
132 size_t num_messages = (size_t)nmsg[SEND] + (size_t)nmsg[RECV];
133 struct Xt_redist_msg *msgs = xmalloc(sizeof (*msgs) * num_messages);
134
135 generate_msg_infos(msgs, src_extent, src_displacements,
136 redist, num_repetitions, comm, SEND);
137
138 generate_msg_infos(msgs+nmsg[0], dst_extent, dst_displacements,
139 redist, num_repetitions, comm, RECV);
140
141 struct Xt_config_ config_ = *config;
142 config_.flags |= exch_no_dt_dup;
143
145 nmsg[SEND], nmsg[RECV], msgs, msgs+nmsg[SEND], comm, &config_);
146 free(msgs);
147 xt_mpi_comm_smart_dedup(&comm, tag_offset);
148 return result;
149}
150
151Xt_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]) {
155 redist, src_extent, dst_extent, num_repetitions, displacements,
156 displacements, (Xt_config)&xt_default_config);
157}
158
160 MPI_Aint dst_extent, int num_repetitions,
161 const int displacements[num_repetitions],
162 Xt_config config)
163{
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 */
int MPI_Comm
Definition core.h:64
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition ppm_xfuncs.h:70
const struct xt_redist_vtable * vtable
int(* get_num_msg)(Xt_redist, enum xt_msg_direction)
int MPI_Type_create_resized(MPI_Datatype oldtype, MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype)
int MPI_Type_free(MPI_Datatype *datatype)
struct Xt_config_ xt_default_config
Definition xt_config.c:204
implementation of configuration object
@ exch_no_dt_dup
int xt_initialized(void)
MPI_Comm xt_mpi_comm_smart_dup(MPI_Comm comm, int *tag_offset)
Definition xt_mpi.c:333
void xt_mpi_comm_smart_dedup(MPI_Comm *comm, int tag_offset)
Definition xt_mpi.c:386
utility routines for MPI
MPI_Datatype xt_mpi_generate_datatype(int const *displacements, int count, MPI_Datatype old_type, MPI_Comm comm)
#define xt_mpi_call(call, comm)
Definition xt_mpi.h:68
MPI_Datatype xt_redist_get_MPI_Datatype(Xt_redist redist, int rank, enum xt_msg_direction direction, bool do_dup)
Definition xt_redist.c:123
int xt_redist_get_msg_ranks(Xt_redist redist, enum xt_msg_direction direction, int *restrict *ranks)
Definition xt_redist.c:135
redistribution of data
MPI_Comm xt_redist_get_MPI_Comm(Xt_redist redist)
Definition xt_redist.c:130
redistribution of data, non-public declarations
xt_msg_direction
Xt_redist xt_redist_repeat_custom_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int displacements[num_repetitions], Xt_config config)
Xt_redist xt_redist_repeat_asym_custom_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int src_displacements[num_repetitions], const int dst_displacements[num_repetitions], Xt_config config)
static const char filename[]
Xt_redist xt_redist_repeat_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int displacements[num_repetitions])
static void generate_msg_infos(struct Xt_redist_msg *restrict msgs, MPI_Aint extent, const int *displacements, Xt_redist redist, int num_repetitions, MPI_Comm comm, enum xt_msg_direction direction)
Xt_redist xt_redist_repeat_asym_new(Xt_redist redist, MPI_Aint src_extent, MPI_Aint dst_extent, int num_repetitions, const int src_displacements[num_repetitions], const int dst_displacements[num_repetitions])
Xt_redist xt_redist_single_array_base_custom_new(int nsend, int nrecv, const struct Xt_redist_msg send_msgs[], const struct Xt_redist_msg recv_msgs[], MPI_Comm comm, Xt_config config)