9.1
general documentation
cs_halo.h
Go to the documentation of this file.
1#ifndef CS_HALO_H
2#define CS_HALO_H
3
4/*============================================================================
5 * Structure and function headers handling with ghost cells
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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/*----------------------------------------------------------------------------
31 * Local headers
32 *----------------------------------------------------------------------------*/
33
34#include "base/cs_defs.h"
35#include "base/cs_array.h"
36#include "base/cs_base.h"
37#include "base/cs_base_accel.h"
38#include "base/cs_interface.h"
40
41#include "fvm/fvm_periodicity.h"
42
43/*----------------------------------------------------------------------------*/
44
46
47/*============================================================================
48 * Macro definitions
49 *============================================================================*/
50
51/*=============================================================================
52 * Type definitions
53 *============================================================================*/
54
57typedef enum {
58
62
64
65/* Halo communication mode */
66
67typedef enum {
68
74
75/* Structure for halo management */
76/* ----------------------------- */
77
78typedef struct {
79
80 int n_c_domains; /* Number of communicating domains. */
81 int n_transforms; /* Number of periodic transformations */
82
83 int *c_domain_rank; /* List of communicating ranks */
84
85 const fvm_periodicity_t * periodicity; /* Pointer to periodicity
86 structure describing transforms */
87
88 int n_rotations; /* Number of periodic transformations
89 involving rotations */
90
91 cs_lnum_t n_local_elts; /* Number of local elements */
92
93 /* send_halo features : send to distant ranks */
94
95 cs_lnum_t n_send_elts[2]; /* Numer of ghost elements in send_list
96 n_elts[0] = standard elements
97 n_elts[1] = extended + standard elements */
98
99 cs_lnum_t *send_list; /* List of local elements in distant halos
100 (0 to n-1 numbering) */
101
102 cs_lnum_t *send_index; /* Index on send_list
103 Size = 2*n_c_domains + 1. For each rank, we
104 have an index for standard halo and one
105 for extended halo. */
106
107 cs_lnum_t *send_perio_lst; /* For each transformation and for each type of
108 halo on each communicating rank, we store
109 2 values:
110 - start index,
111 - number of elements. */
112
113 cs_lnum_t std_send_block_size; /* Send block size for packing */
114 cs_lnum_t n_std_send_blocks; /* Number of send blocks for packing with
115 standard exchange */
116 cs_lnum_t *std_send_blocks; /* Block start and end info for packing
117 with standard exchange */
118
119 /* halo features : receive from distant ranks */
120
121 cs_lnum_t n_elts[2]; /* Numer of ghost elements in halo
122 n_elts[0] = standard elements
123 n_elts[1] = extended + standard elements */
124
125 cs_lnum_t *index; /* Index on halo sections;
126 Size = 2*n_c_domains + 1. For each rank, we
127 have an index for the standard halo and one
128 for the extended halo. */
129
130 cs_lnum_t *perio_lst; /* For each transformation and for each type of halo
131 on each communicating rank, we store 2 values:
132 - start index,
133 - number of elements. */
134
135 /* Organization of perio_lst:
136
137 -------------------------------------------------
138 T1: | | | | | | | | | | | | |
139 -------------------------------------------------
140 idx n idx n idx n idx n idx n idx n
141 ______ ______ ______ ______ ______ ______
142 std ext std ext std ext
143 ___________ ___________ ___________
144 rank 0 rank 1 rank 2
145
146 -------------------------------------------------
147 T2: | | | | | | | | | | | | |
148 -------------------------------------------------
149 idx n idx n idx n idx n idx n idx n
150 ______ ______ ______ ______ ______ ______
151 std ext std ext std ext
152 ___________ ___________ ___________
153 rank 0 rank 1 rank 2
154
155 -------------------------------------------------
156 T3: | | | | | | | | | | | | |
157 -------------------------------------------------
158 idx n idx n idx n idx n idx n idx n
159 ______ ______ ______ ______ ______ ______
160 std ext std ext std ext
161 ___________ ___________ ___________
162 rank 0 rank 1 rank 2
163
164 etc...
165
166 */
167
168#if defined(HAVE_MPI)
169
170 MPI_Group c_domain_group; /* Group of connected domains */
171 cs_lnum_t *c_domain_s_shift; /* Target buffer shift for distant
172 ranks using one-sided get */
173#endif
174
175} cs_halo_t;
176
179typedef struct _cs_halo_state_t cs_halo_state_t;
180
181/*=============================================================================
182 * Global static variables
183 *============================================================================*/
184
186#ifdef __cplusplus
187
188/*=============================================================================
189 * Public function prototypes
190 *============================================================================*/
191
192/*----------------------------------------------------------------------------*/
200/*----------------------------------------------------------------------------*/
201
202cs_halo_t *
204
205/*----------------------------------------------------------------------------*/
206/*
207 * \brief Ready halo for use.
208 *
209 * This function should be called after building a halo using the
210 * cs_halo_create_function and defined locally.
211 * It is called automatically by cs_halo_create_from_ref and
212 * cs_halo_create_from_rank_neigbors so does not need to be called again
213 * using these functions.
214 *
215 * \param[in] halo pointer to halo structure
216 */
217/*----------------------------------------------------------------------------*/
218
219void
221
222/*----------------------------------------------------------------------------*/
223/*
224 * \brief Create a halo structure, given a reference halo.
225 *
226 * \param[in] ref pointer to reference halo
227 *
228 * \return pointer to created cs_halo_t structure
229 */
230/*----------------------------------------------------------------------------*/
231
232cs_halo_t *
234
235#if defined(HAVE_MPI)
236
237/*----------------------------------------------------------------------------*/
238/*
239 * \brief Create a halo structure from distant element distant ranks and ids.
240 *
241 * \param[in] rn associated rank neighbors info
242 * \param[in] n_local_elts number of elements for local rank
243 * \param[in] n_distant_elts number of distant elements for local rank
244 * \param[in] elt_rank_idx distant element rank index in rank neighbors,
245 * ordered by rank (size: n_distant_elts)
246 * \param[in] elt_id distant element id (at distant rank),
247 * ordered by rank (size: n_distant_elts)
248 * \param[in] elt_tr_id distant element transform id (-1 for
249 * non-periodic elements), null if non-periodic
250 * \param[in] periodicity optional periodicity, or null
251 *
252 * \return pointer to created cs_halo_t structure
253 */
254/*----------------------------------------------------------------------------*/
255
256cs_halo_t *
257cs_halo_create_from_rank_neighbors
258(
259 const cs_rank_neighbors_t *rn,
260 cs_lnum_t n_local_elts,
261 cs_lnum_t n_distant_elts,
262 const int elt_rank_idx[],
263 const cs_lnum_t elt_id[],
264 const int16_t elt_tr_id[],
265 const fvm_periodicity_t *periodicity
266);
267
268/*----------------------------------------------------------------------------*/
284/*----------------------------------------------------------------------------*/
285
286cs_halo_t *
287cs_halo_create_from_rank_neighbors
288(
289 const cs_rank_neighbors_t *rn,
290 cs_lnum_t n_local_elts,
291 cs_lnum_t n_distant_elts,
292 const int elt_rank_idx[],
293 const cs_lnum_t elt_id[]
294);
295
296#endif /* HAVE_MPI */
297
298/*----------------------------------------------------------------------------*/
304/*----------------------------------------------------------------------------*/
305
306void
308
309/*----------------------------------------------------------------------------*/
310
311#endif // __cplusplus
313
314/*----------------------------------------------------------------------------*/
320/*----------------------------------------------------------------------------*/
321
324
325/*----------------------------------------------------------------------------*/
332/*----------------------------------------------------------------------------*/
333
334void
336
337/*----------------------------------------------------------------------------*/
343/*----------------------------------------------------------------------------*/
344
347
348/*----------------------------------------------------------------------------*/
358/*----------------------------------------------------------------------------*/
359
360static inline size_t
362 cs_datatype_t data_type,
363 int stride)
364{
365 size_t elt_size = cs_datatype_size[data_type]*stride;
366 size_t pack_size = halo->n_send_elts[CS_HALO_EXTENDED] * elt_size;
367
368 return pack_size;
369}
370
371/*----------------------------------------------------------------------------
372 * Apply local cells renumbering to a halo
373 *
374 * parameters:
375 * halo <-- pointer to halo structure
376 * new_cell_id <-- array indicating old -> new cell id (0 to n-1)
377 *---------------------------------------------------------------------------*/
378
379void
381 const cs_lnum_t new_cell_id[]);
382
383/*----------------------------------------------------------------------------
384 * Apply ghost cells renumbering to a halo
385 *
386 * parameters:
387 * halo <-- pointer to halo structure
388 * old_cell_id <-- array indicating new -> old cell id (0 to n-1)
389 *---------------------------------------------------------------------------*/
390
391void
393 const cs_lnum_t old_cell_id[]);
394
395/*----------------------------------------------------------------------------*/
418/*----------------------------------------------------------------------------*/
419
420void *
422 cs_halo_type_t sync_mode,
423 cs_datatype_t data_type,
424 int stride,
425 void *send_buf,
426 cs_halo_state_t *hs);
427
428/*----------------------------------------------------------------------------*/
447/*----------------------------------------------------------------------------*/
448
449void
450cs_halo_sync_pack(const cs_halo_t *halo,
451 cs_halo_type_t sync_mode,
452 cs_datatype_t data_type,
453 int stride,
454 void *val,
455 void *send_buf,
456 cs_halo_state_t *hs);
457
458#if defined(HAVE_ACCEL)
459
460/*----------------------------------------------------------------------------*/
480/*----------------------------------------------------------------------------*/
481
482void
483cs_halo_sync_pack_d(const cs_halo_t *halo,
484 cs_halo_type_t sync_mode,
485 cs_datatype_t data_type,
486 int stride,
487 void *val,
488 void *send_buf,
489 cs_halo_state_t *hs);
490
491#endif /* defined(HAVE_ACCEL) */
492
493/*----------------------------------------------------------------------------*/
508/*----------------------------------------------------------------------------*/
509
510void
511cs_halo_sync_start(const cs_halo_t *halo,
512 void *val,
513 cs_halo_state_t *hs);
514
515/*----------------------------------------------------------------------------*/
531/*----------------------------------------------------------------------------*/
532
533void
534cs_halo_sync_wait(const cs_halo_t *halo,
535 void *val,
536 cs_halo_state_t *hs);
537
538/*----------------------------------------------------------------------------*/
552/*----------------------------------------------------------------------------*/
553
554void
555cs_halo_sync(const cs_halo_t *halo,
556 cs_halo_type_t sync_mode,
557 cs_datatype_t data_type,
558 int stride,
559 void *val);
560
561#if defined(HAVE_ACCEL)
562
563/*----------------------------------------------------------------------------*/
578/*----------------------------------------------------------------------------*/
579
580void
581cs_halo_sync_d(const cs_halo_t *halo,
582 cs_halo_type_t sync_mode,
583 cs_datatype_t data_type,
584 int stride,
585 void *val);
586
587#endif /* defined(HAVE_ACCEL) */
588
589/*----------------------------------------------------------------------------
590 * Update array of any type of halo values in case of parallelism or
591 * periodicity.
592 *
593 * Data is untyped; only its size is given, so this function may also
594 * be used to synchronize interleaved multidimendsional data, using
595 * size = element_size*dim (assuming a homogeneous environment, at least
596 * as far as data encoding goes).
597 *
598 * This function aims at copying main values from local elements
599 * (id between 1 and n_local_elements) to ghost elements on distant ranks
600 * (id between n_local_elements + 1 to n_local_elements_with_halo).
601 *
602 * parameters:
603 * halo <-- pointer to halo structure
604 * sync_mode <-- synchronization mode (standard or extended)
605 * size <-- size of each element
606 * num <-> pointer to local number value array
607 *----------------------------------------------------------------------------*/
608
609void
611 cs_halo_type_t sync_mode,
612 size_t size,
613 void *val);
614
615/*----------------------------------------------------------------------------
616 * Update array of integer halo values in case of parallelism or periodicity.
617 *
618 * This function aims at copying main values from local elements
619 * (id between 1 and n_local_elements) to ghost elements on distant ranks
620 * (id between n_local_elements + 1 to n_local_elements_with_halo).
621 *
622 * parameters:
623 * halo <-- pointer to halo structure
624 * sync_mode <-- synchronization mode (standard or extended)
625 * num <-> pointer to local number value array
626 *----------------------------------------------------------------------------*/
627
628void
629cs_halo_sync_num(const cs_halo_t *halo,
630 cs_halo_type_t sync_mode,
631 cs_lnum_t num[]);
632
633/*----------------------------------------------------------------------------
634 * Update array of variable (floating-point) halo values in case of
635 * parallelism or periodicity.
636 *
637 * This function aims at copying main values from local elements
638 * (id between 1 and n_local_elements) to ghost elements on distant ranks
639 * (id between n_local_elements + 1 to n_local_elements_with_halo).
640 *
641 * parameters:
642 * halo <-- pointer to halo structure
643 * sync_mode <-- synchronization mode (standard or extended)
644 * var <-> pointer to variable value array
645 *----------------------------------------------------------------------------*/
646
647void
648cs_halo_sync_var(const cs_halo_t *halo,
649 cs_halo_type_t sync_mode,
650 cs_real_t var[]);
651
652/*----------------------------------------------------------------------------
653 * Update array of strided variable (floating-point) halo values in case
654 * of parallelism or periodicity.
655 *
656 * This function aims at copying main values from local elements
657 * (id between 1 and n_local_elements) to ghost elements on distant ranks
658 * (id between n_local_elements + 1 to n_local_elements_with_halo).
659 *
660 * parameters:
661 * halo <-- pointer to halo structure
662 * sync_mode <-- synchronization mode (standard or extended)
663 * var <-> pointer to variable value array
664 * stride <-- number of (interlaced) values by entity
665 *----------------------------------------------------------------------------*/
666
667void
669 cs_halo_type_t sync_mode,
670 cs_real_t var[],
671 int stride);
672
673/*----------------------------------------------------------------------------
674 * Return MPI_Barrier usage flag.
675 *
676 * returns:
677 * true if MPI barriers are used after posting receives and before posting
678 * sends, false otherwise
679 *---------------------------------------------------------------------------*/
680
681bool
683
684/*----------------------------------------------------------------------------
685 * Set MPI_Barrier usage flag.
686 *
687 * parameters:
688 * use_barrier <-- true if MPI barriers should be used after posting
689 * receives and before posting sends, false otherwise.
690 *---------------------------------------------------------------------------*/
691
692void
693cs_halo_set_use_barrier(bool use_barrier);
694
695/*----------------------------------------------------------------------------*/
701/*----------------------------------------------------------------------------*/
702
705
706/*----------------------------------------------------------------------------*/
712/*----------------------------------------------------------------------------*/
713
714void
716
717/*----------------------------------------------------------------------------*/
723/*----------------------------------------------------------------------------*/
724
727
728/*----------------------------------------------------------------------------*/
734/*----------------------------------------------------------------------------*/
735
736void
738
739/*----------------------------------------------------------------------------*/
740/*
741 * \brief Return pointer to working send buffer used by default halo state.
742 *
743 * This allows sharing the allocation with other operations which might be
744 * used frequently, such as range set scatters (which play a similar role to
745 * halos for data which can be on process boundaries, such as vertex or
746 * face-based data).
747 *
748 * If the current buffer's size is smaller than the requested size, it is
749 * increased.
750 *
751 * \warning The returned buffer should not be used while a halo exchange
752 * using the default halo state is in progress.
753 *
754 * \return] halo pointer to pointer to cs_halo structure to destroy.
755 */
756/*----------------------------------------------------------------------------*/
757
758void *
759cs_halo_get_default_buffer(size_t size);
760
761/*----------------------------------------------------------------------------
762 * Dump a cs_halo_t structure.
763 *
764 * parameters:
765 * halo <-- pointer to cs_halo_t struture
766 * print_level <-- 0 only dimensions and indexes are printed, else (1)
767 * everything is printed
768 *---------------------------------------------------------------------------*/
769
770void
771cs_halo_dump(const cs_halo_t *halo,
772 int print_level);
773
774/*----------------------------------------------------------------------------*/
775
777
778#if defined(__cplusplus)
779
780/*=============================================================================
781 * Public C++ functions
782 *============================================================================*/
783
784/*----------------------------------------------------------------------------*/
785/*
786 * \brief Update array of values in case of parallelism or periodicity.
787 *
788 * This function aims at copying main values from local elements
789 * (id between 1 and n_local_elements) to ghost elements on distant ranks
790 * (id between n_local_elements + 1 to n_local_elements_with_halo).
791 *
792 * \tparam[in] Stride number of (interlaced) values by entity
793 * \tparam[in] T value type
794 *
795 * \param[in] halo pointer to halo structure
796 * \param[in] sync_mode synchronization mode (standard or extended)
797 * \param[in] on_device run on accelerated device if possible
798 * \param[in, out] val pointer to variable value array
799 */
800/*----------------------------------------------------------------------------*/
801
802template <typename T>
803void
804cs_halo_sync(const cs_halo_t *halo,
805 cs_halo_type_t sync_mode,
806 bool on_device,
807 T val[]);
808
809template <int Stride, typename T>
810void
811cs_halo_sync(const cs_halo_t *halo,
812 cs_halo_type_t sync_mode,
813 bool on_device,
814 T val[][Stride]);
815
816/*----------------------------------------------------------------------------*/
817/*
818 * \brief Update array of values in case of parallelism or periodicity,
819 * using the standard neighborhood.
820 *
821 * This function aims at copying main values from local elements
822 * (id between 1 and n_local_elements) to ghost elements on distant ranks
823 * (id between n_local_elements + 1 to n_local_elements_with_halo).
824 *
825 * \tparam[in] Stride number of (interlaced) values by entity
826 * \tparam[in] T value type
827 *
828 * \param[in] halo pointer to halo structure
829 * \param[in] on_device run on accelerated device if possible
830 * \param[in, out] val pointer to variable value array
831 */
832/*----------------------------------------------------------------------------*/
833
834template <typename T>
835void
836cs_halo_sync(const cs_halo_t *halo,
837 bool on_device,
838 T val[]);
839
840template <int Stride, typename T>
841void
842cs_halo_sync(const cs_halo_t *halo,
843 bool on_device,
844 T val[][Stride]);
845
846/*----------------------------------------------------------------------------*/
847/*
848 * \brief Update ghost cell values of a spatial vector field,
849 * including rotational periodicity if present.
850 *
851 * This function aims at copying main values from local elements
852 * (id between 1 and n_local_elements) to ghost elements on distant ranks
853 * (id between n_local_elements + 1 to n_local_elements_with_halo).
854 *
855 * \tparam[in] T value type
856 *
857 * \param[in] halo pointer to halo structure
858 * \param[in] sync_mode synchronization mode (standard or extended)
859 * \param[in] on_device run on accelerated device if possible
860 * \param[in, out] val pointer to variable value array
861 */
862/*----------------------------------------------------------------------------*/
863
864template <typename T>
865void
866cs_halo_sync_r(const cs_halo_t *halo,
867 cs_halo_type_t sync_mode,
868 bool on_device,
869 T val[][3]);
870
871/*----------------------------------------------------------------------------*/
872/*
873 * \brief Update ghost cell values of a spatial vector field,
874 * including rotational periodicity if present,
875 * using the standard neighborhood.
876 *
877 * This function aims at copying main values from local elements
878 * (id between 1 and n_local_elements) to ghost elements on distant ranks
879 * (id between n_local_elements + 1 to n_local_elements_with_halo).
880 *
881 * \tparam[in] T value type
882 *
883 * \param[in] halo pointer to halo structure
884 * \param[in] on_device run on accelerated device if possible
885 * \param[in, out] val pointer to variable value array
886 */
887/*----------------------------------------------------------------------------*/
888
889template <typename T>
890void
891cs_halo_sync_r(const cs_halo_t *halo,
892 bool on_device,
893 T val[][3]);
894
895/*----------------------------------------------------------------------------*/
896/*
897 * \brief Update ghost cell values of a symmetric tensor field,
898 * including rotational periodicity if present.
899 *
900 * This function aims at copying main values from local elements
901 * (id between 1 and n_local_elements) to ghost elements on distant ranks
902 * (id between n_local_elements + 1 to n_local_elements_with_halo).
903 *
904 * \tparam[in] T value type
905 *
906 * \param[in] halo pointer to halo structure
907 * \param[in] sync_mode synchronization mode (standard or extended)
908 * \param[in] on_device run on accelerated device if possible
909 * \param[in, out] val pointer to variable value array
910 */
911/*----------------------------------------------------------------------------*/
912
913template <typename T>
914void
915cs_halo_sync_r(const cs_halo_t *halo,
916 cs_halo_type_t sync_mode,
917 bool on_device,
918 T val[][6]);
919
920/*----------------------------------------------------------------------------*/
921/*
922 * \brief Update ghost cell values of a symmetric tensor field,
923 * including rotational periodicity if present,
924 * using the standard neighborhood.
925 *
926 * This function aims at copying main values from local elements
927 * (id between 1 and n_local_elements) to ghost elements on distant ranks
928 * (id between n_local_elements + 1 to n_local_elements_with_halo).
929 *
930 * \tparam[in] T value type
931 *
932 * \param[in] halo pointer to halo structure
933 * \param[in] sync_mode synchronization mode (standard or extended)
934 * \param[in] on_device run on accelerated device if possible
935 * \param[in, out] val pointer to variable value array
936 */
937/*----------------------------------------------------------------------------*/
938
939template <typename T>
940void
941cs_halo_sync_r(const cs_halo_t *halo,
942 bool on_device,
943 T val[][6]);
944
945/*----------------------------------------------------------------------------*/
961/*----------------------------------------------------------------------------*/
962
963template <typename T>
964void
965cs_halo_sync_r(const cs_halo_t *halo,
966 cs_halo_type_t sync_mode,
967 bool on_device,
968 T val[][3][3]);
969
970/*----------------------------------------------------------------------------*/
971/*----------------------------------------------------------------------------*/
972
973template<typename T, int N>
974void
976(
977 const cs_halo_t *halo,
978 cs_halo_type_t sync_mode,
979 [[maybe_unused]] bool on_device,
981)
982{
983 static_assert(N == 1 || N == 2,
984 "Only possible for arrays of dim 1 or 2.");
985
986 if (halo == nullptr)
987 return;
988
989 cs_datatype_t datatype = cs_datatype_from_type<T>();
990
991 T *val = span.data();
992
993 int Stride = (N == 1) ? 1 : span.extent(1);
994
995#if defined(HAVE_ACCEL)
996 if (on_device)
997 cs_halo_sync_pack_d(halo,
998 sync_mode,
999 datatype,
1000 Stride,
1001 val,
1002 nullptr,
1003 nullptr);
1004 else
1005#endif
1006 cs_halo_sync_pack(halo,
1007 sync_mode,
1008 datatype,
1009 Stride,
1010 val,
1011 nullptr,
1012 nullptr);
1013
1014 cs_halo_sync_start(halo, val, nullptr);
1015
1016 cs_halo_sync_wait(halo, val, nullptr);
1017}
1018
1019template<typename T, int N>
1020void
1022(
1023 const cs_halo_t *halo,
1024 [[maybe_unused]] bool on_device,
1026)
1027{
1028 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, span);
1029}
1030
1031template<typename T, int N>
1032void
1034(
1035 const cs_halo_t *halo,
1036 cs_halo_type_t sync_mode,
1038)
1039{
1040 bool on_device = cs_mem_is_device_ptr(span.data());
1041 cs_halo_sync<T, N>(halo, sync_mode, on_device, span);
1042}
1043
1044template<typename T, int N>
1045void
1047(
1048 const cs_halo_t *halo,
1050)
1051{
1052 bool on_device = cs_mem_is_device_ptr(span.data());
1053 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, span);
1054}
1055
1056/*----------------------------------------------------------------------------*/
1057/*----------------------------------------------------------------------------*/
1058
1059template<typename T, int N>
1060void
1062(
1063 const cs_halo_t *halo,
1064 cs_halo_type_t sync_mode,
1065 [[maybe_unused]] bool on_device,
1066 cs_mdarray_r<T, N> array
1067)
1068{
1069 cs_halo_sync<T, N>(halo, sync_mode, on_device, array.view());
1070}
1071
1072template<typename T, int N>
1073void
1075(
1076 const cs_halo_t *halo,
1077 [[maybe_unused]] bool on_device,
1078 cs_mdarray_r<T, N> array
1079)
1080{
1081 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, array.view());
1082}
1083
1084template<typename T, int N>
1085void
1087(
1088 const cs_halo_t *halo,
1089 cs_halo_type_t sync_mode,
1090 cs_mdarray_r<T, N> array
1091)
1092{
1093 bool on_device = cs_mem_is_device_ptr(array.data());
1094 cs_halo_sync<T, N>(halo, sync_mode, on_device, array.view());
1095}
1096
1097template<typename T, int N>
1098void
1100(
1101 const cs_halo_t *halo,
1102 cs_mdarray_r<T, N> array
1103)
1104{
1105 bool on_device = cs_mem_is_device_ptr(array.data());
1106 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, array.view());
1107}
1108
1109/*----------------------------------------------------------------------------*/
1110
1111#endif // __cplusplus
1112
1113#endif /* CS_HALO_H */
Definition: cs_array.h:1111
CS_F_HOST_DEVICE mdspan< T, N, L > view()
Get span view of array, same dimensions as array.
Definition: cs_array.h:1544
CS_F_HOST_DEVICE T * data()
Getter to data array.
Definition: cs_array.h:2263
Definition: cs_mdspan.h:69
CS_F_HOST_DEVICE cs_lnum_t extent(int i)
Getter for extent along a given dimension.
Definition: cs_mdspan.h:454
CS_F_HOST_DEVICE T * data()
Getter for data raw pointer.
Definition: cs_mdspan.h:490
const size_t cs_datatype_size[]
Definition: cs_defs.cpp:133
cs_datatype_t
Definition: cs_defs.h:315
#define BEGIN_C_DECLS
Definition: cs_defs.h:554
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
#define END_C_DECLS
Definition: cs_defs.h:555
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
bool cs_halo_get_use_barrier(void)
Definition: cs_halo.cpp:2400
void cs_halo_sync_pack(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_datatype_t data_type, int stride, void *val, void *send_buf, cs_halo_state_t *hs)
Pack halo data to send into dense buffer.
Definition: cs_halo.cpp:1727
cs_halo_state_t * cs_halo_state_create(void)
Create a halo state structure.
Definition: cs_halo.cpp:1347
cs_halo_comm_mode_t
Definition: cs_halo.h:67
@ CS_HALO_COMM_P2P
Definition: cs_halo.h:69
@ CS_HALO_COMM_RMA_GET
Definition: cs_halo.h:70
void cs_halo_state_destroy(cs_halo_state_t **halo_state)
Destroy a halo state structure.
Definition: cs_halo.cpp:1396
void cs_halo_sync_start(const cs_halo_t *halo, void *val, cs_halo_state_t *hs)
Launch update array of values in case of parallelism or periodicity.
Definition: cs_halo.cpp:1945
cs_halo_comm_mode_t cs_halo_get_comm_mode(void)
Get default communication mode for halo exchange.
Definition: cs_halo.cpp:2428
void cs_halo_sync(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_datatype_t data_type, int stride, void *val)
Update array of values in case of parallelism or periodicity.
Definition: cs_halo.cpp:2228
void * cs_halo_get_default_buffer(size_t size)
Return pointer to working send buffer used by default halo state.
Definition: cs_halo.cpp:2496
void cs_halo_set_comm_mode(cs_halo_comm_mode_t mode)
Set default communication mode for halo exchange.
Definition: cs_halo.cpp:2442
cs_alloc_mode_t cs_halo_get_buffer_alloc_mode(void)
Get default host/device allocation mode for message packing arrays.
Definition: cs_halo.cpp:2457
static size_t cs_halo_pack_size(const cs_halo_t *halo, cs_datatype_t data_type, int stride)
Compute required size for packing send data into dense buffer.
Definition: cs_halo.h:361
void cs_halo_renumber_cells(cs_halo_t *halo, const cs_lnum_t new_cell_id[])
Definition: cs_halo.cpp:1445
cs_halo_t * cs_halo_create_from_ref(const cs_halo_t *ref)
Create a halo structure, given a reference halo.
Definition: cs_halo.cpp:856
void cs_halo_dump(const cs_halo_t *halo, int print_level)
Definition: cs_halo.cpp:2523
cs_halo_t * cs_halo_create(const cs_interface_set_t *ifs)
Create a halo structure given an interface set.
Definition: cs_halo.cpp:600
void cs_halo_sync_wait(const cs_halo_t *halo, void *val, cs_halo_state_t *hs)
Wait for completion of update array of values in case of parallelism or periodicity.
Definition: cs_halo.cpp:2118
void cs_halo_set_use_barrier(bool use_barrier)
Definition: cs_halo.cpp:2414
cs_halo_type_t
Definition: cs_halo.h:57
@ CS_HALO_N_TYPES
Definition: cs_halo.h:61
@ CS_HALO_STANDARD
Definition: cs_halo.h:59
@ CS_HALO_EXTENDED
Definition: cs_halo.h:60
void * cs_halo_sync_pack_init_state(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_datatype_t data_type, int stride, void *send_buf, cs_halo_state_t *hs)
Initialize halo state prior to packing halo data to send.
Definition: cs_halo.cpp:1631
void cs_halo_create_complete(cs_halo_t *halo)
Ready halo for use.
Definition: cs_halo.cpp:745
void cs_halo_sync_untyped(const cs_halo_t *halo, cs_halo_type_t sync_mode, size_t size, void *val)
Definition: cs_halo.cpp:2316
cs_halo_state_t * cs_halo_state_get_default(void)
Get pointer to default halo state structure.
Definition: cs_halo.cpp:1431
void cs_halo_set_buffer_alloc_mode(cs_alloc_mode_t mode)
Set default host/device allocation mode for message packing arrays.
Definition: cs_halo.cpp:2471
void cs_halo_sync_var(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition: cs_halo.cpp:2360
void cs_halo_sync_num(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_lnum_t num[])
Definition: cs_halo.cpp:2338
void cs_halo_sync_r(const cs_halo_t *halo, cs_halo_type_t sync_mode, bool on_device, T val[][3])
Update ghost cell values of a spatial vector field, including rotational periodicity if present.
Definition: cs_halo.cpp:2860
void cs_halo_renumber_ghost_cells(cs_halo_t *halo, const cs_lnum_t old_cell_id[])
Definition: cs_halo.cpp:1469
void cs_halo_sync_var_strided(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[], int stride)
Definition: cs_halo.cpp:2383
void cs_halo_destroy(cs_halo_t **halo)
Definition: cs_halo.cpp:1298
struct _cs_halo_state_t cs_halo_state_t
Definition: cs_halo.h:179
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:61
static bool cs_mem_is_device_ptr(const void *ptr)
Check if a pointer is a device (or shared) pointer.
Definition: cs_mem.h:764
cs_alloc_mode_t
Definition: cs_mem.h:50
struct _fvm_periodicity_t fvm_periodicity_t
Definition: fvm_periodicity.h:67
Definition: cs_halo.h:78
int n_transforms
Definition: cs_halo.h:81
cs_lnum_t * index
Definition: cs_halo.h:125
cs_lnum_t * send_list
Definition: cs_halo.h:99
cs_lnum_t * send_index
Definition: cs_halo.h:102
int n_rotations
Definition: cs_halo.h:88
cs_lnum_t * std_send_blocks
Definition: cs_halo.h:116
cs_lnum_t n_local_elts
Definition: cs_halo.h:91
cs_lnum_t n_std_send_blocks
Definition: cs_halo.h:114
int n_c_domains
Definition: cs_halo.h:80
int * c_domain_rank
Definition: cs_halo.h:83
cs_lnum_t * perio_lst
Definition: cs_halo.h:130
cs_lnum_t std_send_block_size
Definition: cs_halo.h:113
cs_lnum_t * send_perio_lst
Definition: cs_halo.h:107
const fvm_periodicity_t * periodicity
Definition: cs_halo.h:85
cs_lnum_t n_send_elts[2]
Definition: cs_halo.h:95