TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
TRUSTVect.h
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 TRUSTVect_included
17#define TRUSTVect_included
18
19#include <type_traits>
20#include <MD_Vector_tools.h>
21#include <MD_Vector_base.h>
22#include <TRUSTArray.h>
23#include <limits.h>
24#include <math.h>
25
26#include <MD_Vector.h>
27#ifndef LATATOOLS // Lata tools does not use parallelism
28#include <DescStructure.h>
29#include <communications.h>
30#endif
31
32template<typename _TYPE_, typename _SIZE_>
33class TRUSTVect : public TRUSTArray<_TYPE_,_SIZE_>
34{
35protected:
36 inline unsigned taille_memoire() const override { throw; }
37
38 inline int duplique() const override
39 {
40 TRUSTVect* xxx = new TRUSTVect(*this);
41 if(!xxx) Process::exit("Not enough memory ");
42 return xxx->numero();
43 }
44
45 Sortie& printOn(Sortie& os) const override
46 {
47#ifndef LATATOOLS
49 Process::exit("Error in TRUSTVect::printOn: try to print a parallel vector");
51#endif
52 return os;
53 }
54
55 /*! @brief Reads a sequential vector (like an ArrOfDouble). Invalid call if the vector has a non-null MD_Vector.
56 *
57 * (For parallel vectors, use a save/restore method instead)
58 *
59 */
60 Entree& readOn(Entree& is) override
61 {
62#ifndef LATATOOLS
63 // Reading into a vector that already has a parallel structure is not allowed:
64 if (md_vector_)
65 Process::exit("Error in TRUSTVect::readOn: vector has a parallel structure");
68 line_size_ = 1;
69#endif
70 return is;
71 }
72
73public:
74
75 using Span_ = tcb::span<_TYPE_>;
76
77 // One instanciation with given template parameter may see all other template versions (useful in ref_as_xxx())
78 template<typename _TYPE2_, typename _SIZE2_> friend class TRUSTVect;
79
80 virtual ~TRUSTVect() { }
81
83
84 /*! @brief Constructs a vector of size n.
85 *
86 * Elements are initialized to zero by default. To skip initialization, use: DoubleVect toto;
87 * toto.resize(n, RESIZE_OPTIONS::NOCOPY_NOINIT);
88 *
89 */
90 TRUSTVect(_SIZE_ n) : TRUSTArray<_TYPE_,_SIZE_>(n), size_reelle_(n), line_size_(1) { }
91
92 /*! @brief Copy constructor.
93 *
94 * This is a deep copy; see ArrOfDouble::ArrOfDouble(const ArrOfDouble &). Note: there is no copy constructor from ArrOfDouble on purpose,
95 * to avoid large performance losses from implicit object creation that are hard to track down.
96 * (Example: calling toto(const IntVect &) with an ArrOfInt would silently copy the array!)
97 * Use copy() to copy an ArrOfDouble into a DoubleVect.
98 *
99 */
101
103 inline TRUSTVect& operator=(_TYPE_);
104 inline _SIZE_ size() const;
105 inline _SIZE_ size_totale() const;
106 inline _SIZE_ size_reelle() const;
107 inline _SIZE_ size_reelle_ok() const;
108 inline int line_size() const; // Even in 64b we suppose line_size_ is always sufficiently small to fit in an int.
109 inline void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT);
110 inline void copy(const TRUSTArray<_TYPE_,_SIZE_>&, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT);
111 inline void copy(const TRUSTVect&, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT);
112 inline void operator+=(const TRUSTVect& v) { operator_add(*this, v); }
113 inline void operator+=(const _TYPE_ x) { operator_add(*this, x); }
114 inline void operator-=(const TRUSTVect& v) { operator_sub(*this, v); }
115 inline void operator-=(const _TYPE_ x) { operator_sub(*this, x); }
116 inline void operator*=(const TRUSTVect& v) { operator_multiply(*this, v); }
117 inline void operator*= (const _TYPE_ x) { operator_multiply(*this, x); }
118
119 template<typename _T_ /* double ou float */>
120 inline void operator/=(const TRUSTVect<_T_, _SIZE_>& v) { operator_divide(*this, v); }
121 inline void operator/= (const _TYPE_ x) { operator_divide(*this, x); }
122
123 inline virtual const MD_Vector& get_md_vector() const { return md_vector_; }
124 inline void resize_tab(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) override;
125
126 // See same methods as in TRUSTArray - CAREFUL, this is not an override because arg types are different (vect vs arr)
127 inline void from_tid_to_int(TRUSTVect<int, int>& out) const;
129 inline void ref_as_small(TRUSTVect<_TYPE_, int>& out) const;
130
131 // Default options chosen for compatibility with the previous version. Note: there was an echange_espace_virtuel call before, which is not strictly equivalent.
132 inline void abs(Mp_vect_options opt=VECT_ALL_ITEMS) { operator_abs(*this, opt); }
133 inline void carre(Mp_vect_options opt=VECT_ALL_ITEMS) { carre_(*this, opt); }
134 inline void racine_carree(Mp_vect_options opt=VECT_ALL_ITEMS) { racine_carree_(*this, opt); }
135
136 template<typename _SCALAR_TYPE_>
137 inline void ajoute(_SCALAR_TYPE_ alpha, const TRUSTVect& y, Mp_vect_options opt=VECT_ALL_ITEMS);
138
139 template<typename _SCALAR_TYPE_>
140 inline void ajoute_sans_ech_esp_virt(_SCALAR_TYPE_ alpha, const TRUSTVect& y, Mp_vect_options opt=VECT_REAL_ITEMS);
141
142 template<typename _SCALAR_TYPE_>
143 inline void ajoute_produit_scalaire(_SCALAR_TYPE_ alpha, const TRUSTVect& x, const TRUSTVect& y, Mp_vect_options opt=VECT_ALL_ITEMS);
144
145 template<typename _SCALAR_TYPE_>
146 inline void ajoute_carre(_SCALAR_TYPE_ alpha, const TRUSTVect& y, Mp_vect_options opt=VECT_ALL_ITEMS);
147
148#ifndef LATATOOLS
149 //
150 // All the methods below involve parallelism or are not used in lata_tools
151 //
152
153 // Default: min and max over real items (compat. 1.5.6):
154 inline _TYPE_ local_max_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return local_max_vect_(*this, opt); }
155 inline _TYPE_ local_min_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return local_min_vect_(*this, opt); }
156 inline _TYPE_ local_max_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return local_max_abs_vect_(*this, opt); }
157 inline _TYPE_ local_min_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return local_min_abs_vect_(*this, opt); }
158 inline _TYPE_ mp_max_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return mp_max_vect_(*this, opt); }
159 inline _TYPE_ mp_min_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return mp_min_vect_(*this, opt); }
160 inline _TYPE_ mp_max_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return mp_max_abs_vect_(*this, opt); }
161 inline _TYPE_ mp_min_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const { return mp_min_abs_vect_(*this, opt); }
162 inline _TYPE_ mp_norme_vect() const { return mp_norme_vect_(*this); }
163#endif // LATATOOLS
164
165 // Virtual methods
166
167 inline virtual void ref(const TRUSTVect&);
168 inline virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type = IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname");
169 inline virtual void start_echange_espace_virtuel_async(const std::string kernel_name);
170 inline virtual void finish_echange_espace_virtuel_async(const std::string kernel_name);
171
172 inline virtual void set_md_vector(const MD_Vector&);
173 inline virtual void jump(Entree&);
174 inline virtual void lit(Entree&, bool resize_and_read=1);
175 inline virtual void ecrit(Sortie&) const;
176 inline virtual void detach_vect() { md_vector_.detach(); }
177
178 inline void ref_data(_TYPE_* ptr, _SIZE_ new_size) override;
179 inline void ref_array(TRUSTArray<_TYPE_,_SIZE_>&, _SIZE_ start = 0, _SIZE_ sz = -1) override;
180
183 inline const Span_ get_span() const override { return Span_((_TYPE_*)TRUSTArray<_TYPE_,_SIZE_>::addr(), size_reelle()); }
185
186 /*! @brief Resets the object to the state obtained by the default constructor.
187 *
188 */
189 inline void reset() override
190 {
191 md_vector_.detach();
192 line_size_ = 1;
193 size_reelle_ = 0;
195 }
196
197protected:
198 inline void set_line_size_(int n); // Even in 64b we suppose line_size_ is always sufficiently small to fit in an int.
199 inline void resize_vect_(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT);
200 inline void copy_(const TRUSTVect& v, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT);
201
202 // A DoubleVect is an ArrOfDouble that optionally carries a distributed array structure. This pointer may be null.
204
205 // The size_reelle property of the array (provided by scattered_vect_data). -1 => calls to size_reelle() and size() are invalid for this vector.
207
208 // Multiplicative factor between md_vector_.nb_items_tot() and size_array(), and between md_vector_.nb_items_reels() and size_reelle_.
209 // For a 2D array, this is typically the product of dimension(i) for i>1 (one array row per geometric item in the descriptor).
210 // Warning: line_size_ may be zero for an array with zero columns, but not if a descriptor is attached.
211 // Even in 64b we suppose line_size_ is always sufficiently small to fit in an int.
213};
214
215using DoubleVect = TRUSTVect<double, int>;
216using FloatVect = TRUSTVect<float, int>;
217using IntVect = TRUSTVect<int, int>;
218using TIDVect = TRUSTVect<trustIdType, int>;
219
220template <typename _TYPE_>
221using BigTRUSTVect = TRUSTVect<_TYPE_, trustIdType>;
222
223using BigDoubleVect = BigTRUSTVect<double>;
224using BigIntVect = BigTRUSTVect<int>;
225using BigTIDVect = BigTRUSTVect<trustIdType>;
226
227/* ********************************** *
228 * NON-MEMBER FUNCTIONS OF TRUSTVect *
229 * ********************************** */
230
231#include <TRUSTVect_tools.tpp> // external templates function specializations ici ;)
232
233/* ****************************** *
234 * MEMBER FUNCTIONS OF TRUSTVect *
235 * ****************************** */
236
237#include <TRUSTVect.tpp> // template specializations are here ;)
238
239#endif /* TRUSTVect_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
: This class is an OWN_PTR but the pointed object is shared among multiple
Definition MD_Vector.h:48
int numero() const
Returns the index of the object in Memoire::data.
Definition Objet_U.cpp:264
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
Definition Process.cpp:102
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
virtual void reset()
Definition TRUSTArray.h:240
_SIZE_ size_array() const
_TYPE_ * addr()
Entree & readOn(Entree &is) override
Reads an Objet_U from an input stream. Virtual method to override.
friend class TRUSTArray
Definition TRUSTArray.h:108
Sortie & printOn(Sortie &os) const override
Writes the object to an output stream. Virtual method to override.
void operator*=(const TRUSTVect &v)
Definition TRUSTVect.h:116
void ref_as_small(TRUSTVect< _TYPE_, int > &out) const
virtual void finish_echange_espace_virtuel_async(const std::string kernel_name)
void carre(Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.h:133
Entree & readOn(Entree &is) override
Reads a sequential vector (like an ArrOfDouble). Invalid call if the vector has a non-null MD_Vector.
Definition TRUSTVect.h:60
_SIZE_ size() const
Definition TRUSTVect.tpp:45
_TYPE_ local_min_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:157
TRUSTVect & operator=(_TYPE_)
void operator/=(const TRUSTVect< _T_, _SIZE_ > &v)
Definition TRUSTVect.h:120
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
void operator+=(const _TYPE_ x)
Definition TRUSTVect.h:113
_TYPE_ mp_min_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:161
_TYPE_ local_max_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:154
void copy(const TRUSTArray< _TYPE_, _SIZE_ > &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void operator+=(const TRUSTVect &v)
Definition TRUSTVect.h:112
int line_size() const
Definition TRUSTVect.tpp:67
TRUSTVect & operator=(const TRUSTVect &)
virtual void lit(Entree &, bool resize_and_read=1)
virtual void jump(Entree &)
virtual void detach_vect()
Definition TRUSTVect.h:176
virtual ~TRUSTVect()
Definition TRUSTVect.h:80
_TYPE_ mp_max_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:160
void ref_as_big(TRUSTVect< _TYPE_, trustIdType > &out) const
void abs(Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.h:132
TRUSTVect(const TRUSTVect &v)
Copy constructor.
Definition TRUSTVect.h:100
_TYPE_ mp_norme_vect() const
Definition TRUSTVect.h:162
void copy_(const TRUSTVect &v, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Sortie & printOn(Sortie &os) const override
Writes the object to an output stream. Virtual method to override.
Definition TRUSTVect.h:45
virtual void set_md_vector(const MD_Vector &)
_TYPE_ mp_max_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:158
_SIZE_ size_reelle() const
Definition TRUSTVect.tpp:27
const Span_ get_span() const override
Definition TRUSTVect.h:183
unsigned taille_memoire() const override
Definition TRUSTVect.h:36
virtual void start_echange_espace_virtuel_async(const std::string kernel_name)
_SIZE_ size_reelle_ok() const
Definition TRUSTVect.tpp:38
void racine_carree(Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.h:134
void from_tid_to_int(TRUSTVect< int, int > &out) const
void operator-=(const TRUSTVect &v)
Definition TRUSTVect.h:114
void ref_array(TRUSTArray< _TYPE_, _SIZE_ > &, _SIZE_ start=0, _SIZE_ sz=-1) override
int duplique() const override
Definition TRUSTVect.h:38
void operator-=(const _TYPE_ x)
Definition TRUSTVect.h:115
const Span_ get_span_tot() const override
Definition TRUSTVect.h:184
void resize_vect_(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Span_ get_span_tot() override
Definition TRUSTVect.h:182
Span_ get_span() override
Definition TRUSTVect.h:181
void ajoute_carre(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
_TYPE_ local_max_abs_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:156
virtual void ecrit(Sortie &) const
void ajoute(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
Definition TRUSTVect.tpp:52
void reset() override
Resets the object to the state obtained by the default constructor.
Definition TRUSTVect.h:189
void set_line_size_(int n)
Definition TRUSTVect.tpp:78
tcb::span< int > Span_
Definition TRUSTVect.h:75
void ajoute_sans_ech_esp_virt(_SCALAR_TYPE_ alpha, const TRUSTVect &y, Mp_vect_options opt=VECT_REAL_ITEMS)
_TYPE_ local_min_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:155
void ref_data(_TYPE_ *ptr, _SIZE_ new_size) override
TRUSTVect(_SIZE_ n)
Constructs a vector of size n.
Definition TRUSTVect.h:90
_TYPE_ mp_min_vect(Mp_vect_options opt=VECT_REAL_ITEMS) const
Definition TRUSTVect.h:159
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
friend class TRUSTVect
Definition TRUSTVect.h:78
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
void ajoute_produit_scalaire(_SCALAR_TYPE_ alpha, const TRUSTVect &x, const TRUSTVect &y, Mp_vect_options opt=VECT_ALL_ITEMS)
void copy(const TRUSTVect &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
virtual void ref(const TRUSTVect &)
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
void resize_tab(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) override