TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Check_espace_virtuel.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <Check_espace_virtuel.h>
17#include <MD_Vector_base.h>
18
19/*! @brief Verifie si le vecteur v a son espace virtuel a jour.
20 *
21 * Cette fonction doit etre appelee simultanement par tous les processeurs qui partagent le vecteur. (pour cela, on cree une copie qu'on echange, puis on compare a l'original).
22 *
23 */
24int check_espace_virtuel_vect(const DoubleVect& v)
25{
26 if (Process::is_sequential()) return 1; // ToDo Provisoire on ne verifie pas en sequentiel
27 // On fait une copie:
28 DoubleVect w(v);
29 // On echange
30 w.echange_espace_virtuel();
31 // Norme de w :
32 const double norme_w = norme_array(w);
33 // On compare : difference entre les deux vecteurs au sens
34 // ArrOfDouble (pas d'echange espace virtuel)
35 w.ArrOfDouble::operator-=(v);
36 const double ecart = norme_array(w);
37 if (ecart > (norme_w + 1e-30) * 1e-12)
38 return 0;
39 else
40 return 1;
41}
42
43/*! @brief Idem que check_espace_virtuel_vect(const DoubleVect & v)
44 *
45 */
46int check_espace_virtuel_vect(const IntVect& v)
47{
48 // On fait une copie:
49 IntVect w(v);
50 // On echange
51 w.echange_espace_virtuel();
52 // On compare:
53 const int n = v.size_array();
54 for (int i = 0; i < n; i++)
55 if (v[i] != w[i])
56 return 0;
57 return 1;
58}
59
60/*! @brief Appelle remplir_items_non_calcules() si on est en mode comm_check_enabled() ou en mode debug (NDEBUG non defini)
61 *
62 * La "valeur" par defaut est censee provoquer une erreur si on
63 * essaye de l'utiliser.
64 *
65 */
66void assert_invalide_items_non_calcules(DoubleVect& v, double valeur)
67{
68#ifdef NDEBUG
70 remplir_items_non_calcules(v, valeur);
71#else
72 remplir_items_non_calcules(v, valeur);
73#endif
74}
75
76#ifndef LATATOOLS
77namespace
78{
79template <typename ExecSpace, typename _TYPE_>
80void remplir_items_non_calcules_kernel_(TRUSTVect<_TYPE_>& v, _TYPE_ valeur, const ArrOfInt& blocs, const int sz, const int line_size)
81{
82 auto v_view= v.template view_wo<1, ExecSpace>();
83
84 int j = 0;
85
86 for (int i = 0; i <= sz; i++)
87 {
88
89 // Fill the elemns until the beginning of the bloc
90 // If i ==sz, fill the elems between the end of the last block and the end of the vect
91 // (<=sz instead of <sz + extra loop: small) Hack from Remi B to avoid re-writing the loop two times
92
93 const int j_fin = i==sz ? v.size_array() : blocs[i*2] * line_size;
94 assert(j >= 0 && j_fin <= v.size_array());
95
96 Kokkos::RangePolicy<ExecSpace> policy(j, j_fin);
97 Kokkos::parallel_for(start_gpu_timer(__KERNEL_NAME__),policy,
98 KOKKOS_LAMBDA(const int k) {v_view[k]=valeur;});
99
100 end_gpu_timer(__KERNEL_NAME__, is_default_exec_space<ExecSpace>);
101
102 // Sauter a la fin du bloc
103 if (i<sz) j = blocs[i*2+1] * line_size;
104 }
105}
106}
107#endif
108
109template <typename _TYPE_>
110void remplir_items_non_calcules_(TRUSTVect<_TYPE_>& v, _TYPE_ valeur)
111{
112#ifndef LATATOOLS
113 if (v.get_md_vector() && Process::is_parallel()) // Checking virtual items in sequential is meaningless
114 {
115 const ArrOfInt& blocs = v.get_md_vector()->get_blocs_items_to_compute();
116 const int sz = blocs.size_array() / 2, line_size = v.line_size();
117
118 bool kernelOnDevice = v.checkDataOnDevice();
119
120 if (kernelOnDevice)
121 remplir_items_non_calcules_kernel_<Kokkos::DefaultExecutionSpace, _TYPE_>(v, valeur, blocs, sz, line_size);
122 else
123 remplir_items_non_calcules_kernel_<Kokkos::DefaultHostExecutionSpace, _TYPE_>(v, valeur, blocs, sz, line_size);
124 }
125#else
126 return
127#endif
128}
129
130// Explicit instanciation
131template void remplir_items_non_calcules_<double>(TRUSTVect<double>& v, double valeur);
132template void remplir_items_non_calcules_<int>(TRUSTVect<int>& v, int valeur);
133template void remplir_items_non_calcules_<float>(TRUSTVect<float>& v, float valeur);
static int check_enabled()
Definition Comm_Group.h:159
virtual const ArrOfInt & get_blocs_items_to_compute() const =0
static bool is_parallel()
Definition Process.cpp:110
static bool is_sequential()
Definition Process.cpp:115
_SIZE_ size_array() const
int line_size() const
Definition TRUSTVect.tpp:67
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123