9.2
general documentation
cs_all_to_all.h
Go to the documentation of this file.
1#ifndef CS_ALL_TO_ALL_H
2#define CS_ALL_TO_ALL_H
3
4/*============================================================================
5 * All-to-all parallel data exchange.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30#if defined(HAVE_MPI)
31#include <mpi.h>
32#endif
33
34/*----------------------------------------------------------------------------
35 * Local headers
36 *----------------------------------------------------------------------------*/
37
38#include "base/cs_block_dist.h"
39#include "base/cs_defs.h"
40#include "base/cs_parall.h"
42
43/*=============================================================================
44 * Macro definitions
45 *============================================================================*/
46
51#define CS_ALL_TO_ALL_USE_DEST_ID (1 << 0)
52#define CS_ALL_TO_ALL_ORDER_BY_SRC_RANK (1 << 1)
53
54#define CS_ALL_TO_ALL_NO_REVERSE (1 << 2)
55#define CS_ALL_TO_ALL_NEED_SRC_RANK (1 << 3)
56
57/*============================================================================
58 * Type definitions
59 *============================================================================*/
60
61/* All-to-all algorithm choice */
62
64typedef enum {
65
72
73/* Opaque all-to-all distribution structure */
74
75#if defined(HAVE_MPI)
76
77typedef struct _cs_all_to_all_t cs_all_to_all_t;
78
79#endif
80
81/*=============================================================================
82 * Public function prototypes
83 *============================================================================*/
84
85#if defined(HAVE_MPI)
86
87/*----------------------------------------------------------------------------*/
121/*----------------------------------------------------------------------------*/
122
124cs_all_to_all_create(size_t n_elts,
125 int flags,
126 const cs_lnum_t *dest_id,
127 const int dest_rank[],
128 MPI_Comm comm);
129
130/*----------------------------------------------------------------------------*/
152/*----------------------------------------------------------------------------*/
153
156 int flags,
157 const cs_gnum_t *src_gnum,
159 MPI_Comm comm);
160
161/*----------------------------------------------------------------------------*/
167/*----------------------------------------------------------------------------*/
168
169void
171
172/*----------------------------------------------------------------------------*/
182/*----------------------------------------------------------------------------*/
183
184void
186 int **dest_rank);
187
188/*----------------------------------------------------------------------------*/
199/*----------------------------------------------------------------------------*/
200
201void
203 cs_lnum_t **dest_id);
204
205/*----------------------------------------------------------------------------*/
218/*----------------------------------------------------------------------------*/
219
222
223/*----------------------------------------------------------------------------*/
250/*----------------------------------------------------------------------------*/
251
252void *
254 cs_datatype_t datatype,
255 int stride,
256 bool reverse,
257 const void *src_data,
258 void *dest_data);
259
260/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285
286cs_lnum_t *
288 bool reverse,
289 const cs_lnum_t *src_index,
290 cs_lnum_t *dest_index);
291
292/*----------------------------------------------------------------------------*/
320/*----------------------------------------------------------------------------*/
321
322void *
324 cs_datatype_t datatype,
325 bool reverse,
326 const cs_lnum_t *src_index,
327 const void *src_data,
328 const cs_lnum_t *dest_index,
329 void *dest_data);
330
331/*----------------------------------------------------------------------------*/
354/*----------------------------------------------------------------------------*/
355
356int *
358
359#endif /* defined(HAVE_MPI) */
360
361/*----------------------------------------------------------------------------*/
367/*----------------------------------------------------------------------------*/
368
371
372/*----------------------------------------------------------------------------*/
378/*----------------------------------------------------------------------------*/
379
380void
382
383/*----------------------------------------------------------------------------*/
389/*----------------------------------------------------------------------------*/
390
391void
393
394/*----------------------------------------------------------------------------*/
400/*----------------------------------------------------------------------------*/
401
402void
404
405/*----------------------------------------------------------------------------*/
410/*----------------------------------------------------------------------------*/
411
412void
414
415/*----------------------------------------------------------------------------*/
416
417#if defined(HAVE_MPI)
418
419/*----------------------------------------------------------------------------*/
444/*----------------------------------------------------------------------------*/
445
446template <typename T>
447T *
449 int stride,
450 bool reverse,
451 const T *src_data)
452{
453 return static_cast<T *>(cs_all_to_all_copy_array(d,
454 cs_datatype_from_type<T>(),
455 stride,
456 reverse,
457 src_data,
458 nullptr));
459};
460
461/*----------------------------------------------------------------------------*/
487/*----------------------------------------------------------------------------*/
488
489template <typename T>
490void
492 int stride,
493 bool reverse,
494 const T *src_data,
495 void *dest_data)
496{
498 cs_datatype_from_type<T>(),
499 stride,
500 reverse,
501 src_data,
502 dest_data);
503};
504
505/*----------------------------------------------------------------------------*/
531/*----------------------------------------------------------------------------*/
532
533template <typename T>
534T *
536 bool reverse,
537 const cs_lnum_t *src_index,
538 const T *src_data,
539 const cs_lnum_t *dest_index)
540{
541 return static_cast<T *>(cs_all_to_all_copy_indexed(d,
542 cs_datatype_from_type<T>(),
543 reverse,
544 src_index,
545 src_data,
546 dest_index,
547 nullptr));
548};
549
550/*----------------------------------------------------------------------------*/
577/*----------------------------------------------------------------------------*/
578
579template <typename T>
580void
582 bool reverse,
583 const cs_lnum_t *src_index,
584 const T *src_data,
585 const cs_lnum_t *dest_index,
586 void *dest_data)
587{
589 cs_datatype_from_type<T>(),
590 reverse,
591 src_index,
592 src_data,
593 dest_index,
594 dest_data);
595};
596
597#endif
598
599/*----------------------------------------------------------------------------*/
600
601#endif /* CS_ALL_TO_ALL_H */
void * cs_all_to_all_copy_array(cs_all_to_all_t *d, cs_datatype_t datatype, int stride, bool reverse, const void *src_data, void *dest_data)
Communicate array data using all-to-all distributor.
Definition: cs_all_to_all.cpp:2786
void * cs_all_to_all_copy_indexed(cs_all_to_all_t *d, cs_datatype_t datatype, bool reverse, const cs_lnum_t *src_index, const void *src_data, const cs_lnum_t *dest_index, void *dest_data)
Communicate local index using all-to-all distributor.
Definition: cs_all_to_all.cpp:3159
void cs_all_to_all_set_type(cs_all_to_all_type_t t)
Set current type of all-to-all distributor algorithm choice.
Definition: cs_all_to_all.cpp:3546
void cs_all_to_all_destroy(cs_all_to_all_t **d)
Destroy an all-to-all distributor.
Definition: cs_all_to_all.cpp:2509
cs_lnum_t cs_all_to_all_n_elts_dest(cs_all_to_all_t *d)
Get number of elements associated with all-to-all distributor.
Definition: cs_all_to_all.cpp:2622
struct _cs_all_to_all_t cs_all_to_all_t
Definition: cs_all_to_all.h:77
cs_all_to_all_type_t cs_all_to_all_get_type(void)
Get current type of all-to-all distributor algorithm choice.
Definition: cs_all_to_all.cpp:3503
void cs_all_to_all_log_finalize(void)
Log performance information relative to instrumented all-to-all distribution.
Definition: cs_all_to_all.cpp:3559
cs_lnum_t * cs_all_to_all_copy_index(cs_all_to_all_t *d, bool reverse, const cs_lnum_t *src_index, cs_lnum_t *dest_index)
Communicate local index using all-to-all distributor.
Definition: cs_all_to_all.cpp:3058
cs_all_to_all_type_t
Definition: cs_all_to_all.h:64
@ CS_ALL_TO_ALL_MPI_DEFAULT
Definition: cs_all_to_all.h:66
@ CS_ALL_TO_ALL_HYBRID
Definition: cs_all_to_all.h:68
@ CS_ALL_TO_ALL_CRYSTAL_ROUTER
Definition: cs_all_to_all.h:69
int * cs_all_to_all_get_src_rank(cs_all_to_all_t *d)
Get array of source element ranks associated with an all-to-all distributor.
Definition: cs_all_to_all.cpp:3432
cs_all_to_all_t * cs_all_to_all_create_from_block(size_t n_elts, int flags, const cs_gnum_t *src_gnum, cs_block_dist_info_t bi, MPI_Comm comm)
Create an all-to-all distributor for elements whose destination rank is determined from global number...
Definition: cs_all_to_all.cpp:2434
void cs_all_to_all_set_hybrid_parameters(cs_rank_neighbors_exchange_t rne_type)
Set current type of all-to-all distributor algorithm choice.
Definition: cs_all_to_all.cpp:3532
void cs_all_to_all_get_hybrid_parameters(cs_rank_neighbors_exchange_t *rne_type)
Get current type of hybrid all-to-all distributor parameters.
Definition: cs_all_to_all.cpp:3517
void cs_all_to_all_transfer_dest_id(cs_all_to_all_t *d, cs_lnum_t **dest_id)
Transfer ownership of destination ids to an all-to-all distributor.
Definition: cs_all_to_all.cpp:2589
cs_all_to_all_t * cs_all_to_all_create(size_t n_elts, int flags, const cs_lnum_t *dest_id, const int dest_rank[], MPI_Comm comm)
Create an all-to-all distributor based on destination rank.
Definition: cs_all_to_all.cpp:2376
void cs_all_to_all_transfer_dest_rank(cs_all_to_all_t *d, int **dest_rank)
Transfer ownership of destination rank to an all-to-all distributor.
Definition: cs_all_to_all.cpp:2558
cs_datatype_t
Definition: cs_defs.h:290
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:317
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
@ t
Definition: cs_field_pointer.h:91
cs_rank_neighbors_exchange_t
Definition: cs_rank_neighbors.h:51
Definition: cs_block_dist.h:46