TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTTab_tools.tpp
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#ifndef TRUSTTab_tools_TPP_included
17#define TRUSTTab_tools_TPP_included
18
19#include <limits>
20#include <Process.h>
21
22// NB: all those methods are never used on big (64b) arrays, so the size type is always 'int'.
23
24template <typename _T_>
25void local_carre_norme_tab(const TRUSTTab<_T_,int>& tableau, TRUSTArray<_T_,int>& norme_colonne);
26
27template <>
28inline void local_carre_norme_tab(const TRUSTTab<int,int>& , TRUSTArray<int,int>& ) = delete;
29
30
31template <typename _T_>
32inline void mp_carre_norme_tab(const TRUSTTab<_T_,int>& tableau, TRUSTArray<_T_,int>& norme_colonne)
33{
34 local_carre_norme_tab(tableau, norme_colonne);
35 Process::mp_sum_for_each_item(norme_colonne);
36}
37
38template <>
39inline void mp_carre_norme_tab(const TRUSTTab<int,int>& , TRUSTArray<int,int>& ) = delete;
40
41
42template <typename _T_>
43inline void mp_norme_tab(const TRUSTTab<_T_,int>& tableau, TRUSTArray<_T_,int>& norme_colonne)
44{
45 mp_carre_norme_tab(tableau,norme_colonne);
46 for (int c=0; c<norme_colonne.size_array(); c++) norme_colonne[c] = sqrt(norme_colonne[c]);
47}
48
49template <>
50inline void mp_norme_tab(const TRUSTTab<int,int>& , TRUSTArray<int,int>& ) = delete;
51
52
53template <typename _T_>
54void local_max_abs_tab(const TRUSTTab<_T_,int>& tableau, TRUSTArray<_T_,int>& max_colonne);
55
56template <>
57inline void local_max_abs_tab(const TRUSTTab<int,int>& , TRUSTArray<int,int>& ) = delete;
58
59
60template <typename _T_>
61inline void mp_max_abs_tab(const TRUSTTab<_T_,int>& tableau, TRUSTArray<_T_,int>& max_colonne)
62{
63 local_max_abs_tab(tableau, max_colonne);
65}
66
67#ifndef LATATOOLS
68/**
69 * @brief Compares two `TRUSTTab<double, _SZ_>` objects for equality.
70 *
71 * Performs an element-wise comparison of the two arrays, using Kokkos for GPU data
72 * and a sequential approach for host data. Returns `true` if all elements match, `false` otherwise.
73 *
74 * @tparam _SZ_ The size type of the `TRUSTTab` object.
75 * @param a First array to compare.
76 * @param b Second array to compare.
77 * @return `true` if the arrays are equal, `false` otherwise.
78 */
79template <typename _SIZE_>
80bool sameDoubleTab(const TRUSTTab<double, _SIZE_>& a, const TRUSTTab<double, _SIZE_>& b)
81{
82 _SIZE_ size_a = a.size_array();
83 _SIZE_ size_b = b.size_array();
84 if (size_a != size_b)
85 return false;
86 bool kernelOnDevice = a.checkDataOnDevice() && b.checkDataOnDevice();
87 if (kernelOnDevice)
88 {
89 auto a_v = static_cast<const ArrOfDouble&>(a).view_ro();
90 auto b_v = static_cast<const ArrOfDouble&>(b).view_ro();
91 bool same = true;
92 Kokkos::parallel_reduce(start_gpu_timer(), size_a, KOKKOS_LAMBDA(const int i, bool& local_same)
93 {
94 if (a_v(i) != b_v(i)) local_same = false;
95 }, Kokkos::LAnd<bool>(same));
96 end_gpu_timer(__KERNEL_NAME__);
97 return same;
98 }
99 else
100 {
101 for (_SIZE_ i = 0; i < size_a; i++)
102 if (a.addr()[i] != b.addr()[i])
103 return false;
104 return true;
105 }
106}
107#endif
108
109template <>
110inline void mp_max_abs_tab(const TRUSTTab<int,int>& , TRUSTArray<int,int>& ) = delete;
111
112#endif /* TRUSTTab_tools_TPP_included */
static void mp_max_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:196
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:193
Represents a an array of int/int64/double/... values.
Definition TRUSTArray.h:81
_SIZE_ size_array() const
_TYPE_ * addr()
: Tableau a n entrees pour n<= 4.
Definition TRUSTTab.h:31