YAC 3.8.0
Yet Another Coupler
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
39 yac_mpi_call(MPI_Pack_size(1, MPI_INT, comm, &pack_size_count), comm);
41 MPI_Pack_size(infos->count, point_info_dt, comm, &pack_size_data), comm);
42
43 return pack_size_count + pack_size_data;
44}
45
47 struct remote_point * point, MPI_Datatype point_info_dt, MPI_Comm comm) {
48
49 int pack_size_id,
50 pack_size_remote_point_infos;
51
52 yac_mpi_call(MPI_Pack_size(1, yac_int_dt, comm, &pack_size_id), comm);
53 pack_size_remote_point_infos =
54 yac_remote_point_infos_get_pack_size(&(point->data), point_info_dt, comm);
55
56 return pack_size_id + pack_size_remote_point_infos;
57}
58
60 struct remote_point_infos const * infos, void * buffer, int buffer_size,
61 int * position, MPI_Datatype point_info_dt, MPI_Comm comm) {
62
63 int count = infos->count;
64
65 struct remote_point_info const * info =
66 (count == 1)?(&(infos->data.single)):(infos->data.multi);
67
69 MPI_Pack(&count, 1, MPI_INT, buffer, buffer_size, position, comm), comm);
71 MPI_Pack(info, count, point_info_dt, buffer, buffer_size, position, comm),
72 comm);
73}
74
76 struct remote_point * point, void * buffer, int buffer_size, int * position,
77 MPI_Datatype point_info_dt, MPI_Comm comm) {
78
80 MPI_Pack(&(point->global_id), 1, yac_int_dt, buffer,
81 buffer_size, position, comm), comm);
82
84 &(point->data), buffer, buffer_size, position, point_info_dt, comm);
85}
86
88 void * buffer, int buffer_size, int * position,
89 struct remote_point_infos * infos, MPI_Datatype point_info_dt, MPI_Comm comm) {
90
91 int count;
93 MPI_Unpack(buffer, buffer_size, position, &count, 1, MPI_INT, comm), comm);
94
95 infos->count = count;
96
98 count > 0, "ERROR(yac_remote_point_infos_unpack): invalid count")
99
100 struct remote_point_info * point_infos;
101 if (count == 1)
102 point_infos = &(infos->data.single);
103 else
104 point_infos =
105 (infos->data.multi = xmalloc((size_t)count * sizeof(*point_infos)));
106
108 MPI_Unpack(buffer, buffer_size, position, point_infos, count,
109 point_info_dt, comm), comm);
110}
111
113 void * buffer, int buffer_size, int * position, struct remote_point * point,
114 MPI_Datatype point_info_dt, MPI_Comm comm) {
115
117 MPI_Unpack(
118 buffer, buffer_size, position, &(point->global_id), 1, yac_int_dt, comm),
119 comm);
121 buffer, buffer_size, position, &(point->data), point_info_dt, comm);
122}
123
125 struct remote_points * points, MPI_Datatype point_info_dt, MPI_Comm comm) {
126
127 size_t count = points->count;
128 struct remote_point * points_data = points->data;
129
130 int count_pack_size,
131 remote_points_pack_size;
132
133 yac_mpi_call(MPI_Pack_size(2, MPI_UINT64_T, comm, &count_pack_size), comm);
134 remote_points_pack_size = 0;
135 for (size_t i = 0; i < count; ++i)
136 remote_points_pack_size +=
137 yac_remote_point_get_pack_size(points_data + i, point_info_dt, comm);
138
139 return count_pack_size + remote_points_pack_size;
140}
141
143 struct remote_points * points, void * buffer, int buffer_size, int * position,
144 MPI_Datatype point_info_dt, MPI_Comm comm) {
145
146 size_t count = points->count;
147 struct remote_point * point_data = points->data;
148 uint64_t counts[2] = {(uint64_t)count, 0};
149 for (size_t i = 0; i < count; ++i)
150 if (point_data[i].data.count > 1)
151 counts[1] += (uint64_t)(point_data[i].data.count);
152
154 MPI_Pack(counts, 2, MPI_UINT64_T, buffer,
155 buffer_size, position, comm), comm);
156 for (size_t i = 0; i < count; ++i)
158 point_data + i, buffer, buffer_size, position, point_info_dt, comm);
159}
160
162 void * buffer, int buffer_size, int * position,
163 struct remote_point_info * info_buffer, size_t * info_buffer_position,
164 struct remote_point_infos * infos, MPI_Datatype point_info_dt, MPI_Comm comm) {
165
166 int count;
168 MPI_Unpack(buffer, buffer_size, position, &count, 1, MPI_INT, comm), comm);
169
170 infos->count = count;
171
172 struct remote_point_info * point_infos;
173 if (count == 1)
174 point_infos = &(infos->data.single);
175 else {
176 point_infos =
177 (infos->data.multi = info_buffer + *info_buffer_position);
178 *info_buffer_position += count;
179 }
180
182 MPI_Unpack(buffer, buffer_size, position, point_infos, count,
183 point_info_dt, comm), comm);
184}
185
187 void * buffer, int buffer_size, int * position,
188 struct remote_point_info * info_buffer, size_t * info_buffer_position,
189 struct remote_point * point, MPI_Datatype point_info_dt, MPI_Comm comm) {
190
192 MPI_Unpack(
193 buffer, buffer_size, position, &(point->global_id), 1, yac_int_dt, comm),
194 comm);
196 buffer, buffer_size, position, info_buffer, info_buffer_position,
197 &(point->data), point_info_dt, comm);
198}
199
201 void * buffer, int buffer_size, int * position,
202 struct remote_points ** points, MPI_Datatype point_info_dt, MPI_Comm comm) {
203
204 uint64_t counts[2];
205
207 MPI_Unpack(
208 buffer, buffer_size, position, counts, 2, MPI_UINT64_T, comm), comm);
209
210 *points = xmalloc(((size_t)counts[1]) * sizeof(struct remote_point_infos) +
211 sizeof(**points));
212
213 size_t count = ((*points)->count = (size_t)(counts[0]));
214 struct remote_point * point_data =
215 ((*points)->data = xmalloc(count * sizeof(*((*points)->data))));
216 struct remote_point_info * remote_point_info_buffer =
217 &((*points)->buffer[0]);
218
219 for (size_t i = 0, offset = 0; i < count; ++i) {
220
222 buffer, buffer_size, position, remote_point_info_buffer, &offset,
223 point_data + i, point_info_dt, comm);
224 }
225}
#define YAC_ASSERT(exp, msg)
#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
double * buffer
static struct user_input_data_points ** points
Definition yac.c:151
MPI_Datatype yac_create_resized(MPI_Datatype dt, size_t new_size, MPI_Comm comm)
Definition yac_mpi.c:556
#define yac_mpi_call(call, comm)
#define yac_int_dt
Definition yac_types.h:16