TrioCFD 1.9.9_beta
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; // most common default value (0 is the special case)
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; // most common default value (0 is the special case)
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 Helper method to append an item to a "blocs"-type array containing series of blocks.
96 *
97 * Extends the previous block or starts a new block if the item is not contiguous with the previous block.
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); // the array contains blocks, so an even number of elements
103 assert(n == 0 || item >= blocs[n - 1]); // items must be added in ascending order
104 if (n == 0 || blocs[n - 1] != item)
105 {
106 // new block
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 // Could be optimised for ArrOfBit by adding a setflag/clearflag(range_begin, range_end) method to this class;
145 int jmax = (*(ptr++)) * line_size; // start of the next block of sequential items
146 for (; j < jmax; j++)
147 flags.clearbit(j);
148 jmax = (*(ptr++)) * line_size; // end of the block of sequential items
149 assert(jmax > j);
150 count += jmax - j;
151 for (; j < jmax; j++)
152 {
153 assert(flags[j] == 1); // was already set by default in caller
154 }
155 }
156 // End of filling
157 int sz = get_nb_items_tot() * line_size;
158 for (; j < sz; j++)
159 flags.clearbit(j);
160 return count;
161}
162
ArrOfBit_32_64 & resize_array(int_t n)
Changes the size of the array and copies existing data.
Definition ArrOfBit.cpp:70
void clearbit(int_t i) const
Set bit e to 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)
Helper method to append an item to a "blocs"-type array containing series of blocks.
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
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
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
_TYPE_ * addr()
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)