TRUST 1.9.8
HPC thermohydraulic platform
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 Lecture d'un vecteur sequentiel (comme un ArrOfDouble) Attention: appel invalide si le vecteur a un MD_Vector non nul.
56 *
57 * (pour les vecteurs paralleles, utiliser une methode de sauvegarde/reprise)
58 *
59 */
60 Entree& readOn(Entree& is) override
61 {
62#ifndef LATATOOLS
63 // Que veut-on faire si on lit dans un vecteur ayant deja une structure parallele ?
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 construction d'un vecteur de taille n.
85 *
86 * Les elements du vecteur sont initialises a zero par defaut. Pour ne pas initialiser les valeurs, utiliser ceci: 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 Constructeur par copie.
93 *
94 * Il s'agit d'un "deep copy" voir ArrOfDouble::ArrOfDouble(const ArrOfDouble &) Remarque: il n'y a pas de constructeur par copie a partir de ArrOfDouble
95 * Ceci est volontaire, sinon on risque de grosses pertes de performances par creation implicite d'objets, difficile a trouver.
96 * (exemple: appel d'une methode toto(const IntVect &) avec un ArrOfInt produit une copie du tableau !)
97 * Utiliser copy() pour copier un ArrOfDouble dans un 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 // Options par defaut choisies pour compatibilite avec la version precedente. Attention: il y avait un echange_espace_virtuel avant, ce n'est pas strictement 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 // par defaut: min et max sur items reels (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 // methodes virtuelles
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 met l'objet dans l'etat obtenu par le constructeur par defaut.
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 // Un DoubleVect est un ArrOfDouble qui possede eventuellement une structure de tableau distribue. Ce pointeur peut etre nul.
204
205 // Propriete size_reelle du tableau (fournie par scattered_vect_data). -1 => l'appel a size_reelle() et size() est invalide pour ce vecteur.
207
208 // Facteur multiplicatif a appliquer entre md_vector_.nb_items_tot() et size_array() et entre md_vector_.nb_items_reels() et size_reelle_.
209 // Si l'objet est un tableau, ce facteur est generalement egal au produit des dimension(i) pour i>1 (une ligne du tableau par item geometrique du descripteur)
210 // Attention, line_size_ peut etre nul pour un tableau a zero colonnes mais pas s'il y a un descripteur attache.
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 * FONCTIONS NON MEMBRES DE TRUSTVect *
229 * ********************************** */
230
231#include <TRUSTVect_tools.tpp> // external templates function specializations ici ;)
232
233/* ****************************** *
234 * FONCTIONS MEMBRES DE TRUSTVect *
235 * ****************************** */
236
237#include <TRUSTVect.tpp> // templates specializations ici ;)
238
239#endif /* TRUSTVect_included */
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
Definition MD_Vector.h:48
int numero() const
Renvoie l'indice de l'objet dans Memoire::data.
Definition Objet_U.cpp:268
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
Definition Process.cpp:104
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
virtual void reset()
Definition TRUSTArray.h:240
_SIZE_ size_array() const
_TYPE_ * addr()
Entree & readOn(Entree &is) override
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
friend class TRUSTArray
Definition TRUSTArray.h:108
Sortie & printOn(Sortie &os) const override
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
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
Lecture d'un vecteur sequentiel (comme un ArrOfDouble) Attention: appel invalide si le vecteur a un M...
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)
Constructeur par copie.
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
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
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
met l'objet dans l'etat obtenu par le constructeur par defaut.
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)
construction d'un vecteur de taille 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