YAC 3.18.0
Yet Another Coupler
Loading...
Searching...
No Matches
remote_point.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifdef HAVE_CONFIG_H
6// Get the definition of the 'restrict' keyword.
7#include "config.h"
8#endif
9
10#include "yac_mpi_common.h"
11#include "yac_mpi_internal.h"
12#include "remote_point.h"
13
14MPI_Datatype yac_get_remote_point_info_mpi_datatype(MPI_Comm comm) {
15
16 struct remote_point_info dummy;
17 MPI_Datatype remote_point_info_dt;
18 int array_of_blocklengths[] = {1, 1};
19 const MPI_Aint array_of_displacements[] =
20 {(MPI_Aint)(intptr_t)(const void *)&(dummy.rank) -
21 (MPI_Aint)(intptr_t)(const void *)&dummy,
22 (MPI_Aint)(intptr_t)(const void *)&(dummy.orig_pos) -
23 (MPI_Aint)(intptr_t)(const void *)&dummy};
24 const MPI_Datatype array_of_types[] =
25 {MPI_INT, MPI_UINT64_T};
27 MPI_Type_create_struct(2, array_of_blocklengths, array_of_displacements,
28 array_of_types, &remote_point_info_dt), comm);
29 return yac_create_resized(remote_point_info_dt, sizeof(dummy), comm);
30}
31
33 struct remote_point_infos const * infos, MPI_Datatype point_info_dt,
34 MPI_Comm comm) {
35
36 int pack_size_count,
37 pack_size_data;
38
40 infos->count > 0,
41 "ERROR(yac_remote_point_infos_get_pack_size): "
42 "count has to be > 0 (got %d)", infos->count)
43
44 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &pack_size_count), comm);
46 MPI_Pack_size(infos->count, point_info_dt, comm, &pack_size_data), comm);
47
48 return pack_size_count + pack_size_data;
49}
50
52 struct remote_point * point, MPI_Datatype point_info_dt, MPI_Comm comm) {
53
54 int pack_size_id,
55 pack_size_remote_point_infos;
56
57 yac_mpi_call(MPI_Pack_size(1, yac_int_dt, comm, &pack_size_id), comm);
58 pack_size_remote_point_infos =
59 yac_remote_point_infos_get_pack_size(&(point->data), point_info_dt, comm);
60
61 return pack_size_id + pack_size_remote_point_infos;
62}
63
65 struct remote_point_infos const * infos, void * buffer, int buffer_size,
66 int * position, MPI_Datatype point_info_dt, MPI_Comm comm) {
67
68 int count = infos->count;
69
71 count > 0,
72 "ERROR(yac_remote_point_infos_pack): "
73 "count has to be > 0 (got %d)", count)
74
75 struct remote_point_info const * info =
76 (count == 1)?(&(infos->data.single)):(infos->data.multi);
77
79 MPI_Pack(&count, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
81 MPI_Pack(info, count, point_info_dt, buffer, buffer_size, position, comm),
82 comm);
83}
84
86 struct remote_point * point, void * buffer, int buffer_size, int * position,
87 MPI_Datatype point_info_dt, MPI_Comm comm) {
88
90 MPI_Pack(&(point->global_id), 1, yac_int_dt, buffer,
91 buffer_size, position, comm), comm);
92
94 &(point->data), buffer, buffer_size, position, point_info_dt, comm);
95}
96
98 void * buffer, int buffer_size, int * position,
99 struct remote_point_infos * infos, MPI_Datatype point_info_dt, MPI_Comm comm) {
100
101 int count;
103 MPI_Unpack(buffer, buffer_size, position, &count, 1, MPI_INT, comm), comm);
104
105 infos->count = count;
106
108 count > 0, "ERROR(yac_remote_point_infos_unpack): "
109 "count has to be > 0 (got %d)", count)
110
111 struct remote_point_info * point_infos;
112 if (count == 1)
113 point_infos = &(infos->data.single);
114 else
115 point_infos =
116 (infos->data.multi = xmalloc((size_t)count * sizeof(*point_infos)));
117
119 MPI_Unpack(buffer, buffer_size, position, point_infos, count,
120 point_info_dt, comm), comm);
121}
122
124 void * buffer, int buffer_size, int * position, struct remote_point * point,
125 MPI_Datatype point_info_dt, MPI_Comm comm) {
126
128 MPI_Unpack(
129 buffer, buffer_size, position, &(point->global_id), 1, yac_int_dt, comm),
130 comm);
132 buffer, buffer_size, position, &(point->data), point_info_dt, comm);
133}
134
136 struct remote_points * points, MPI_Datatype point_info_dt, MPI_Comm comm) {
137
138 size_t count = points->count;
139 struct remote_point * points_data = points->data;
140
141 int count_pack_size,
142 remote_points_pack_size;
143
144 yac_mpi_call(MPI_Pack_size(2, MPI_UINT64_T, comm, &count_pack_size), comm);
145 remote_points_pack_size = 0;
146 for (size_t i = 0; i < count; ++i)
147 remote_points_pack_size +=
148 yac_remote_point_get_pack_size(points_data + i, point_info_dt, comm);
149
150 return count_pack_size + remote_points_pack_size;
151}
152
154 struct remote_points * points, void * buffer, int buffer_size, int * position,
155 MPI_Datatype point_info_dt, MPI_Comm comm) {
156
157 size_t count = points->count;
158 struct remote_point * point_data = points->data;
159 uint64_t counts[2] = {(uint64_t)count, 0};
160 for (size_t i = 0; i < count; ++i)
161 if (point_data[i].data.count > 1)
162 counts[1] += (uint64_t)(point_data[i].data.count);
163
165 MPI_Pack(counts, 2, MPI_UINT64_T, buffer,
166 buffer_size, position, comm), comm);
167 for (size_t i = 0; i < count; ++i)
169 point_data + i, buffer, buffer_size, position, point_info_dt, comm);
170}
171
173 void * buffer, int buffer_size, int * position,
174 struct remote_point_info * info_buffer, size_t * info_buffer_position,
175 struct remote_point_infos * infos, MPI_Datatype point_info_dt, MPI_Comm comm) {
176
177 int count;
179 MPI_Unpack(buffer, buffer_size, position, &count, 1, MPI_INT, comm), comm);
180
181 infos->count = count;
182
183 struct remote_point_info * point_infos;
184 if (count == 1)
185 point_infos = &(infos->data.single);
186 else {
187 point_infos =
188 (infos->data.multi = info_buffer + *info_buffer_position);
189 *info_buffer_position += count;
190 }
191
193 MPI_Unpack(buffer, buffer_size, position, point_infos, count,
194 point_info_dt, comm), comm);
195}
196
198 void * buffer, int buffer_size, int * position,
199 struct remote_point_info * info_buffer, size_t * info_buffer_position,
200 struct remote_point * point, MPI_Datatype point_info_dt, MPI_Comm comm) {
201
203 MPI_Unpack(
204 buffer, buffer_size, position, &(point->global_id), 1, yac_int_dt, comm),
205 comm);
207 buffer, buffer_size, position, info_buffer, info_buffer_position,
208 &(point->data), point_info_dt, comm);
209}
210
212 void * buffer, int buffer_size, int * position,
213 struct remote_points ** points, MPI_Datatype point_info_dt, MPI_Comm comm) {
214
215 uint64_t counts[2];
216
218 MPI_Unpack(
219 buffer, buffer_size, position, counts, 2, MPI_UINT64_T, comm), comm);
220
221 *points = xmalloc(((size_t)counts[1]) * sizeof(struct remote_point_infos) +
222 sizeof(**points));
223
224 size_t count = ((*points)->count = (size_t)(counts[0]));
225 struct remote_point * point_data =
226 ((*points)->data = xmalloc(count * sizeof(*((*points)->data))));
227 struct remote_point_info * remote_point_info_buffer =
228 &((*points)->buffer[0]);
229
230 for (size_t i = 0, offset = 0; i < count; ++i) {
231
233 buffer, buffer_size, position, remote_point_info_buffer, &offset,
234 point_data + i, point_info_dt, comm);
235 }
236}
#define xmalloc(size)
Definition ppm_xfuncs.h:66
void yac_remote_point_pack(struct remote_point *point, void *buffer, int buffer_size, int *position, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_point_unpack(void *buffer, int buffer_size, int *position, struct remote_point *point, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_point_infos_unpack(void *buffer, int buffer_size, int *position, struct remote_point_infos *infos, MPI_Datatype point_info_dt, MPI_Comm comm)
int yac_remote_point_infos_get_pack_size(struct remote_point_infos const *infos, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_points_pack(struct remote_points *points, void *buffer, int buffer_size, int *position, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_points_unpack(void *buffer, int buffer_size, int *position, struct remote_points **points, MPI_Datatype point_info_dt, MPI_Comm comm)
int yac_remote_points_get_pack_size(struct remote_points *points, MPI_Datatype point_info_dt, MPI_Comm comm)
MPI_Datatype yac_get_remote_point_info_mpi_datatype(MPI_Comm comm)
static void yac_remote_point_infos_unpack_info_buffer(void *buffer, int buffer_size, int *position, struct remote_point_info *info_buffer, size_t *info_buffer_position, struct remote_point_infos *infos, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_point_unpack_info_buffer(void *buffer, int buffer_size, int *position, struct remote_point_info *info_buffer, size_t *info_buffer_position, struct remote_point *point, MPI_Datatype point_info_dt, MPI_Comm comm)
void yac_remote_point_infos_pack(struct remote_point_infos const *infos, void *buffer, int buffer_size, int *position, MPI_Datatype point_info_dt, MPI_Comm comm)
int yac_remote_point_get_pack_size(struct remote_point *point, MPI_Datatype point_info_dt, MPI_Comm comm)
single location information of a point
location information about a point that is located on one or
union remote_point_infos::@53 data
struct remote_point_info single
struct remote_point_info * multi
information (global id and location) about a point that
yac_int global_id
struct remote_point_infos data
structure containing the information (global id and location)
double * data
int info
double * buffer
#define YAC_ASSERT_F(exp, format,...)
Definition yac_assert.h:30
MPI_Datatype yac_create_resized(MPI_Datatype dt, size_t new_size, MPI_Comm comm)
Definition yac_mpi.c:557
#define yac_mpi_call(call, comm)
#define yac_int_dt
Definition yac_types.h:18