Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
StreamVBlockMatrixBuilderInserterT.h
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19#pragma once
20
21/*---------------------------------------------------------------------------*/
22
23#include <arccore/collections/Array2.h>
24
25/*---------------------------------------------------------------------------*/
26
27namespace Alien
28{
29
30/*---------------------------------------------------------------------------*/
31
32template <typename ValueT>
33StreamVBlockMatrixBuilderT<ValueT>::BaseInserter::BaseInserter()
34: m_parent(NULL)
35{
36 throw FatalErrorException(A_FUNCINFO, "Virtual Ctor never called");
37}
38
39/*---------------------------------------------------------------------------*/
40
41template <typename ValueT>
42StreamVBlockMatrixBuilderT<ValueT>::BaseInserter::BaseInserter(
43StreamVBlockMatrixBuilderT<ValueT>* parent, Integer id)
44: m_id(id)
45, m_index(0)
46, m_current_size(0)
47, m_current_k(NULL)
48, m_values(NULL)
49, m_count(0)
50, m_size(0)
51, m_parent(parent)
52{}
53
54/*---------------------------------------------------------------------------*/
55
56template <typename ValueT>
57StreamVBlockMatrixBuilderT<ValueT>::BaseInserter::~BaseInserter()
58{}
59
60/*---------------------------------------------------------------------------*/
61
62template <typename ValueT>
64{
65 m_index = 0;
66 m_current_size = 0;
67 m_current_k = NULL;
68 m_values = NULL;
69 m_count = 0;
70 m_size = 0;
71}
72
73/*---------------------------------------------------------------------------*/
74
75template <typename ValueT>
76Integer
81
82/*---------------------------------------------------------------------------*/
83
84template <typename ValueT>
86{
87 init();
88 m_n.resize(0);
89 m_row_index.resize(0);
90 m_col_index.resize(0);
91 m_data_index.resize(0);
92 m_block_size_row.resize(0);
93 m_block_size_col.resize(0);
94}
95
96/*---------------------------------------------------------------------------*/
97
98template <typename ValueT>
99void StreamVBlockMatrixBuilderT<ValueT>::BaseInserter::setMatrixValues(ValueT* matrix_values)
100{
101 ALIEN_ASSERT((this->m_parent->m_state == ePrepared), ("Inconsistent state"));
102 m_values = matrix_values;
103 m_index = 0;
104 m_current_size = m_n[0];
105 m_current_k = m_data_index.data();
106}
107
108/*---------------------------------------------------------------------------*/
109
110template <typename ValueT>
111Integer
114 return m_size;
115}
116
117/*---------------------------------------------------------------------------*/
118
119template <typename ValueT>
120Integer
125
126template <typename ValueT>
127bool StreamVBlockMatrixBuilderT<ValueT>::Filler::isBegin()
128{
129 return (this->m_index == 0);
130}
131
132/*---------------------------------------------------------------------------*/
133
134template <typename ValueT>
136{
137 return (this->m_index == this->m_size);
138}
139
140template <typename ValueT>
141Integer
143{
144 return this->m_current_size;
145}
146
147/*---------------------------------------------------------------------------*/
148
149template <typename ValueT>
150Integer
152{
153 return this->m_index;
154}
155
156/*---------------------------------------------------------------------------*/
157
158template <typename ValueT>
160{
161 // ALIEN_ASSERT((this->m_parent->m_state == eStart),("Inconsistent state"));
162 // ALIEN_ASSERT((this->m_values!=NULL),("Inserter is not ready for filling"));
163 this->m_index = 0;
164 this->m_current_size = this->m_n[0];
165 this->m_current_k = this->m_data_index.data();
166 this->m_current_block_size_row = this->m_block_size_row[0];
167 this->m_current_block_size_col = this->m_block_size_col[0];
168}
169
170/*---------------------------------------------------------------------------*/
171
172template <typename ValueT>
173void StreamVBlockMatrixBuilderT<ValueT>::Profiler::addMatrixEntry(
174Integer row_index, Integer col_index)
175{
176 // std::cout << "inserter inside " << row_index << "," << col_index << std::endl;
177 this->_startTimer();
178 const VBlock* block_sizes = this->m_parent->vblock();
179 // ALIEN_ASSERT((this->m_parent->m_state == ePrepared),("Inconsistent state"));
180 this->m_n.add(1);
181 ++this->m_count;
182 this->m_row_index.add(row_index);
183 this->m_col_index.add(col_index);
184 this->m_block_size_row.add(block_sizes->size(row_index));
185 this->m_block_size_col.add(block_sizes->size(col_index));
186 ++this->m_size;
187 this->_stopTimer();
188}
189
190/*---------------------------------------------------------------------------*/
191
192template <typename ValueT>
193void StreamVBlockMatrixBuilderT<ValueT>::Filler::addBlockData(ConstArray2View<ValueT> values)
194{
195 this->_startTimer();
196 // ALIEN_ASSERT((this->m_parent->m_state == eStart),("Inconsistent state"));
197 // ALIEN_ASSERT((values.dim1Size()==this->m_current_block_size_row),("Incompatible block
198 // row size %d vs %d",values.dim1Size(),this->m_current_block_size_row));
199 // ALIEN_ASSERT((values.dim2Size()==this->m_current_block_size_col),("Incompatible block
200 // row size %d vs %d",values.dim2Size(),this->m_current_block_size_col));
201
202 Array2View<ValueT> view(
203 this->m_values + *this->m_current_k, values.dim1Size(), values.dim2Size());
204
205 for (Integer i = 0; i < values.dim1Size(); ++i)
206 for (Integer k = 0; k < values.dim2Size(); ++k)
207 view[i][k] += values[i][k];
208
209 this->_stopTimer();
210}
211
212/*---------------------------------------------------------------------------*/
213
214template <typename ValueT>
215typename StreamVBlockMatrixBuilderT<ValueT>::Filler&
216StreamVBlockMatrixBuilderT<ValueT>::Filler::operator++()
217{
218 this->_startTimer();
219 // ALIEN_ASSERT((this->m_parent->m_state == eStart),("Inconsistent state"));
220 ++this->m_index;
221 this->m_current_k += this->m_current_size;
222 this->m_current_size = this->m_n[this->m_index];
223 this->m_current_block_size_row = this->m_block_size_row[this->m_index];
224 this->m_current_block_size_col = this->m_block_size_col[this->m_index];
225 this->_stopTimer();
226 return *this;
227}
228
229/*---------------------------------------------------------------------------*/
230
231} // namespace Alien
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
Integer getId() const
Identifiant de l'inserter dans son StreamVBlockMatrixBuilder.
void end()
Termine l'inserter (déallocation des données).
UniqueArray< Integer > m_data_index
positon of entry in the Matrix CSR structure
Integer currentSize()
Taille du bloc courant à insérer.
bool isEnd()
Retourn true, le filler est à la fin.
Integer index()
Retourne l'index d'itération courante de l'inserter.
StreamVBlockMatrixBuilderT(VBlockMatrix &matrix, bool init_and_start=true)
Variable size block elements for block matrices.
Definition VBlock.h:46
Arccore::Integer size(Arccore::Integer index) const
Get the size of a block.
Definition VBlock.cc:162
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17