16#ifndef TRUSTTab_TPP_included
17#define TRUSTTab_TPP_included
22template<
typename _TYPE_,
typename _SIZE_>
25 assert(this->
nb_dim_ == 1 || (this->
nb_dim_ == 2 && dimensions_[1] == 1));
26 assert(i >= 0 && i < dimension_tot_0_);
31template<
typename _TYPE_,
typename _SIZE_>
34 assert(this->
nb_dim_ == 1 || (this->
nb_dim_ == 2 && dimensions_[1] == 1));
35 assert(i >= 0 && i < dimension_tot_0_);
39template<
typename _TYPE_,
typename _SIZE_>
42 assert(this->
nb_dim_ == 1 || (this->
nb_dim_ == 2 && dimensions_[1] == 1));
43 assert(i >= 0 && i < dimension_tot_0_);
47template<
typename _TYPE_,
typename _SIZE_>
50 assert(this->
nb_dim_ == 1 || (this->
nb_dim_ == 2 && dimensions_[1] == 1));
51 assert(i >= 0 && i < dimension_tot_0_);
55#pragma GCC diagnostic push
56#pragma GCC diagnostic ignored "-Wstrict-overflow"
57template<
typename _TYPE_,
typename _SIZE_>
61 assert(i1 >= 0 && i1 < dimension_tot_0_);
62 assert(i2 >= 0 && i2 < dimensions_[1]);
66template<
typename _TYPE_,
typename _SIZE_>
70 assert(i1 >= 0 && i1 < dimension_tot_0_);
71 assert(i2 >= 0 && i2 < dimensions_[1]);
75template<
typename _TYPE_,
typename _SIZE_>
79 assert(i1 >= 0 && i1 < dimension_tot_0_);
80 assert(i2 >= 0 && i2 < dimensions_[1]);
81 assert(i3 >= 0 && i3 < dimensions_[2]);
85template<
typename _TYPE_,
typename _SIZE_>
89 assert(i1 >= 0 && i1 < dimension_tot_0_);
90 assert(i2 >= 0 && i2 < dimensions_[1]);
91 assert(i3 >= 0 && i3 < dimensions_[2]);
95template<
typename _TYPE_,
typename _SIZE_>
99 assert(i1 >= 0 && i1 < dimension_tot_0_);
100 assert(i2 >= 0 && i2 < dimensions_[1]);
101 assert(i3 >= 0 && i3 < dimensions_[2]);
102 assert(i4 >= 0 && i4 < dimensions_[3]);
106template<
typename _TYPE_,
typename _SIZE_>
110 assert(i1 >= 0 && i1 < dimension_tot_0_);
111 assert(i2 >= 0 && i2 < dimensions_[1]);
112 assert(i3 >= 0 && i3 < dimensions_[2]);
113 assert(i4 >= 0 && i4 < dimensions_[3]);
116#pragma GCC diagnostic pop
132template<
typename _TYPE_,
typename _SIZE_>
135 assert(i >= 0 && i < this->
nb_dim_);
137 assert(dimensions_[i] >= 0);
138 assert(i == 0 || dimensions_[i] < std::numeric_limits<int>::max());
139 return dimensions_[i];
151template<
typename _TYPE_,
typename _SIZE_>
159template<
typename _TYPE_,
typename _SIZE_>
162 assert(i >= 0 && i < this->
nb_dim_);
163 return (i == 0) ? dimension_tot_0_ : dimensions_[i];
169template<
typename _TYPE_,
typename _SIZE_>
176 for (
int i = 0; i < this->
nb_dim_; i++)
178 assert(dimensions_[i] < std::numeric_limits<int>::max());
179 sizes[i] = (int)dimensions_[i];
187template<
typename _TYPE_,
typename _SIZE_>
191 out.dimension_tot_0_ = dimension_tot_0_;
192 for(
int d=0; d<out.
nb_dim_; d++)
193 out.dimensions_[d] = dimensions_[d];
197template<
typename _TYPE_,
typename _SIZE_>
201 if(dimension_tot_0_ > std::numeric_limits<int>::max() || dimensions_[0] > std::numeric_limits<int>::max())
202 Process::exit(
"TRUSTTab<_TYPE_,_SIZE_>::ref_as_small() - initial array is too big to be referenced as 32b-long array!");
203 out.dimension_tot_0_ =
static_cast<int>(dimension_tot_0_);
205 out.dimensions_[d] =
static_cast<int>(dimensions_[d]);
212template<
typename _TYPE_,
typename _SIZE_>
218 const _SIZE_ n = dimension_tot_0_;
219 dimensions_[0] = ++dimension_tot_0_;
227template<
typename _TYPE_,
typename _SIZE_>
233 const _SIZE_ n = dimension_tot_0_ * 2;
234 dimensions_[0] = ++dimension_tot_0_;
242template<
typename _TYPE_,
typename _SIZE_>
248 const _SIZE_ n = dimension_tot_0_ * 3;
249 dimensions_[0] = ++dimension_tot_0_;
258template<
typename _TYPE_,
typename _SIZE_>
264 const _SIZE_ n = dimension_tot_0_ * 4;
265 dimensions_[0] = ++dimension_tot_0_;
278template<
typename _TYPE_,
typename _SIZE_>
281 assert(std::string(
typeid(v).name()).find(
"TRUSTVect") != std::string::npos);
298 dimensions_[0] = sz / l;
300 else dimensions_[0] = -1;
303 assert(verifie_LINE_SIZE());
307template<
typename _TYPE_,
typename _SIZE_>
312 for (
int i = 0; i < MAXDIM_TAB; i++) dimensions_[i] = src.dimensions_[i];
313 dimension_tot_0_ = src.dimension_tot_0_;
314 assert(verifie_LINE_SIZE());
318template<
typename _TYPE_,
typename _SIZE_>
322 if (new_size<0) new_size=-new_size;
325 dimensions_[0] = dimension_tot_0_ = new_size;
326 assert(verifie_LINE_SIZE());
331template<
typename _TYPE_,
typename _SIZE_>
338 assert(verifie_LINE_SIZE());
344template<
typename _TYPE_,
typename _SIZE_>
347 if (nb_lines < 0) nb_lines = t.dimension_tot_0_ - start_line;
348 assert(start_line >= 0 && nb_lines >= 0 && start_line + nb_lines <= t.dimension_tot_0_);
354 dimension_tot_0_ = nb_lines;
355 dimensions_[0] = nb_lines;
356 for (
int i = 1; i < MAXDIM_TAB; i++) dimensions_[i] = t.dimensions_[i];
357 assert(verifie_LINE_SIZE());
361template<
typename _TYPE_,
typename _SIZE_>
366 dimension_tot_0_ = 0;
368 assert(verifie_LINE_SIZE());
372template<
typename _TYPE_,
typename _SIZE_>
376 assert(verifie_LINE_SIZE());
380template<
typename _TYPE_,
typename _SIZE_>
384 assert(n1 >= 0 && n2 >= 0);
389 init_dimensions(dimensions_);
391 dimensions_[0] = dimension_tot_0_ = n1;
396 assert(verifie_LINE_SIZE());
399template<
typename _TYPE_,
typename _SIZE_>
403 assert(n1 >= 0 && n2 >= 0 && n3 >= 0);
408 init_dimensions(dimensions_);
410 dimensions_[0] = dimension_tot_0_ = n1;
416 assert(verifie_LINE_SIZE());
419template<
typename _TYPE_,
typename _SIZE_>
423 assert(n1 >= 0 && n2 >= 0 && n3 >= 0 && n4 >= 0);
428 init_dimensions(dimensions_);
430 dimensions_[0] = dimension_tot_0_ = n1;
437 assert(verifie_LINE_SIZE());
440template<
typename _TYPE_,
typename _SIZE_>
444 if (this->
nb_dim_ == 2 && dimensions_[1] == 1)
return;
452 assert(verifie_LINE_SIZE());
458template<
typename _TYPE_,
typename _SIZE_>
464 dimensions_[0] = dimension_tot_0_ = n;
465 assert(verifie_LINE_SIZE());
468template<
typename _TYPE_,
typename _SIZE_>
475 dimensions_[0] = dimension_tot_0_ = n;
476 assert(verifie_LINE_SIZE());
479template<
typename _TYPE_,
typename _SIZE_>
482 assert(n >= 0 && n2 >= 0);
484 _SIZE_ new_size = n * n2;
486 if (std::is_same<_TYPE_,int>::value && new_size < 0)
488 Cerr <<
"n1*n2 > 2^31. Error! Contact TRUST support, integer 32 bits limit exceeded with n1=" << n <<
" and n2=" << n2 << finl;
494 dimensions_[0] = dimension_tot_0_ = n;
496 assert(verifie_LINE_SIZE());
499template<
typename _TYPE_,
typename _SIZE_>
502 assert(n >= 0 && n2 >= 0 && n3 >= 0);
504 _SIZE_ new_size = n * n2 * n3;
506 if (std::is_same<_TYPE_,int>::value && new_size < 0)
508 Cerr <<
"n1*n2*n3 > 2^31. Error! Contact TRUST support, integer 32 bits limit exceeded with n1=" << n <<
" and n2=" << n2 <<
" and n3=" << n3 << finl;
514 dimensions_[0] = dimension_tot_0_ = n;
517 assert(verifie_LINE_SIZE());
520template<
typename _TYPE_,
typename _SIZE_>
523 assert(n >= 0 && n2 >= 0 && n3 >= 0 && n4 >= 0);
525 _SIZE_ new_size = n * n2 * n3 * n4;
527 if (std::is_same<_TYPE_,int>::value && new_size<0)
529 Cerr <<
"n1*n2*n3*n4 > 2^31. Error! Contact TRUST support, integer 32 bits limit exceeded with n1=" << n <<
" and n2=" << n2 <<
" and n3=" << n3 <<
" and n4=" << n4 << finl;
535 dimensions_[0] = dimension_tot_0_ = n;
539 assert(verifie_LINE_SIZE());
544template<
typename _TYPE_,
typename _SIZE_>
548 if (this->nb_dim_ <= 0 || this->
nb_dim_ > MAXDIM_TAB)
550 Cerr <<
"Internal error in TRUSTTab::resize(const ArrOfInt & tailles, ...) \n" <<
" wrong dimensions number " << this->
nb_dim_ << finl;
554 for (
int i = 0; i < this->
nb_dim_; i++)
556 const _SIZE_ n = tailles[i];
562 Cerr <<
"Internal error in TRUSTTab::resize(const ArrOfInt & tailles, ...) \n";
564 Cerr <<
" wrong dimensions: " << tailles << finl;
569 dimension_tot_0_ = dimensions_[0];
572 assert(verifie_LINE_SIZE());
577template<
typename _TYPE_,
typename _SIZE_>
586template<
typename _TYPE_,
typename _SIZE_>
589 assert(std::string(
typeid(src).name()).find(
"TRUSTVect") != std::string::npos);
604 dimensions_[0] = sz / l;
607 else dimensions_[0] = -1;
610 assert(verifie_LINE_SIZE());
614template<
typename _TYPE_,
typename _SIZE_>
621template<
typename _TYPE_,
typename _SIZE_>
628 for (
int i = 0; i < MAXDIM_TAB; i++) dimensions_[i] = src.dimensions_[i];
629 dimension_tot_0_ = src.dimension_tot_0_;
630 assert(verifie_LINE_SIZE());
634template<
typename _TYPE_,
typename _SIZE_>
638 verifie_MAXDIM_TAB();
646 return operator()(indice[0], indice[1], indice[2]);
648 return operator()(indice[0], indice[1], indice[2], indice[3]);
652template<
typename _TYPE_,
typename _SIZE_>
656 verifie_MAXDIM_TAB();
664 return operator()(indice[0], indice[1], indice[2]);
666 return operator()(indice[0], indice[1], indice[2], indice[3]);
672template<
typename _TYPE_,
typename _SIZE_>
676 _SIZE_ dim0 = dimension_tot_0_;
680 dimensions_[0] = dim0;
681 assert(verifie_LINE_SIZE());
687template<
typename _TYPE_,
typename _SIZE_>
700template<
typename _TYPE_,
typename _SIZE_>
709template<
typename _TYPE_,
typename _SIZE_>
720 for (
int i = 1; i < this->
nb_dim_; i++)
724 if (ok && tmp.
size_array() != this->nb_dim_) ok = 0;
726 for (
int i = 0; i < this->
nb_dim_; i++)
735 resize(tmp, RESIZE_OPTIONS::NOCOPY_NOINIT);
740 Cerr <<
"Error in DoubleTab::lit: array has wrong dimensions" << finl;
743 Cerr <<
"We try to read an array with " <<
dimension(0) <<
" items whereas we are waiting for a size of " << tmp[0] <<
"!" << finl;
744 Cerr <<
"Probably a different partitionning from your previous calculation..." << finl;
745 Cerr <<
"Change your current partitionning to match the previous calculation or try .xyz restart protocol." << finl;
758template<
typename _TYPE_,
typename _SIZE_>
759template <
typename _T_>
769 const int line_size_x = vx.
line_size(), line_size_y = vy.line_size(), line_size_xy = v.
line_size();
770 assert(line_size_xy == line_size_x * line_size_y);
773 assert(vy.size_totale() * line_size_xy == v.
size_totale() * line_size_y);
794 for (; nblocs_left; nblocs_left--)
796 const _SIZE_ debut = (*(bloc_itr++)), fin = (*(bloc_itr++));
797 _SIZE_ v_index = debut * line_size_xy;
798 for (_SIZE_ i = debut; i < fin; i++)
799 for (_SIZE_ j = 0; j < line_size_x; j++)
801 _T_ xval = vx[i * line_size_x + j];
802 for (_SIZE_ k = 0; k < line_size_y; k++)
804 _T_ yval = vy[i * line_size_y + k];
805 v[v_index] += alpha * xval * yval;
813template<
typename _TYPE_,
typename _SIZE_>
814template <
typename _T_>
822 bool cvg = (*this).decomp_LU(n,index,lu_dec);
824 if(cvg) lu_dec.
resoud_LU(n,index,b,solution);
831template<
typename _TYPE_,
typename _SIZE_>
832template <
typename _T_>
836 _SIZE_ i, j, k, imax = -1, cvg = 1;
837 _T_ big, dum, sum, temp;
841 for (i=0 ; i<n ; i++)
844 for (j=0 ; j<n ; j++)
845 if ((temp = std::fabs(matLU(i,j))) > big) big = temp;
849 Cerr <<
"Singular matrix in LU decomposition"<<finl;
857 for (j=0 ; j<n ; j++)
859 for (i=0 ; i<j ; i++)
862 for (k=0 ; k<i ; k++) sum -= matLU(i,k) * matLU(k,j);
867 for (i=j ; i<n ; i++)
870 for (k=0 ; k<j ; k++) sum -= matLU(i,k) * matLU(k,j);
872 if ((dum = vv[i]*std::fabs(sum)) >= big)
881 for (k=0 ; k<n ; k++)
884 matLU(imax,k) = matLU(j,k);
892 for (i=j+1 ; i<n ; i++) matLU(i,j) *= dum;
898template<
typename _TYPE_,
typename _SIZE_>
899template <
typename _T_>
905 for (i=0 ; i<n ; i++)
909 solution[ip] = solution[i];
911 for (j=ii ; j<i ; j++) sum -= (*
this)(i,j)*solution[j];
917 for (i=n-1 ; i>=0 ; i--)
920 for (j=i+1 ; j<n ; j++) sum -= (*
this)(i,j)*solution[j];
921 solution[i] = sum/(*this)(i,i);
927template<
typename _TYPE_,
typename _SIZE_>
928template <
typename _T_>
934 const _T_ *u_ptr = u.
addr();
935 const _T_ epsilon = 1.e-8;
939 _T_ a = std::fabs(*du_ptr), b = std::fabs(*u_ptr), c = a / (b + epsilon);
940 if (b > 1.e-2 && c > res) res = c;
Class defining operators and methods for all reading operation in an input flow (file,...
virtual bool use_blocks() const =0
virtual int get_nb_items_reels() const
virtual const ArrOfInt & get_blocs_items_to_compute() const =0
: Cette classe est un OWN_PTR mais l'objet pointe est partage entre plusieurs
static bool is_parallel()
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Classe de base des flux de sortie.
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
_SIZE_ size_array() const
_TYPE_ & operator[](_SIZE_ i)
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void jump(Entree &) override
void ref_as_big(TRUSTTab< _TYPE_, trustIdType > &out) const
virtual void ref(const TRUSTTab &)
void set_md_vector(const MD_Vector &) override
void resoud_LU(_SIZE_, TRUSTArray< int, _SIZE_ > &, const TRUSTArray< _T_, _SIZE_ > &, TRUSTArray< _T_, _SIZE_ > &)
int dimension_int(int d) const
void ref_array(TRUSTArray< _TYPE_, _SIZE_ > &, _SIZE_ start=0, _SIZE_ sz=-1) override
void ref_data(_TYPE_ *ptr, _SIZE_ size) override
void promote_scalar_to_dim2()
void lit(Entree &, bool resize_and_read=true) override
void ref_as_small(TRUSTTab< _TYPE_, int > &out) const
void reshape(_SIZE_ n1, int n2)
_TYPE_ & operator[](_SIZE_ i)
_TYPE_ & operator()(const TRUSTArray< _SIZE_, int > &indice)
virtual void ref_tab(TRUSTTab &, _SIZE_ start_line=0, _SIZE_ nb_lines=-1)
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void ecrit(Sortie &) const override
bool decomp_LU(_SIZE_, TRUSTArray< int, _SIZE_ > &, TRUSTTab< _T_, _SIZE_ > &)
void ajoute_produit_tensoriel(_T_ alpha, const TRUSTTab< _T_, _SIZE_ > &, const TRUSTTab< _T_, _SIZE_ > &)
_SIZE_ dimension_tot(int) const override
void resize_dim0(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_T_ max_du_u(const TRUSTTab< _T_, _SIZE_ > &)
bool inverse_LU(const TRUSTArray< _T_, _SIZE_ > &, TRUSTArray< _T_, _SIZE_ > &)
void copy(const TRUSTTab &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void from_tid_to_int(TRUSTTab< int, int > &out) const
void resize_tab(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) override
_SIZE_ dimension(int d) const
TRUSTTab & operator=(const TRUSTTab &)
void ref_as_small(TRUSTVect< _TYPE_, int > &out) const
_SIZE_ size_totale() const
TRUSTVect & operator=(const TRUSTVect &)
virtual void lit(Entree &, bool resize_and_read=1)
void ref_as_big(TRUSTVect< _TYPE_, trustIdType > &out) const
void copy_(const TRUSTVect &v, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
virtual void set_md_vector(const MD_Vector &)
_SIZE_ size_reelle() const
_SIZE_ size_reelle_ok() const
void from_tid_to_int(TRUSTVect< int, int > &out) const
void ref_array(TRUSTArray< _TYPE_, _SIZE_ > &, _SIZE_ start=0, _SIZE_ sz=-1) override
void resize_vect_(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
virtual void ecrit(Sortie &) const
void reset() override
met l'objet dans l'etat obtenu par le constructeur par defaut.
void set_line_size_(int n)
void ref_data(_TYPE_ *ptr, _SIZE_ new_size) override
virtual const MD_Vector & get_md_vector() const
virtual void ref(const TRUSTVect &)