15#include <alien/kernels/simple_csr/CSRStructInfo.h>
16#include <alien/kernels/simple_csr/SimpleCSRInternal.h>
17#include <alien/kernels/simple_csr/SimpleCSRMatrix.h>
19#include <alien/utils/ArrayUtils.h>
37 template <
typename ValueT,
typename MatrixImplT>
41 m_matrix_impl = &m_matrix.impl()->
template get<typename MatrixImplType::TagType>(
false);
43 const ISpace& space = m_matrix_impl->rowSpace();
45 if (space != m_matrix_impl->colSpace())
46 m_square_matrix =
false;
51 if (m_parallel_mng ==
nullptr) {
55 m_nproc = m_parallel_mng->commSize();
58 m_local_size = dist.localRowSize();
59 m_global_size = dist.globalRowSize();
61 if (!m_square_matrix) {
62 m_col_local_size = dist.localColSize();
63 m_col_global_size = dist.globalColSize();
64 m_col_local_offset = dist.colOffset();
72 template <
typename ValueT,
typename MatrixImplT>
73 MatrixProfilerT<ValueT,MatrixImplT>::~MatrixProfilerT()
82 template <
typename ValueT,
typename MatrixImplT>
83 void MatrixProfilerT<ValueT,MatrixImplT>::addMatrixEntry(Integer iIndex, Integer jIndex)
85 const Integer local_row = iIndex - m_local_offset;
89 std::vector<Integer>& row_def = m_def_matrix[local_row];
90 const Integer row_def_size =
static_cast<Integer
>(row_def.size());
91 if (row_def_size == 0)
92 row_def.push_back(jIndex);
95 jIndex, ConstArrayView<Integer>(row_def_size, &row_def[0]));
96 if (pos >= row_def_size)
97 row_def.push_back(jIndex);
98 else if (row_def[pos] != jIndex) {
99 row_def.insert(row_def.begin() + pos, jIndex);
106 template <
typename ValueT,
typename MatrixImplT>
107 void MatrixProfilerT<ValueT,MatrixImplT>::allocate()
113 m_matrix_impl->updateTimestamp();
120 template <
typename ValueT,
typename MatrixImplT>
121 void MatrixProfilerT<ValueT,MatrixImplT>::computeProfile()
123 UniqueArray<Integer> m_offset;
124 m_offset.resize(m_nproc + 1);
125 if (m_parallel_mng) {
126 Arccore::MessagePassing::mpAllGather(m_parallel_mng,
127 ConstArrayView<Integer>(1, &m_local_offset), m_offset.subView(0, m_nproc));
129 m_offset[m_nproc] = m_global_size;
131 auto& profile = m_matrix_impl->getCSRProfile();
132 profile.init(m_local_size);
135 ArrayView<Integer> row_offsets = profile.getRowOffset();
137 for (Integer i = 0; i < m_local_size; ++i) {
138 row_offsets[i] = offset;
139 offset +=
static_cast<Integer
>(m_def_matrix[i].size());
141 row_offsets[m_local_size] = offset;
146 ArrayView<Integer> cols = profile.getCols();
148 for (Integer i = 0, pos = 0; i < m_local_size; ++i) {
149 const VectorDefinition& vdef = m_def_matrix[i];
150 for (VectorDefinition::const_iterator iterJ = vdef.begin(); iterJ != vdef.end();
152 cols[pos++] = *iterJ;
156 if (m_matrix_impl->vblock()) {
157 const VBlock* block_sizes = m_matrix_impl->vblock();
158 auto& block_row_offset = profile.getBlockRowOffset();
159 auto& block_cols = profile.getBlockCols();
160 auto kcol = profile.kcol();
161 auto cols = profile.cols();
163 for (Integer irow = 0; irow < m_local_size; ++irow) {
164 block_row_offset[irow] = offset;
165 auto row_blk_size = block_sizes->size(m_local_offset + irow);
166 for (
auto k = kcol[irow]; k < kcol[irow + 1]; ++k) {
167 block_cols[k] = offset;
169 auto col_blk_size = block_sizes->size(jcol);
170 offset += row_blk_size * col_blk_size;
173 block_row_offset[m_local_size] = offset;
174 block_cols[kcol[m_local_size]] = offset;
177 m_matrix_impl->allocate();
178 m_matrix_impl->internal()->setValues(0) ;
183 m_matrix_impl->parallelStart(m_offset, m_parallel_mng,
true);
185 m_matrix_impl->sequentialStart();
187 profile.getColOrdering() = SimpleCSRInternal::CSRStructInfo::eFull;
189 profile.setTimestamp(m_matrix_impl->timestamp() + 1);
Integer m_local_offset
Global matrix informations.
MatrixDefinition m_def_matrix
MatrixProfilerT(IMatrix &matrix)
Scalar matrix builder.
Interface for all matrices.
Interface for algebraic space objects.
Computes a matrix distribution.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
Integer dichotomicPositionScan(const T &x, ConstArrayView< T > v)
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --