46 static const bool on_host_only = true ;
48 typedef ValueT ValueType;
53 typedef typename ProfileType::IndexType IndexType ;
62 , m_send_policy(SimpleCSRInternal::CommProperty::ASynch)
63 , m_recv_policy(SimpleCSRInternal::CommProperty::ASynch)
69 , m_matrix(multi_impl ? multi_impl->
vblock() != nullptr : false)
70 , m_send_policy(SimpleCSRInternal::CommProperty::ASynch)
71 , m_recv_policy(SimpleCSRInternal::CommProperty::ASynch)
77#ifdef ALIEN_USE_PERF_TIMER
78 m_timer.printInfo(
"SimpleCSR-MATRIX");
82 void setTraceMng(ITraceMng* trace_mng) { m_trace = trace_mng; }
97 m_matrix.getValues().resize((getCSRProfile().getNnz() + 1) * size * size);
100 m_matrix.getValues().resize(getCSRProfile().getBlockNnz() + 1);
103 m_matrix.getValues().resize(getCSRProfile().getNnz() + 1);
107 void scal(ValueType
const* values)
109 m_matrix.scal(values) ;
112 CSRStructInfo& getCSRProfile() {
return m_matrix.getCSRProfile(); }
114 const CSRStructInfo& getCSRProfile()
const {
return m_matrix.getCSRProfile(); }
116 const CSRStructInfo& getProfile()
const {
return m_matrix.getCSRProfile(); }
118 const DistStructInfo& getDistStructInfo()
const {
return m_matrix_dist_info; }
120 SimpleCSRInternal::CommProperty::ePolicyType getSendPolicy()
const
122 return m_send_policy;
125 SimpleCSRInternal::CommProperty::ePolicyType getRecvPolicy()
const
127 return m_recv_policy;
130 ValueType* getAddressData() {
return m_matrix.getDataPtr(); }
131 ValueType* data() {
return m_matrix.getDataPtr(); }
133 ValueType
const* getAddressData()
const {
return m_matrix.getDataPtr(); }
134 ValueType
const* data()
const {
return m_matrix.getDataPtr(); }
136 MatrixInternal* internal() {
return &m_matrix; }
138 MatrixInternal
const* internal()
const {
return &m_matrix; }
140 bool isParallel()
const {
return m_is_parallel; }
142 Integer getLocalSize()
const {
return m_local_size; }
144 Integer getLocalOffset()
const {
return m_local_offset; }
146 Integer getGlobalSize()
const {
return m_global_size; }
148 Integer getGhostSize()
const {
return m_ghost_size; }
150 Integer getAllocSize()
const
152 auto total_size = m_local_size + m_ghost_size;
156 return m_matrix_dist_info.m_block_offsets[total_size];
162 Integer blockSize()
const
172 return m_own_block_size ;
176 void setBlockSize(Integer block_size)
179 const_cast<MultiMatrixImpl*
>(this->
m_multi_impl)->setBlockInfos(block_size) ;
181 m_own_block_size = block_size ;
184 IMessagePassingMng* getParallelMng()
186 return m_parallel_mng;
189 void sequentialStart()
192 m_local_size = getCSRProfile().getNRows();
193 m_global_size = m_local_size;
196 m_is_parallel =
false;
197 m_matrix_dist_info.m_local_row_size.resize(m_local_size);
198 auto& profile = internal()->getCSRProfile();
199 ConstArrayView<Integer> offset = profile.getRowOffset();
200 for (Integer i = 0; i < m_local_size; ++i)
201 m_matrix_dist_info.m_local_row_size[i] = offset[i + 1] - offset[i];
204 void parallelStart(ConstArrayView<Integer> offset, IMessagePassingMng* parallel_mng,
205 bool need_sort_ghost_col =
false)
207 m_local_size = getCSRProfile().getNRows();
208 m_parallel_mng = parallel_mng;
210 if (m_parallel_mng == NULL) {
212 m_global_size = m_local_size;
215 m_is_parallel =
false;
218 m_myrank = m_parallel_mng->commRank();
219 m_nproc = m_parallel_mng->commSize();
220 m_local_offset = offset[m_myrank];
221 m_global_size = offset[m_nproc];
222 m_is_parallel = (m_nproc > 1);
225 if (need_sort_ghost_col)
226 sortGhostCols(offset);
228 m_matrix_dist_info.compute(
229 m_nproc, offset, m_myrank, m_parallel_mng, getCSRProfile(), m_trace);
232 m_matrix_dist_info.compute(m_nproc, offset, m_myrank, m_parallel_mng,
236 m_matrix_dist_info.compute(
237 m_nproc, offset, m_myrank, m_parallel_mng, getCSRProfile(), m_trace);
239 m_ghost_size = m_matrix_dist_info.m_ghost_nrow;
243 void sortGhostCols(ConstArrayView<Integer> offset)
245 IsLocal isLocal(offset, m_myrank);
246 UniqueArray<ValueType>& values = m_matrix.getValues();
247 ProfileType& profile = m_matrix.getCSRProfile();
248 UniqueArray<Integer>& cols = profile.getCols();
249 ConstArrayView<Integer> kcol = profile.getRowOffset();
251 UniqueArray<Integer> gcols;
252 UniqueArray<ValueType> gvalues;
253 for (Integer irow = 0; irow < m_local_size; ++irow) {
254 bool need_sort =
false;
255 Integer first = next;
256 next = kcol[irow + 1];
257 Integer row_size = next - first;
258 for (Integer k = first; k < next; ++k) {
259 if (!isLocal(cols[k])) {
265 gvalues.resize(row_size);
266 gcols.resize(row_size);
267 Integer local_count = 0;
268 Integer ghost_count = 0;
269 for (Integer k = first; k < next; ++k) {
270 Integer col = cols[k];
272 cols[first + local_count] = col;
273 values[first + local_count] = values[k];
277 gcols[ghost_count] = col;
278 gvalues[ghost_count] = values[k];
282 for (Integer k = 0; k < ghost_count; ++k) {
283 cols[first + local_count] = gcols[k];
284 values[first + local_count] = gvalues[k];
298 matrix->m_is_parallel = m_is_parallel;
299 matrix->m_local_size = m_local_size;
300 matrix->m_local_offset = m_local_offset;
301 matrix->m_global_size = m_global_size;
302 matrix->m_ghost_size = m_ghost_size;
303 matrix->m_send_policy = m_send_policy;
304 matrix->m_recv_policy = m_recv_policy;
305 matrix->m_nproc = m_nproc;
306 matrix->m_myrank = m_myrank;
307 matrix->m_parallel_mng = m_parallel_mng;
308 matrix->m_trace = m_trace;
309 matrix->setBlockSize(blockSize()) ;
310 matrix->m_matrix.copy(m_matrix);
311 matrix->m_matrix_dist_info.copy(m_matrix_dist_info);
317 m_is_parallel = matrix.m_is_parallel;
318 m_local_size = matrix.m_local_size;
319 m_local_offset = matrix.m_local_offset;
320 m_global_size = matrix.m_global_size;
321 m_ghost_size = matrix.m_ghost_size;
322 m_send_policy = matrix.m_send_policy;
323 m_recv_policy = matrix.m_recv_policy;
324 m_nproc = matrix.m_nproc;
325 m_myrank = matrix.m_myrank;
326 m_parallel_mng = matrix.m_parallel_mng;
327 m_trace = matrix.m_trace;
328 if(blockSize()==matrix.blockSize())
329 m_matrix.copy(matrix.m_matrix);
332 auto nb_blocks = matrix.getCSRProfile().getNnz() + 1 ;
333 m_matrix.copy(matrix.m_matrix,blockSize(),matrix.blockSize(),nb_blocks) ;
335 m_matrix_dist_info.copy(matrix.m_matrix_dist_info);
340 m_is_parallel = matrix.m_is_parallel;
341 m_local_size = matrix.m_local_size;
342 m_local_offset = matrix.m_local_offset;
343 m_global_size = matrix.m_global_size;
344 m_ghost_size = matrix.m_ghost_size;
345 m_send_policy = matrix.m_send_policy;
346 m_recv_policy = matrix.m_recv_policy;
347 m_nproc = matrix.m_nproc;
348 m_myrank = matrix.m_myrank;
349 m_parallel_mng = matrix.m_parallel_mng;
350 m_trace = matrix.m_trace;
351 m_matrix.getCSRProfile().copy(matrix.m_matrix.getCSRProfile());
352 m_matrix_dist_info.copy(matrix.m_matrix_dist_info);
354 auto& profile = m_matrix.getCSRProfile();
355 const VBlock* block_sizes =
vblock();
356 auto& block_row_offset = profile.getBlockRowOffset();
357 auto& block_cols = profile.getBlockCols();
358 auto kcol = profile.kcol();
359 auto cols = profile.cols();
361 for (Integer irow = 0; irow < m_local_size; ++irow) {
362 block_row_offset[irow] = offset;
363 auto row_blk_size = block_sizes->size(m_local_offset + irow);
364 for (
auto k = kcol[irow]; k < kcol[irow + 1]; ++k) {
365 block_cols[k] = offset;
367 auto col_blk_size = block_sizes->size(jcol);
368 offset += row_blk_size * col_blk_size;
371 block_row_offset[m_local_size] = offset;
372 block_cols[kcol[m_local_size]] = offset;
374 const Integer total_size = m_local_size + m_ghost_size;
376 m_matrix_dist_info.m_block_sizes.resize(total_size);
377 m_matrix_dist_info.m_block_offsets.resize(total_size + 1);
380 for (Integer i = 0; i < m_local_size; ++i) {
381 auto blk_size = block_sizes->size(m_local_offset + i);
382 m_matrix_dist_info.m_block_sizes[i] = blk_size;
383 m_matrix_dist_info.m_block_offsets[i] = offset;
386 for (Integer i = m_local_size; i < total_size; ++i) {
387 auto blk_size = block_sizes->size(m_matrix_dist_info.m_recv_info.m_uids[i - m_local_size]);
388 m_matrix_dist_info.m_block_sizes[i] = blk_size;
389 m_matrix_dist_info.m_block_offsets[i] = offset;
392 m_matrix_dist_info.m_block_offsets[total_size] = offset;
398 m_matrix.notifyChanges();
403 if (m_matrix.needUpdate()) {
404 m_matrix.endUpdate();
413 IsLocal(
const ConstArrayView<Integer> offset,
const Integer myrank)
417 bool operator()(Arccore::Integer col)
const
419 return (col >= m_offset[m_myrank]) && (col < m_offset[m_myrank + 1]);
423 const ConstArrayView<Integer> m_offset;
424 const Integer m_myrank;
427 MatrixInternal m_matrix;
428 bool m_is_parallel = 0;
429 Integer m_local_size = 0;
430 Integer m_local_offset = 0;
431 Integer m_global_size = 0;
432 Integer m_ghost_size = 0;
433 DistStructInfo m_matrix_dist_info;
434 SimpleCSRInternal::CommProperty::ePolicyType m_send_policy;
435 SimpleCSRInternal::CommProperty::ePolicyType m_recv_policy;
436 IMessagePassingMng* m_parallel_mng =
nullptr;
437 Integer m_own_block_size = 1;
439 Integer m_myrank = 0;
440 ITraceMng* m_trace =
nullptr;
445 mutable TimerType m_timer;
448 TimerType& timer()
const