TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
MD_Vector_base.cpp
1/****************************************************************************
2* Copyright (c) 2025, 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 <MD_Vector_base.h>
17#include <TRUSTTabs.h>
18#include <ArrOfBit.h>
19#include <Param.h>
20
21Implemente_base(MD_Vector_base, "MD_Vector_base", Objet_U);
22
23/*! @brief method used to dump/restore a descriptor in a file Each process writes a different descriptor.
24 *
25 * See MD_Vector_tools::dump_vector_with_md()
26 *
27 */
29{
30 Param p("MD_Vector_base");
31 p.ajouter("nb_items_tot", &nb_items_tot_);
32 p.ajouter("nb_items_reels", &nb_items_reels_);
33 p.ajouter("nb_items_seq_tot", &nb_items_seq_tot_);
34 p.ajouter("nb_items_seq_local", &nb_items_seq_local_);
35 p.lire_avec_accolades(is);
36 return is;
37}
38
40{
41 os << "{" << finl;
42 os << "nb_items_tot" << tspace << nb_items_tot_ << finl;
43 os << "nb_items_reels" << tspace << nb_items_reels_ << finl;
44 os << "nb_items_seq_tot" << tspace << nb_items_seq_tot_ << finl;
45 os << "nb_items_seq_local" << tspace << nb_items_seq_local_ << finl;
46 os << "}" << finl;
47 return os;
48}
49
50/*! Check the consistency of array size as defined by the MD_Vector and as found in the array.
51 */
52bool MD_Vector_base::validate(trustIdType sz_array, int line_size) const
53{
54 int size_tot = this->get_nb_items_tot() * line_size;
55 if (size_tot != sz_array)
56 {
57 Cerr << "Internal error in TRUSTVect::set_md_vector(): wrong array size\n"
58 << " Needed size = " << this->get_nb_items_tot() << " x " << line_size
59 << "\n Actual size = " << sz_array << finl;
61 }
62 if (line_size == 0)
63 {
64 Cerr << "Internal error in TRUSTVect::set_md_vector():\n"
65 << " cannot attach descriptor to empty array (line_size_ is zero)" << finl;
67 }
68 return true;
69}
70
71int MD_Vector_base::get_sequential_items_flags(ArrOfBit& flags, int line_size) const
72{
73 const int sz = get_nb_items_tot() * line_size;
74 flags.resize_array(sz);
75 flags = 1; // valeur par defaut la plus courante (0 est le cas particulier)
76 return get_seq_flags_impl(flags, line_size);
77}
78
79// This version is just used in SSOR I think:
80int MD_Vector_base::get_sequential_items_flags(ArrOfInt& flags, int line_size) const
81{
82 const int sz = get_nb_items_tot() * line_size;
83 flags.resize_array(sz);
84
85 ArrOfBit flgs_bits(sz);
86 flgs_bits = 1; // valeur par defaut la plus courante (0 est le cas particulier)
87 int n = get_seq_flags_impl(flgs_bits, line_size);
88 for (int i=0; i<sz; i++)
89 flags[i] = flgs_bits[i];
90
91 return n;
92}
93
94
95/*! @brief methode outil pour ajouter un item a un tableau du genre "blocs" contenant des series de blocs.
96 *
97 * .. alonge le bloc precedent ou commence un nouveau bloc si l'item n'est pas contigu avec le bloc precedent.
98 */
99void MD_Vector_base::append_item_to_blocs(ArrOfInt& blocs, int item)
100{
101 int n = blocs.size_array();
102 assert(n % 2 == 0); // le tableau contient des blocs, donc un nombre pair d'elements
103 assert(n == 0 || item >= blocs[n - 1]); // les items doivent etre ajoutes dans l'ordre croissant
104 if (n == 0 || blocs[n - 1] != item)
105 {
106 // nouveau bloc
107 blocs.append_array(item);
108 blocs.append_array(item + 1);
109 }
110 else blocs[n - 1] = item + 1;
111}
112
113void MD_Vector_base::append_blocs(ArrOfInt& dest, const ArrOfInt& src, int offset, int multiplier)
114{
115 int i = dest.size_array();
116 const int n = src.size_array();
117 dest.resize_array(i + n);
118 for (int j = 0; j < n; j++, i++)
119 dest[i] = offset + src[j] * multiplier;
120}
121
122void MD_Vector_base::append_items(ArrOfInt& dest, const ArrOfInt& src, int offset, int multiplier)
123{
124 int i = dest.size_array();
125 const int n = src.size_array();
126 dest.resize_array(i + n * multiplier);
127 for (int j = 0; j < n; j++)
128 {
129 int x = offset + src[j] * multiplier;
130 for (int k = 0; k < multiplier; k++)
131 dest[i++] = x++;
132 }
133}
134
135int MD_Vector_base::get_seq_flags_impl(ArrOfBit& flags, int line_size) const
136{
137 int count = 0;
138 const ArrOfInt& itm_sum = get_blocs_items_to_sum();
139 const int nblocs = itm_sum.size_array() >> 1;
140 const int *ptr = itm_sum.addr();
141 int j = 0;
142 for (int i = nblocs; i; i--)
143 {
144 // On pourrait optimiser pour les ArrOfBit en ajoutant a cette classe
145 // une methode setflag/clearflag(range_begin, range_end);
146 int jmax = (*(ptr++)) * line_size; // debut du prochain bloc d'items sequentiels
147 for (; j < jmax; j++)
148 flags.clearbit(j);
149 jmax = (*(ptr++)) * line_size; // fin du bloc d'items sequentiels
150 assert(jmax > j);
151 count += jmax - j;
152 for (; j < jmax; j++)
153 {
154 assert(flags[j] == 1); // was already set by default in caller
155 }
156 }
157 // Fin du remplissage
158 int sz = get_nb_items_tot() * line_size;
159 for (; j < sz; j++)
160 flags.clearbit(j);
161 return count;
162}
163
ArrOfBit_32_64 & resize_array(int_t n)
Change la taille du tableau et copie les donnees existantes.
Definition ArrOfBit.cpp:71
void clearbit(int_t i) const
Met le bit e a 0.
Definition ArrOfBit.h:100
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for distributed vectors parallel descriptors.
virtual const ArrOfInt & get_blocs_items_to_sum() const =0
int get_sequential_items_flags(ArrOfBit &flags, int line_size=1) const
static void append_blocs(ArrOfInt &dest, const ArrOfInt &src, int offset=0, int multiplier=1)
trustIdType nb_items_seq_tot_
virtual int get_seq_flags_impl(ArrOfBit &flags, int line_size) const
static void append_items(ArrOfInt &dest, const ArrOfInt &src, int offset=0, int multiplier=1)
virtual bool validate(trustIdType sz_array, int line_size) const
virtual int get_nb_items_tot() const
static void append_item_to_blocs(ArrOfInt &blocs, int item)
methode outil pour ajouter un item a un tableau du genre "blocs" contenant des series de blocs.
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)