29 typedef Integer IndexType;
37 CSRStructInfo(
bool is_variable_block =
false)
38 : m_is_variable_block(is_variable_block)
41 CSRStructInfo(Integer nrow,
bool is_variable_block =
false)
42 : m_is_variable_block(is_variable_block)
45 m_row_offset.resize(nrow + 1);
46 if (m_is_variable_block)
47 m_block_row_offset.resize(nrow + 1);
50 CSRStructInfo(Integer nrow,
const int* kcol,
const int* cols)
51 : m_is_variable_block(
false)
54 m_row_offset.resize(nrow + 1);
55 std::copy(kcol, kcol + nrow + 1, m_row_offset.data());
56 Integer nnz = kcol[nrow];
58 std::copy(cols, cols + nnz, m_cols.data());
61 CSRStructInfo(
const CSRStructInfo& src) { copy(src); }
63 virtual ~CSRStructInfo()
65#ifdef ALIEN_USE_PERF_TIMER
66 m_timer.printInfo(
"CSR-StructInfo");
70 CSRStructInfo& operator=(
const CSRStructInfo& src)
76 CSRStructInfo* clone()
const
78 return new CSRStructInfo(*
this);
81 void init(Arccore::Integer nrow)
84 m_row_offset.resize(nrow + 1);
85 if (m_is_variable_block)
86 m_block_row_offset.resize(nrow + 1);
89 void init(Integer nrows, Integer nnz)
91 assert(!m_is_variable_block);
93 m_row_offset.resize(nrows + 1);
95 m_row_offset[nrows] = nnz;
99 Arccore::Int64 timestamp()
const
104 void setTimestamp(Arccore::Int64 value)
109 bool getSymmetric()
const
114 void setSymmetric(
bool value)
119 Integer getNRows()
const
124 Integer getNRow()
const
129 Arccore::UniqueArray<Arccore::Integer>& getBlockRowOffset()
131 return m_block_row_offset;
134 Arccore::ArrayView<Integer> getRowOffset()
136 return m_row_offset.view();
139 Arccore::ConstArrayView<Integer> getRowOffset()
const
141 return m_row_offset.constView();
144 const int* kcol()
const
146 return m_row_offset.data();
151 return m_row_offset.data();
154 ConstArrayView<Integer> getBlockRowOffset()
const
156 return m_block_row_offset.constView();
159 UniqueArray<Integer>& getCols()
164 UniqueArray<Integer>& getBlockCols()
169 ConstArrayView<Integer> getCols()
const
171 return m_cols.constView();
176 return m_cols.data();
179 const int* cols()
const
181 return m_cols.data();
184 ConstArrayView<Integer> getBlockCols()
const
186 return m_block_cols.constView();
189 ColOrdering& getColOrdering()
191 return m_col_ordering;
194 ColOrdering getColOrdering()
const
196 return m_col_ordering;
199 void setDiagFirst(
bool val)
204 bool getDiagFirstOpt()
const
209 Integer getRowSize(Integer row)
const
211 return m_row_offset[row + 1] - m_row_offset[row];
214 Integer getBlockRowSize(Integer row)
const
216 return m_block_row_offset[row + 1] - m_block_row_offset[row];
219 Integer getNnz()
const
221 return m_row_offset[m_nrow];
224 Integer getNElems()
const
226 return m_row_offset[m_nrow];
229 Integer getBlockNnz()
const
231 return m_block_row_offset[m_nrow];
234 UniqueArray<Integer>& getUpperDiagOffset()
236 if (m_col_ordering != eUndef && m_upper_diag_offset.size() == 0)
237 computeUpperDiagOffset();
238 return m_upper_diag_offset;
241 ConstArrayView<Integer> getUpperDiagOffset()
const
243 if (m_col_ordering != eUndef && m_upper_diag_offset.size() == 0)
244 computeUpperDiagOffset();
245 return m_upper_diag_offset.constView();
248 int const* dcol()
const
250 if (m_col_ordering == eUndef)
253 getUpperDiagOffset();
254 return m_upper_diag_offset.data();
260 auto row_offset = (m_nrow > 0) ? m_row_offset[m_nrow] : 0;
261 m_cols.resize(row_offset);
262 if (m_is_variable_block)
263 m_block_cols.resize(row_offset + 1);
266 void computeUpperDiagOffset()
const
268#ifdef ALIEN_USE_PERF_TIMER
269 SentryType sentry(m_timer,
"CSR-ComputeDiagOffset");
271 if (m_col_ordering != eUndef) {
272 m_upper_diag_offset.resize(m_nrow);
273 for (
int irow = 0; irow < m_nrow; ++irow) {
274 int index = m_row_offset[irow];
275 for (
int k = m_row_offset[irow]; k < m_row_offset[irow + 1]; ++k) {
276 if (m_cols[k] < irow)
281 m_upper_diag_offset[irow] = index;
286 Integer computeBandeSize()
const
289 for (
int irow = 0; irow < m_nrow; ++irow) {
292 for (
int k = m_row_offset[irow]; k < m_row_offset[irow + 1]; ++k) {
294 min_col = std::min(col, min_col);
295 max_col = std::max(col, max_col);
297 bande_size = std::max(bande_size, max_col - min_col);
302 Integer computeUpperBandeSize()
const
305 for (
int irow = 0; irow < m_nrow; ++irow) {
307 for (
int k = m_row_offset[irow]; k < m_row_offset[irow + 1]; ++k) {
309 max_col = std::max(col, max_col);
311 bande_size = std::max(bande_size, max_col - irow);
316 Integer computeLowerBandeSize()
const
318 std::vector<int> maxRow(m_nrow);
319 for (
int col = 0; col < m_nrow; ++col)
321 for (
int irow = 0; irow < m_nrow; ++irow) {
322 for (
int k = m_row_offset[irow]; k < m_row_offset[irow + 1]; ++k) {
324 maxRow[col] = std::max(maxRow[col], irow);
328 for (
int col = 0; col < m_nrow; ++col)
329 bande_size = std::max(bande_size, maxRow[col]);
333 Integer computeMaxRowSize()
const
336 for (
int irow = 0; irow < m_nrow; ++irow)
337 m_max_row_size = std::max(m_max_row_size, m_row_offset[irow + 1] - m_row_offset[irow]);
338 return m_max_row_size;
341 Integer getMaxRowSize()
const
343 if (m_max_row_size == -1)
345 return m_max_row_size;
348 void copy(
const CSRStructInfo& profile)
350 auto nrows = profile.getNRows();
353 m_row_offset.copy(profile.getRowOffset());
357 m_cols.copy(profile.getCols());
359 if (m_is_variable_block) {
360 m_block_row_offset.copy(profile.getBlockRowOffset());
361 m_block_cols.copy(profile.getBlockCols());
364 m_col_ordering = profile.getColOrdering();
366 setDiagFirst(profile.getDiagFirstOpt());
368 m_upper_diag_offset.copy(profile.getUpperDiagOffset());
370 setSymmetric(profile.getSymmetric());
374 void computeSubProfile(ConstArrayView<Integer> parent_lid,
375 ConstArrayView<Integer> old2new_uid,
377 ConstArrayView<Integer> parent_kcol,
378 ConstArrayView<Integer> parent_cols,
379 ConstArrayView<Integer> filter,
380 ConstArrayView<Integer> new_offset,
383 m_nrow = new_offset[my_rank+1] - new_offset[my_rank] ;
384 m_row_offset.resize(m_nrow + 1) ;
385 m_row_offset[0] = 0 ;
388 for (Integer i = 0; i < parent_nrow; ++i)
392 m_row_offset[irow] = icount;
393 for (Integer k = parent_kcol[i]; k < parent_kcol[i + 1]; ++k)
395 if(filter[parent_cols[k]] == 1)
401 m_row_offset[irow] = icount ;
402 assert(irow == m_nrow);
404 m_cols.resize(icount);
405 for (Integer irow = 0; irow < m_nrow; ++irow)
407 Integer parent = parent_lid[irow];
408 Integer kstart = parent_kcol[parent];
409 Integer kend = parent_kcol[parent + 1];
411 for (Integer k = kstart; k < kend; ++k)
413 Integer col = parent_cols[k];
414 if (filter[col] == 1)
416 m_cols[m_row_offset[irow] + kcount] = old2new_uid[col];
420 assert(kcount == m_row_offset[irow + 1] - m_row_offset[irow]);
424 void computeSubProfile(ConstArrayView<Integer> parent_lid,
425 ConstArrayView<Integer> old2new_uid,
426 Integer parent_local_offset,
428 ConstArrayView<Integer> parent_kcol,
429 ConstArrayView<Integer> parent_cols,
430 ConstArrayView<Integer> parent_local_row_sizes,
431 ConstArrayView<Integer> filter,
432 ConstArrayView<Integer> new_offset,
435 m_nrow = new_offset[my_rank+1] - new_offset[my_rank] ;
436 m_row_offset.resize(m_nrow + 1) ;
437 m_row_offset[0] = 0 ;
440 for (Integer i = 0; i < parent_nrow; ++i)
444 m_row_offset[irow] = icount;
445 Integer kstart = parent_kcol[i];
446 Integer kend = parent_kcol[i + 1];
447 Integer local_row_size = parent_local_row_sizes[i];
449 for (Integer k = kstart; k < kstart + local_row_size; ++k)
451 if(filter[parent_cols[k]] == 1)
454 for (Integer k = kstart + local_row_size; k < kend; ++k)
456 if(filter[parent_cols[k]] == 1)
462 m_row_offset[irow] = icount ;
463 assert(irow == m_nrow);
465 m_cols.resize(icount);
466 for (Integer irow = 0; irow < m_nrow; ++irow)
468 Integer parent = parent_lid[irow];
469 Integer kstart = parent_kcol[parent];
470 Integer kend = parent_kcol[parent + 1];
471 Integer local_row_size = parent_local_row_sizes[parent];
473 for (Integer k = kstart; k < kstart + local_row_size; ++k)
475 Integer col = parent_cols[k];
476 if (filter[col] == 1)
478 m_cols[m_row_offset[irow] + kcount] = old2new_uid[col];
482 for (Integer k = kstart + local_row_size; k < kend; ++k)
484 Integer col = parent_cols[k];
485 if (filter[col] == 1)
487 m_cols[m_row_offset[irow] + kcount] = old2new_uid[col];
491 assert(kcount == m_row_offset[irow + 1] - m_row_offset[irow]);
497 bool m_is_variable_block =
false;
498 Arccore::Integer m_nrow = 0;
499 ColOrdering m_col_ordering = eUndef;
500 bool m_diag_first =
false;
501 mutable int m_max_row_size = -1;
502 bool m_symmetric =
true;
503 Arccore::Int64 m_timestamp = -1;
504 Arccore::UniqueArray<Arccore::Integer> m_row_offset;
505 Arccore::UniqueArray<Arccore::Integer> m_block_row_offset;
506 Arccore::UniqueArray<Arccore::Integer> m_cols;
507 Arccore::UniqueArray<Arccore::Integer> m_block_cols;
508 mutable Arccore::UniqueArray<Arccore::Integer> m_upper_diag_offset;
509#ifdef ALIEN_USE_PERF_TIMER
511 mutable TimerType m_timer;