9.2
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-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/*----------------------------------------------------------------------------
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 * Macro definitions
45 *============================================================================*/
46
47/*=============================================================================
48 * Type definitions
49 *============================================================================*/
50
53typedef enum {
54
58
60
61/* Halo communication mode */
62
63typedef enum {
64
70
71/* Structure for halo management */
72/* ----------------------------- */
73
74typedef struct {
75
76 int n_c_domains; /* Number of communicating domains. */
77 int n_transforms; /* Number of periodic transformations */
78
79 int *c_domain_rank; /* List of communicating ranks */
80
81 const fvm_periodicity_t * periodicity; /* Pointer to periodicity
82 structure describing transforms */
83
84 int n_rotations; /* Number of periodic transformations
85 involving rotations */
86
87 cs_lnum_t n_local_elts; /* Number of local elements */
88
89 /* send_halo features : send to distant ranks */
90
91 cs_lnum_t n_send_elts[2]; /* Numer of ghost elements in send_list
92 n_elts[0] = standard elements
93 n_elts[1] = extended + standard elements */
94
95 cs_lnum_t *send_list; /* List of local elements in distant halos
96 (0 to n-1 numbering) */
97
98 cs_lnum_t *send_index; /* Index on send_list
99 Size = 2*n_c_domains + 1. For each rank, we
100 have an index for standard halo and one
101 for extended halo. */
102
103 cs_lnum_t *send_perio_lst; /* For each transformation and for each type of
104 halo on each communicating rank, we store
105 2 values:
106 - start index,
107 - number of elements. */
108
109 cs_lnum_t std_send_block_size; /* Send block size for packing */
110 cs_lnum_t n_std_send_blocks; /* Number of send blocks for packing with
111 standard exchange */
112 cs_lnum_t *std_send_blocks; /* Block start and end info for packing
113 with standard exchange */
114
115 /* halo features : receive from distant ranks */
116
117 cs_lnum_t n_elts[2]; /* Numer of ghost elements in halo
118 n_elts[0] = standard elements
119 n_elts[1] = extended + standard elements */
120
121 cs_lnum_t *index; /* Index on halo sections;
122 Size = 2*n_c_domains + 1. For each rank, we
123 have an index for the standard halo and one
124 for the extended halo. */
125
126 cs_lnum_t *perio_lst; /* For each transformation and for each type of halo
127 on each communicating rank, we store 2 values:
128 - start index,
129 - number of elements. */
130
131 /* Organization of perio_lst:
132
133 -------------------------------------------------
134 T1: | | | | | | | | | | | | |
135 -------------------------------------------------
136 idx n idx n idx n idx n idx n idx n
137 ______ ______ ______ ______ ______ ______
138 std ext std ext std ext
139 ___________ ___________ ___________
140 rank 0 rank 1 rank 2
141
142 -------------------------------------------------
143 T2: | | | | | | | | | | | | |
144 -------------------------------------------------
145 idx n idx n idx n idx n idx n idx n
146 ______ ______ ______ ______ ______ ______
147 std ext std ext std ext
148 ___________ ___________ ___________
149 rank 0 rank 1 rank 2
150
151 -------------------------------------------------
152 T3: | | | | | | | | | | | | |
153 -------------------------------------------------
154 idx n idx n idx n idx n idx n idx n
155 ______ ______ ______ ______ ______ ______
156 std ext std ext std ext
157 ___________ ___________ ___________
158 rank 0 rank 1 rank 2
159
160 etc...
161
162 */
163
164#if defined(HAVE_MPI)
165
166 MPI_Group c_domain_group; /* Group of connected domains */
167 cs_lnum_t *c_domain_s_shift; /* Target buffer shift for distant
168 ranks using one-sided get */
169#endif
170
171} cs_halo_t;
172
175typedef struct _cs_halo_state_t cs_halo_state_t;
176
177/*=============================================================================
178 * Global static variables
179 *============================================================================*/
180
181/*=============================================================================
182 * Public function prototypes
183 *============================================================================*/
184
185/*----------------------------------------------------------------------------*/
193/*----------------------------------------------------------------------------*/
194
195cs_halo_t *
197
198/*----------------------------------------------------------------------------*/
199/*
200 * \brief Ready halo for use.
201 *
202 * This function should be called after building a halo using the
203 * cs_halo_create_function and defined locally.
204 * It is called automatically by cs_halo_create_from_ref and
205 * cs_halo_create_from_rank_neigbors so does not need to be called again
206 * using these functions.
207 *
208 * \param[in] halo pointer to halo structure
209 */
210/*----------------------------------------------------------------------------*/
211
212void
214
215/*----------------------------------------------------------------------------*/
216/*
217 * \brief Create a halo structure, given a reference halo.
218 *
219 * \param[in] ref pointer to reference halo
220 *
221 * \return pointer to created cs_halo_t structure
222 */
223/*----------------------------------------------------------------------------*/
224
225cs_halo_t *
227
228#if defined(HAVE_MPI)
229
230/*----------------------------------------------------------------------------*/
231/*
232 * \brief Create a halo structure from distant element distant ranks and ids.
233 *
234 * \param[in] rn associated rank neighbors info
235 * \param[in] n_local_elts number of elements for local rank
236 * \param[in] n_distant_elts number of distant elements for local rank
237 * \param[in] elt_rank_idx distant element rank index in rank neighbors,
238 * ordered by rank (size: n_distant_elts)
239 * \param[in] elt_id distant element id (at distant rank),
240 * ordered by rank (size: n_distant_elts)
241 * \param[in] elt_tr_id distant element transform id (-1 for
242 * non-periodic elements), null if non-periodic
243 * \param[in] periodicity optional periodicity, or null
244 *
245 * \return pointer to created cs_halo_t structure
246 */
247/*----------------------------------------------------------------------------*/
248
249cs_halo_t *
251(
252 const cs_rank_neighbors_t *rn,
253 cs_lnum_t n_local_elts,
254 cs_lnum_t n_distant_elts,
255 const int elt_rank_idx[],
256 const cs_lnum_t elt_id[],
257 const int16_t elt_tr_id[],
258 const fvm_periodicity_t *periodicity
259);
260
261/*----------------------------------------------------------------------------*/
277/*----------------------------------------------------------------------------*/
278
279cs_halo_t *
281(
282 const cs_rank_neighbors_t *rn,
283 cs_lnum_t n_local_elts,
284 cs_lnum_t n_distant_elts,
285 const int elt_rank_idx[],
286 const cs_lnum_t elt_id[]
287);
288
289#endif /* HAVE_MPI */
290
291/*----------------------------------------------------------------------------*/
297/*----------------------------------------------------------------------------*/
298
299void
301
302/*----------------------------------------------------------------------------*/
308/*----------------------------------------------------------------------------*/
309
312
313/*----------------------------------------------------------------------------*/
320/*----------------------------------------------------------------------------*/
321
322void
324
325/*----------------------------------------------------------------------------*/
331/*----------------------------------------------------------------------------*/
332
335
336/*----------------------------------------------------------------------------*/
346/*----------------------------------------------------------------------------*/
347
348inline size_t
350 cs_datatype_t data_type,
351 int stride)
352{
353 size_t elt_size = cs_datatype_size[data_type]*stride;
354 size_t pack_size = halo->n_send_elts[CS_HALO_EXTENDED] * elt_size;
355
356 return pack_size;
357}
358
359/*----------------------------------------------------------------------------
360 * Apply local cells renumbering to a halo
361 *
362 * parameters:
363 * halo <-- pointer to halo structure
364 * new_cell_id <-- array indicating old -> new cell id (0 to n-1)
365 *---------------------------------------------------------------------------*/
366
367void
369 const cs_lnum_t new_cell_id[]);
370
371/*----------------------------------------------------------------------------
372 * Apply ghost cells renumbering to a halo
373 *
374 * parameters:
375 * halo <-- pointer to halo structure
376 * old_cell_id <-- array indicating new -> old cell id (0 to n-1)
377 *---------------------------------------------------------------------------*/
378
379void
381 const cs_lnum_t old_cell_id[]);
382
383/*----------------------------------------------------------------------------*/
406/*----------------------------------------------------------------------------*/
407
408void *
410 cs_halo_type_t sync_mode,
411 cs_datatype_t data_type,
412 int stride,
413 void *send_buf,
414 cs_halo_state_t *hs);
415
416/*----------------------------------------------------------------------------*/
435/*----------------------------------------------------------------------------*/
436
437void
438cs_halo_sync_pack(const cs_halo_t *halo,
439 cs_halo_type_t sync_mode,
440 cs_datatype_t data_type,
441 int stride,
442 void *val,
443 void *send_buf,
444 cs_halo_state_t *hs);
445
446#if defined(HAVE_ACCEL)
447
448/*----------------------------------------------------------------------------*/
468/*----------------------------------------------------------------------------*/
469
470void
471cs_halo_sync_pack_d(const cs_halo_t *halo,
472 cs_halo_type_t sync_mode,
473 cs_datatype_t data_type,
474 int stride,
475 void *val,
476 void *send_buf,
477 cs_halo_state_t *hs);
478
479#endif /* defined(HAVE_ACCEL) */
480
481/*----------------------------------------------------------------------------*/
496/*----------------------------------------------------------------------------*/
497
498void
499cs_halo_sync_start(const cs_halo_t *halo,
500 void *val,
501 cs_halo_state_t *hs);
502
503/*----------------------------------------------------------------------------*/
519/*----------------------------------------------------------------------------*/
520
521void
522cs_halo_sync_wait(const cs_halo_t *halo,
523 void *val,
524 cs_halo_state_t *hs);
525
526/*----------------------------------------------------------------------------*/
540/*----------------------------------------------------------------------------*/
541
542void
543cs_halo_sync(const cs_halo_t *halo,
544 cs_halo_type_t sync_mode,
545 cs_datatype_t data_type,
546 int stride,
547 void *val);
548
549#if defined(HAVE_ACCEL)
550
551/*----------------------------------------------------------------------------*/
566/*----------------------------------------------------------------------------*/
567
568void
569cs_halo_sync_d(const cs_halo_t *halo,
570 cs_halo_type_t sync_mode,
571 cs_datatype_t data_type,
572 int stride,
573 void *val);
574
575#endif /* defined(HAVE_ACCEL) */
576
577/*----------------------------------------------------------------------------
578 * Update array of any type of halo values in case of parallelism or
579 * periodicity.
580 *
581 * Data is untyped; only its size is given, so this function may also
582 * be used to synchronize interleaved multidimendsional data, using
583 * size = element_size*dim (assuming a homogeneous environment, at least
584 * as far as data encoding goes).
585 *
586 * This function aims at copying main values from local elements
587 * (id between 1 and n_local_elements) to ghost elements on distant ranks
588 * (id between n_local_elements + 1 to n_local_elements_with_halo).
589 *
590 * parameters:
591 * halo <-- pointer to halo structure
592 * sync_mode <-- synchronization mode (standard or extended)
593 * size <-- size of each element
594 * num <-> pointer to local number value array
595 *----------------------------------------------------------------------------*/
596
597void
599 cs_halo_type_t sync_mode,
600 size_t size,
601 void *val);
602
603/*----------------------------------------------------------------------------
604 * Update array of integer halo values in case of parallelism or periodicity.
605 *
606 * This function aims at copying main values from local elements
607 * (id between 1 and n_local_elements) to ghost elements on distant ranks
608 * (id between n_local_elements + 1 to n_local_elements_with_halo).
609 *
610 * parameters:
611 * halo <-- pointer to halo structure
612 * sync_mode <-- synchronization mode (standard or extended)
613 * num <-> pointer to local number value array
614 *----------------------------------------------------------------------------*/
615
616void
617cs_halo_sync_num(const cs_halo_t *halo,
618 cs_halo_type_t sync_mode,
619 cs_lnum_t num[]);
620
621/*----------------------------------------------------------------------------
622 * Update array of variable (floating-point) halo values in case of
623 * parallelism or periodicity.
624 *
625 * This function aims at copying main values from local elements
626 * (id between 1 and n_local_elements) to ghost elements on distant ranks
627 * (id between n_local_elements + 1 to n_local_elements_with_halo).
628 *
629 * parameters:
630 * halo <-- pointer to halo structure
631 * sync_mode <-- synchronization mode (standard or extended)
632 * var <-> pointer to variable value array
633 *----------------------------------------------------------------------------*/
634
635void
636cs_halo_sync_var(const cs_halo_t *halo,
637 cs_halo_type_t sync_mode,
638 cs_real_t var[]);
639
640/*----------------------------------------------------------------------------
641 * Update array of strided variable (floating-point) halo values in case
642 * of parallelism or periodicity.
643 *
644 * This function aims at copying main values from local elements
645 * (id between 1 and n_local_elements) to ghost elements on distant ranks
646 * (id between n_local_elements + 1 to n_local_elements_with_halo).
647 *
648 * parameters:
649 * halo <-- pointer to halo structure
650 * sync_mode <-- synchronization mode (standard or extended)
651 * var <-> pointer to variable value array
652 * stride <-- number of (interlaced) values by entity
653 *----------------------------------------------------------------------------*/
654
655void
657 cs_halo_type_t sync_mode,
658 cs_real_t var[],
659 int stride);
660
661/*----------------------------------------------------------------------------
662 * Return MPI_Barrier usage flag.
663 *
664 * returns:
665 * true if MPI barriers are used after posting receives and before posting
666 * sends, false otherwise
667 *---------------------------------------------------------------------------*/
668
669bool
671
672/*----------------------------------------------------------------------------
673 * Set MPI_Barrier usage flag.
674 *
675 * parameters:
676 * use_barrier <-- true if MPI barriers should be used after posting
677 * receives and before posting sends, false otherwise.
678 *---------------------------------------------------------------------------*/
679
680void
681cs_halo_set_use_barrier(bool use_barrier);
682
683/*----------------------------------------------------------------------------*/
689/*----------------------------------------------------------------------------*/
690
693
694/*----------------------------------------------------------------------------*/
700/*----------------------------------------------------------------------------*/
701
702void
704
705/*----------------------------------------------------------------------------*/
711/*----------------------------------------------------------------------------*/
712
715
716/*----------------------------------------------------------------------------*/
722/*----------------------------------------------------------------------------*/
723
724void
726
727/*----------------------------------------------------------------------------*/
728/*
729 * \brief Return pointer to working send buffer used by default halo state.
730 *
731 * This allows sharing the allocation with other operations which might be
732 * used frequently, such as range set scatters (which play a similar role to
733 * halos for data which can be on process boundaries, such as vertex or
734 * face-based data).
735 *
736 * If the current buffer's size is smaller than the requested size, it is
737 * increased.
738 *
739 * \warning The returned buffer should not be used while a halo exchange
740 * using the default halo state is in progress.
741 *
742 * \return] halo pointer to pointer to cs_halo structure to destroy.
743 */
744/*----------------------------------------------------------------------------*/
745
746void *
747cs_halo_get_default_buffer(size_t size);
748
749/*----------------------------------------------------------------------------
750 * Dump a cs_halo_t structure.
751 *
752 * parameters:
753 * halo <-- pointer to cs_halo_t struture
754 * print_level <-- 0 only dimensions and indexes are printed, else (1)
755 * everything is printed
756 *---------------------------------------------------------------------------*/
757
758void
759cs_halo_dump(const cs_halo_t *halo,
760 int print_level);
761
762/*=============================================================================
763 * Public C++ functions
764 *============================================================================*/
765
766/*----------------------------------------------------------------------------*/
767/*
768 * \brief Update array of values in case of parallelism or periodicity.
769 *
770 * This function aims at copying main values from local elements
771 * (id between 1 and n_local_elements) to ghost elements on distant ranks
772 * (id between n_local_elements + 1 to n_local_elements_with_halo).
773 *
774 * \tparam[in] Stride number of (interlaced) values by entity
775 * \tparam[in] T value type
776 *
777 * \param[in] halo pointer to halo structure
778 * \param[in] sync_mode synchronization mode (standard or extended)
779 * \param[in] on_device run on accelerated device if possible
780 * \param[in, out] val pointer to variable value array
781 */
782/*----------------------------------------------------------------------------*/
783
784template <typename T>
785void
786cs_halo_sync(const cs_halo_t *halo,
787 cs_halo_type_t sync_mode,
788 bool on_device,
789 T val[]);
790
791template <int Stride, typename T>
792void
793cs_halo_sync(const cs_halo_t *halo,
794 cs_halo_type_t sync_mode,
795 bool on_device,
796 T val[][Stride]);
797
798/*----------------------------------------------------------------------------*/
799/*
800 * \brief Update array of values in case of parallelism or periodicity,
801 * using the standard neighborhood.
802 *
803 * This function aims at copying main values from local elements
804 * (id between 1 and n_local_elements) to ghost elements on distant ranks
805 * (id between n_local_elements + 1 to n_local_elements_with_halo).
806 *
807 * \tparam[in] Stride number of (interlaced) values by entity
808 * \tparam[in] T value type
809 *
810 * \param[in] halo pointer to halo structure
811 * \param[in] on_device run on accelerated device if possible
812 * \param[in, out] val pointer to variable value array
813 */
814/*----------------------------------------------------------------------------*/
815
816template <typename T>
817void
818cs_halo_sync(const cs_halo_t *halo,
819 bool on_device,
820 T val[]);
821
822template <int Stride, typename T>
823void
824cs_halo_sync(const cs_halo_t *halo,
825 bool on_device,
826 T val[][Stride]);
827
828/*--------------------------------------------------------------------------*/
836/*--------------------------------------------------------------------------*/
837
838template<typename T, int N>
839void
841(
842 const cs_halo_t *halo,
843 cs_halo_type_t sync_mode,
844 [[maybe_unused]] bool on_device,
846)
847{
848 static_assert(N == 1 || N == 2,
849 "Only possible for arrays of dim 1 or 2.");
850
851 if (halo == nullptr)
852 return;
853
854 cs_datatype_t datatype = cs_datatype_from_type<T>();
855
856 T *val = span.data();
857
858 int Stride = (N == 1) ? 1 : span.extent(1);
859
860#if defined(HAVE_ACCEL)
861 if (on_device)
862 cs_halo_sync_pack_d(halo,
863 sync_mode,
864 datatype,
865 Stride,
866 val,
867 nullptr,
868 nullptr);
869 else
870#endif
872 sync_mode,
873 datatype,
874 Stride,
875 val,
876 nullptr,
877 nullptr);
878
879 cs_halo_sync_start(halo, val, nullptr);
880
881 cs_halo_sync_wait(halo, val, nullptr);
882}
883
884/*--------------------------------------------------------------------------*/
893/*--------------------------------------------------------------------------*/
894
895template<typename T, int N>
896void
898(
899 const cs_halo_t *halo,
900 [[maybe_unused]] bool on_device,
901 cs_mdspan_r<T, N>& span
902)
903{
904 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, span);
905}
906
907/*--------------------------------------------------------------------------*/
917/*--------------------------------------------------------------------------*/
918
919template<typename T, int N>
920void
922(
923 const cs_halo_t *halo,
924 cs_halo_type_t sync_mode,
925 cs_mdspan_r<T, N>& span
926)
927{
928 bool on_device = cs_mem_is_device_ptr(span.data());
929 cs_halo_sync<T, N>(halo, sync_mode, on_device, span);
930}
931
932/*--------------------------------------------------------------------------*/
943/*--------------------------------------------------------------------------*/
944
945template<typename T, int N>
946void
948(
949 const cs_halo_t *halo,
950 cs_mdspan_r<T, N>& span
951)
952{
953 bool on_device = cs_mem_is_device_ptr(span.data());
954 cs_halo_sync<T, N>(halo, CS_HALO_STANDARD, on_device, span);
955}
956
957/*----------------------------------------------------------------------------*/
958/*
959 * \brief Update ghost cell values of a spatial vector field,
960 * including rotational periodicity if present.
961 *
962 * This function aims at copying main values from local elements
963 * (id between 1 and n_local_elements) to ghost elements on distant ranks
964 * (id between n_local_elements + 1 to n_local_elements_with_halo).
965 *
966 * \tparam[in] T value type
967 *
968 * \param[in] halo pointer to halo structure
969 * \param[in] sync_mode synchronization mode (standard or extended)
970 * \param[in] on_device run on accelerated device if possible
971 * \param[in, out] val pointer to variable value array
972 */
973/*----------------------------------------------------------------------------*/
974
975template <typename T>
976void
977cs_halo_sync_r(const cs_halo_t *halo,
978 cs_halo_type_t sync_mode,
979 bool on_device,
980 T val[][3]);
981
982/*----------------------------------------------------------------------------*/
983/*
984 * \brief Update ghost cell values of a spatial vector field,
985 * including rotational periodicity if present,
986 * using the standard neighborhood.
987 *
988 * This function aims at copying main values from local elements
989 * (id between 1 and n_local_elements) to ghost elements on distant ranks
990 * (id between n_local_elements + 1 to n_local_elements_with_halo).
991 *
992 * \tparam[in] T value type
993 *
994 * \param[in] halo pointer to halo structure
995 * \param[in] on_device run on accelerated device if possible
996 * \param[in, out] val pointer to variable value array
997 */
998/*----------------------------------------------------------------------------*/
999
1000template <typename T>
1001void
1002cs_halo_sync_r(const cs_halo_t *halo,
1003 bool on_device,
1004 T val[][3]);
1005
1006/*----------------------------------------------------------------------------*/
1007/*
1008 * \brief Update ghost cell values of a symmetric tensor field,
1009 * including rotational periodicity if present.
1010 *
1011 * This function aims at copying main values from local elements
1012 * (id between 1 and n_local_elements) to ghost elements on distant ranks
1013 * (id between n_local_elements + 1 to n_local_elements_with_halo).
1014 *
1015 * \tparam[in] T value type
1016 *
1017 * \param[in] halo pointer to halo structure
1018 * \param[in] sync_mode synchronization mode (standard or extended)
1019 * \param[in] on_device run on accelerated device if possible
1020 * \param[in, out] val pointer to variable value array
1021 */
1022/*----------------------------------------------------------------------------*/
1023
1024template <typename T>
1025void
1026cs_halo_sync_r(const cs_halo_t *halo,
1027 cs_halo_type_t sync_mode,
1028 bool on_device,
1029 T val[][6]);
1030
1031/*----------------------------------------------------------------------------*/
1032/*
1033 * \brief Update ghost cell values of a symmetric tensor field,
1034 * including rotational periodicity if present,
1035 * using the standard neighborhood.
1036 *
1037 * This function aims at copying main values from local elements
1038 * (id between 1 and n_local_elements) to ghost elements on distant ranks
1039 * (id between n_local_elements + 1 to n_local_elements_with_halo).
1040 *
1041 * \tparam[in] T value type
1042 *
1043 * \param[in] halo pointer to halo structure
1044 * \param[in] sync_mode synchronization mode (standard or extended)
1045 * \param[in] on_device run on accelerated device if possible
1046 * \param[in, out] val pointer to variable value array
1047 */
1048/*----------------------------------------------------------------------------*/
1049
1050template <typename T>
1051void
1052cs_halo_sync_r(const cs_halo_t *halo,
1053 bool on_device,
1054 T val[][6]);
1055
1056/*----------------------------------------------------------------------------*/
1072/*----------------------------------------------------------------------------*/
1073
1074template <typename T>
1075void
1076cs_halo_sync_r(const cs_halo_t *halo,
1077 cs_halo_type_t sync_mode,
1078 bool on_device,
1079 T val[][3][3]);
1080
1081/*--------------------------------------------------------------------------*/
1091/*--------------------------------------------------------------------------*/
1092
1093template<typename T, int N>
1094void
1096(
1097 const cs_halo_t *halo,
1098 cs_halo_type_t sync_mode,
1099 [[maybe_unused]] bool on_device,
1100 cs_mdspan_r<T, N> span
1101)
1102{
1103 static_assert(N == 1 || N == 2,
1104 "Only possible for arrays of dim 1 or 2.");
1105
1106 int stride = (N == 1) ? 1 : span.extent(1);
1107
1108 if (stride == 3) {
1109 using t3_t = T[3];
1110 t3_t *val_v = (t3_t *)span.data();
1111 cs_halo_sync_r(halo, sync_mode, on_device, val_v);
1112 }
1113 else if (stride == 6) {
1114 using t6_t = T[6];
1115 t6_t *val_t = (t6_t *)span.data();
1116 cs_halo_sync_r(halo, sync_mode, on_device, val_t);
1117 }
1118 else
1119 cs_halo_sync(halo, sync_mode, on_device, span);
1120}
1121
1122/*--------------------------------------------------------------------------*/
1134/*--------------------------------------------------------------------------*/
1135
1136template<typename T, int N>
1137void
1139(
1140 const cs_halo_t *halo,
1141 cs_halo_type_t sync_mode,
1142 cs_mdspan_r<T, N> span
1143)
1144{
1145 static_assert(N == 1 || N == 2,
1146 "Only possible for arrays of dim 1 or 2.");
1147
1148 bool on_device = cs_mem_is_device_ptr(span.data());
1149 int stride = (N == 1) ? 1 : span.extent(1);
1150
1151 if (stride == 3) {
1152 using t3_t = T[3];
1153 t3_t *val_v = (t3_t *)span.data();
1154 cs_halo_sync_r(halo, sync_mode, on_device, val_v);
1155 }
1156 else if (stride == 6) {
1157 using t6_t = T[6];
1158 t6_t *val_t = (t6_t *)span.data();
1159 cs_halo_sync_r(halo, sync_mode, on_device, val_t);
1160 }
1161 else
1162 cs_halo_sync(halo, sync_mode, on_device, span);
1163}
1164
1165/*----------------------------------------------------------------------------*/
1166
1167#endif /* CS_HALO_H */
Define a templated mdspan class (non owner of data)
Definition: cs_mdspan.h:68
CS_F_HOST_DEVICE T * data() const
Getter for data raw pointer.
Definition: cs_mdspan.h:561
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:525
const size_t cs_datatype_size[]
Definition: cs_defs.cpp:129
cs_datatype_t
Definition: cs_defs.h:290
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
bool cs_halo_get_use_barrier(void)
Definition: cs_halo.cpp:2412
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:1739
cs_halo_state_t * cs_halo_state_create(void)
Create a halo state structure.
Definition: cs_halo.cpp:1353
cs_halo_comm_mode_t
Definition: cs_halo.h:63
@ CS_HALO_COMM_P2P
Definition: cs_halo.h:65
@ CS_HALO_COMM_RMA_GET
Definition: cs_halo.h:66
void cs_halo_state_destroy(cs_halo_state_t **halo_state)
Destroy a halo state structure.
Definition: cs_halo.cpp:1406
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:1957
cs_halo_comm_mode_t cs_halo_get_comm_mode(void)
Get default communication mode for halo exchange.
Definition: cs_halo.cpp:2440
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:2240
void * cs_halo_get_default_buffer(size_t size)
Return pointer to working send buffer used by default halo state.
Definition: cs_halo.cpp:2508
void cs_halo_set_comm_mode(cs_halo_comm_mode_t mode)
Set default communication mode for halo exchange.
Definition: cs_halo.cpp:2454
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:2469
void cs_halo_renumber_cells(cs_halo_t *halo, const cs_lnum_t new_cell_id[])
Definition: cs_halo.cpp:1455
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:864
void cs_halo_dump(const cs_halo_t *halo, int print_level)
Definition: cs_halo.cpp:2535
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:349
cs_halo_t * cs_halo_create(const cs_interface_set_t *ifs)
Create a halo structure given an interface set.
Definition: cs_halo.cpp:608
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:2130
void cs_halo_set_use_barrier(bool use_barrier)
Definition: cs_halo.cpp:2426
cs_halo_type_t
Definition: cs_halo.h:53
@ CS_HALO_N_TYPES
Definition: cs_halo.h:57
@ CS_HALO_STANDARD
Definition: cs_halo.h:55
@ CS_HALO_EXTENDED
Definition: cs_halo.h:56
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:1641
void cs_halo_create_complete(cs_halo_t *halo)
Ready halo for use.
Definition: cs_halo.cpp:753
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:2328
cs_halo_state_t * cs_halo_state_get_default(void)
Get pointer to default halo state structure.
Definition: cs_halo.cpp:1441
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:2483
void cs_halo_sync_var(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_real_t var[])
Definition: cs_halo.cpp:2372
void cs_halo_sync_num(const cs_halo_t *halo, cs_halo_type_t sync_mode, cs_lnum_t num[])
Definition: cs_halo.cpp:2350
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:2880
void cs_halo_renumber_ghost_cells(cs_halo_t *halo, const cs_lnum_t old_cell_id[])
Definition: cs_halo.cpp:1479
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:2395
cs_halo_t * cs_halo_create_from_rank_neighbors(const cs_rank_neighbors_t *rn, cs_lnum_t n_local_elts, cs_lnum_t n_distant_elts, const int elt_rank_idx[], const cs_lnum_t elt_id[], const int16_t elt_tr_id[], const fvm_periodicity_t *periodicity)
Create a halo structure from distant element distant ranks and ids.
Definition: cs_halo.cpp:954
void cs_halo_destroy(cs_halo_t **halo)
Definition: cs_halo.cpp:1306
struct _cs_halo_state_t cs_halo_state_t
Definition: cs_halo.h:175
struct _cs_interface_set_t cs_interface_set_t
Definition: cs_interface.h:57
bool cs_mem_is_device_ptr(const void *ptr)
Check if a pointer is a device (or shared) pointer.
Definition: cs_mem.h:753
cs_alloc_mode_t
Definition: cs_mem.h:46
struct _fvm_periodicity_t fvm_periodicity_t
Definition: fvm_periodicity.h:63
Definition: cs_halo.h:74
int n_transforms
Definition: cs_halo.h:77
cs_lnum_t * index
Definition: cs_halo.h:121
cs_lnum_t * send_list
Definition: cs_halo.h:95
cs_lnum_t * send_index
Definition: cs_halo.h:98
int n_rotations
Definition: cs_halo.h:84
cs_lnum_t * std_send_blocks
Definition: cs_halo.h:112
cs_lnum_t n_local_elts
Definition: cs_halo.h:87
cs_lnum_t n_std_send_blocks
Definition: cs_halo.h:110
int n_c_domains
Definition: cs_halo.h:76
int * c_domain_rank
Definition: cs_halo.h:79
cs_lnum_t * perio_lst
Definition: cs_halo.h:126
cs_lnum_t std_send_block_size
Definition: cs_halo.h:109
cs_lnum_t * send_perio_lst
Definition: cs_halo.h:103
const fvm_periodicity_t * periodicity
Definition: cs_halo.h:81
MPI_Group c_domain_group
Definition: cs_halo.h:166
cs_lnum_t * c_domain_s_shift
Definition: cs_halo.h:167
cs_lnum_t n_send_elts[2]
Definition: cs_halo.h:91
Definition: cs_rank_neighbors.h:63