Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/dd/d65/MatrixCSR_8h_source.html
DOLFINx 0.8.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
MatrixCSR.h
1// Copyright (C) 2021-2022 Garth N. Wells and Chris N. Richardson
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "SparsityPattern.h"
10#include "matrix_csr_impl.h"
11#include <dolfinx/common/IndexMap.h>
12#include <dolfinx/common/MPI.h>
13#include <dolfinx/graph/AdjacencyList.h>
14#include <mpi.h>
15#include <numeric>
16#include <span>
17#include <utility>
18#include <vector>
19
20namespace dolfinx::la
21{
23enum class BlockMode : int
24{
25 compact = 0,
27 expanded = 1
30};
31
46template <class Scalar, class Container = std::vector<Scalar>,
47 class ColContainer = std::vector<std::int32_t>,
48 class RowPtrContainer = std::vector<std::int64_t>>
50{
51 static_assert(std::is_same_v<typename Container::value_type, Scalar>);
52
53public:
55 using value_type = Scalar;
56
58 using container_type = Container;
59
61 using column_container_type = ColContainer;
62
64 using rowptr_container_type = RowPtrContainer;
65
66 static_assert(std::is_same_v<value_type, typename container_type::value_type>,
67 "Scalar type and container value type must be the same.");
68
91 template <int BS0 = 1, int BS1 = 1>
93 {
94 if ((BS0 != _bs[0] and BS0 > 1 and _bs[0] > 1)
95 or (BS1 != _bs[1] and BS1 > 1 and _bs[1] > 1))
96 {
97 throw std::runtime_error(
98 "Cannot insert blocks of different size than matrix block size");
99 }
100
101 return [&](std::span<const std::int32_t> rows,
102 std::span<const std::int32_t> cols,
103 std::span<const value_type> data) -> int
104 {
105 this->set<BS0, BS1>(data, rows, cols);
106 return 0;
107 };
108 }
109
132 template <int BS0 = 1, int BS1 = 1>
134 {
135 if ((BS0 != _bs[0] and BS0 > 1 and _bs[0] > 1)
136 or (BS1 != _bs[1] and BS1 > 1 and _bs[1] > 1))
137 {
138 throw std::runtime_error(
139 "Cannot insert blocks of different size than matrix block size");
140 }
141
142 return [&](std::span<const std::int32_t> rows,
143 std::span<const std::int32_t> cols,
144 std::span<const value_type> data) -> int
145 {
146 this->add<BS0, BS1>(data, rows, cols);
147 return 0;
148 };
149 }
150
176 MatrixCSR(const SparsityPattern& p, BlockMode mode = BlockMode::compact);
177
180 MatrixCSR(MatrixCSR&& A) = default;
181
185 void set(value_type x) { std::fill(_data.begin(), _data.end(), x); }
186
201 template <int BS0, int BS1>
202 void set(std::span<const value_type> x, std::span<const std::int32_t> rows,
203 std::span<const std::int32_t> cols)
204 {
205 auto set_fn = [](value_type& y, const value_type& x) { y = x; };
206
207 std::int32_t num_rows
208 = _index_maps[0]->size_local() + _index_maps[0]->num_ghosts();
209 assert(x.size() == rows.size() * cols.size() * BS0 * BS1);
210 if (_bs[0] == BS0 and _bs[1] == BS1)
211 {
212 impl::insert_csr<BS0, BS1>(_data, _cols, _row_ptr, x, rows, cols, set_fn,
213 num_rows);
214 }
215 else if (_bs[0] == 1 and _bs[1] == 1)
216 {
217 // Set blocked data in a regular CSR matrix (_bs[0]=1, _bs[1]=1) with
218 // correct sparsity
219 impl::insert_blocked_csr<BS0, BS1>(_data, _cols, _row_ptr, x, rows, cols,
220 set_fn, num_rows);
221 }
222 else
223 {
224 assert(BS0 == 1 and BS1 == 1);
225 // Set non-blocked data in a blocked CSR matrix (BS0=1, BS1=1)
226 impl::insert_nonblocked_csr(_data, _cols, _row_ptr, x, rows, cols, set_fn,
227 num_rows, _bs[0], _bs[1]);
228 }
229 }
230
246 template <int BS0 = 1, int BS1 = 1>
247 void add(std::span<const value_type> x, std::span<const std::int32_t> rows,
248 std::span<const std::int32_t> cols)
249 {
250 auto add_fn = [](value_type& y, const value_type& x) { y += x; };
251
252 assert(x.size() == rows.size() * cols.size() * BS0 * BS1);
253 if (_bs[0] == BS0 and _bs[1] == BS1)
254 {
255 impl::insert_csr<BS0, BS1>(_data, _cols, _row_ptr, x, rows, cols, add_fn,
256 _row_ptr.size());
257 }
258 else if (_bs[0] == 1 and _bs[1] == 1)
259 {
260 // Add blocked data to a regular CSR matrix (_bs[0]=1, _bs[1]=1)
261 impl::insert_blocked_csr<BS0, BS1>(_data, _cols, _row_ptr, x, rows, cols,
262 add_fn, _row_ptr.size());
263 }
264 else
265 {
266 assert(BS0 == 1 and BS1 == 1);
267 // Add non-blocked data to a blocked CSR matrix (BS0=1, BS1=1)
268 impl::insert_nonblocked_csr(_data, _cols, _row_ptr, x, rows, cols, add_fn,
269 _row_ptr.size(), _bs[0], _bs[1]);
270 }
271 }
272
274 std::int32_t num_owned_rows() const { return _index_maps[0]->size_local(); }
275
277 std::int32_t num_all_rows() const { return _row_ptr.size() - 1; }
278
287 std::vector<value_type> to_dense() const;
288
294 {
297 }
298
306 void scatter_rev_begin();
307
313 void scatter_rev_end();
314
317 double squared_norm() const;
318
326 std::shared_ptr<const common::IndexMap> index_map(int dim) const
327 {
328 return _index_maps.at(dim);
329 }
330
333 container_type& values() { return _data; }
334
337 const container_type& values() const { return _data; }
338
341 const rowptr_container_type& row_ptr() const { return _row_ptr; }
342
345 const column_container_type& cols() const { return _cols; }
346
355 {
356 return _off_diagonal_offset;
357 }
358
361 std::array<int, 2> block_size() const { return _bs; }
362
363private:
364 // Maps for the distribution of the ows and columns
365 std::array<std::shared_ptr<const common::IndexMap>, 2> _index_maps;
366
367 // Block mode (compact or expanded)
368 BlockMode _block_mode;
369
370 // Block sizes
371 std::array<int, 2> _bs;
372
373 // Matrix data
374 container_type _data;
376 rowptr_container_type _row_ptr;
377
378 // Start of off-diagonal (unowned columns) on each row
379 rowptr_container_type _off_diagonal_offset;
380
381 // Neighborhood communicator (ghost->owner communicator for rows)
382 dolfinx::MPI::Comm _comm;
383
384 // -- Precomputed data for scatter_rev/update
385
386 // Request in non-blocking communication
387 MPI_Request _request;
388
389 // Position in _data to add received data
390 std::vector<int> _unpack_pos;
391
392 // Displacements for alltoall for each neighbor when sending and
393 // receiving
394 std::vector<int> _val_send_disp, _val_recv_disp;
395
396 // Ownership of each row, by neighbor (for the neighbourhood defined
397 // on _comm)
398 std::vector<int> _ghost_row_to_rank;
399
400 // Temporary stores for data during non-blocking communication
401 container_type _ghost_value_data;
402 container_type _ghost_value_data_in;
403};
404//-----------------------------------------------------------------------------
405template <class U, class V, class W, class X>
407 : _index_maps({p.index_map(0),
408 std::make_shared<common::IndexMap>(p.column_index_map())}),
409 _block_mode(mode), _bs({p.block_size(0), p.block_size(1)}),
410 _data(p.num_nonzeros() * _bs[0] * _bs[1], 0),
411 _cols(p.graph().first.begin(), p.graph().first.end()),
412 _row_ptr(p.graph().second.begin(), p.graph().second.end()),
413 _comm(MPI_COMM_NULL)
414{
415 if (_block_mode == BlockMode::expanded)
416 {
417 // Rebuild IndexMaps
418 for (int i = 0; i < 2; ++i)
419 {
420 const auto im = _index_maps[i];
421 const int size_local = im->size_local() * _bs[i];
422 std::span ghost_i = im->ghosts();
423 std::vector<std::int64_t> ghosts;
424 const std::vector<int> ghost_owner_i(im->owners().begin(),
425 im->owners().end());
426 std::vector<int> src_rank;
427 for (std::size_t j = 0; j < ghost_i.size(); ++j)
428 {
429 for (int k = 0; k < _bs[i]; ++k)
430 {
431 ghosts.push_back(ghost_i[j] * _bs[i] + k);
432 src_rank.push_back(ghost_owner_i[j]);
433 }
434 }
435 const std::array<std::vector<int>, 2> src_dest0
436 = {std::vector(_index_maps[i]->src().begin(),
437 _index_maps[i]->src().end()),
438 std::vector(_index_maps[i]->dest().begin(),
439 _index_maps[i]->dest().end())};
440 _index_maps[i] = std::make_shared<common::IndexMap>(
441 _index_maps[i]->comm(), size_local, src_dest0, ghosts, src_rank);
442 }
443
444 // Convert sparsity pattern and set _bs to 1
445
446 column_container_type new_cols;
447 new_cols.reserve(_data.size());
448 rowptr_container_type new_row_ptr = {0};
449 new_row_ptr.reserve(_row_ptr.size() * _bs[0]);
450 std::span<const std::int32_t> num_diag_nnz = p.off_diagonal_offsets();
451 for (std::size_t i = 0; i < _row_ptr.size() - 1; ++i)
452 {
453 // Repeat row _bs[0] times
454 for (int q0 = 0; q0 < _bs[0]; ++q0)
455 {
456 _off_diagonal_offset.push_back(new_row_ptr.back()
457 + num_diag_nnz[i] * _bs[1]);
458 for (auto j = _row_ptr[i]; j < _row_ptr[i + 1]; ++j)
459 {
460 for (int q1 = 0; q1 < _bs[1]; ++q1)
461 new_cols.push_back(_cols[j] * _bs[1] + q1);
462 }
463 new_row_ptr.push_back(new_cols.size());
464 }
465 }
466 _cols = new_cols;
467 _row_ptr = new_row_ptr;
468 _bs[0] = 1;
469 _bs[1] = 1;
470 }
471 else
472 {
473 // Compute off-diagonal offset for each row (compact)
474 std::span<const std::int32_t> num_diag_nnz = p.off_diagonal_offsets();
475 _off_diagonal_offset.reserve(num_diag_nnz.size());
476 std::transform(num_diag_nnz.begin(), num_diag_nnz.end(), _row_ptr.begin(),
477 std::back_inserter(_off_diagonal_offset), std::plus{});
478 }
479
480 // Some short-hand
481 const std::array local_size
482 = {_index_maps[0]->size_local(), _index_maps[1]->size_local()};
483 const std::array local_range
484 = {_index_maps[0]->local_range(), _index_maps[1]->local_range()};
485 std::span ghosts1 = _index_maps[1]->ghosts();
486
487 std::span ghosts0 = _index_maps[0]->ghosts();
488 std::span src_ranks = _index_maps[0]->src();
489 std::span dest_ranks = _index_maps[0]->dest();
490
491 // Create neighbourhood communicator (owner <- ghost)
492 MPI_Comm comm;
493 MPI_Dist_graph_create_adjacent(_index_maps[0]->comm(), dest_ranks.size(),
494 dest_ranks.data(), MPI_UNWEIGHTED,
495 src_ranks.size(), src_ranks.data(),
496 MPI_UNWEIGHTED, MPI_INFO_NULL, false, &comm);
497 _comm = dolfinx::MPI::Comm(comm, false);
498
499 // Build map from ghost row index position to owning (neighborhood)
500 // rank
501 _ghost_row_to_rank.reserve(_index_maps[0]->owners().size());
502 for (int r : _index_maps[0]->owners())
503 {
504 auto it = std::lower_bound(src_ranks.begin(), src_ranks.end(), r);
505 assert(it != src_ranks.end() and *it == r);
506 int pos = std::distance(src_ranks.begin(), it);
507 _ghost_row_to_rank.push_back(pos);
508 }
509
510 // Compute size of data to send to each neighbor
511 std::vector<std::int32_t> data_per_proc(src_ranks.size(), 0);
512 for (std::size_t i = 0; i < _ghost_row_to_rank.size(); ++i)
513 {
514 assert(_ghost_row_to_rank[i] < data_per_proc.size());
515 std::size_t pos = local_size[0] + i;
516 data_per_proc[_ghost_row_to_rank[i]] += _row_ptr[pos + 1] - _row_ptr[pos];
517 }
518
519 // Compute send displacements
520 _val_send_disp.resize(src_ranks.size() + 1, 0);
521 std::partial_sum(data_per_proc.begin(), data_per_proc.end(),
522 std::next(_val_send_disp.begin()));
523
524 // For each ghost row, pack and send indices to neighborhood
525 std::vector<std::int64_t> ghost_index_data(2 * _val_send_disp.back());
526 {
527 std::vector<int> insert_pos = _val_send_disp;
528 for (std::size_t i = 0; i < _ghost_row_to_rank.size(); ++i)
529 {
530 const int rank = _ghost_row_to_rank[i];
531 int row_id = local_size[0] + i;
532 for (int j = _row_ptr[row_id]; j < _row_ptr[row_id + 1]; ++j)
533 {
534 // Get position in send buffer
535 const std::int32_t idx_pos = 2 * insert_pos[rank];
536
537 // Pack send data (row, col) as global indices
538 ghost_index_data[idx_pos] = ghosts0[i];
539 if (std::int32_t col_local = _cols[j]; col_local < local_size[1])
540 ghost_index_data[idx_pos + 1] = col_local + local_range[1][0];
541 else
542 ghost_index_data[idx_pos + 1] = ghosts1[col_local - local_size[1]];
543
544 insert_pos[rank] += 1;
545 }
546 }
547 }
548
549 // Communicate data with neighborhood
550 std::vector<std::int64_t> ghost_index_array;
551 std::vector<int> recv_disp;
552 {
553 std::vector<int> send_sizes;
554 std::transform(data_per_proc.begin(), data_per_proc.end(),
555 std::back_inserter(send_sizes),
556 [](auto x) { return 2 * x; });
557
558 std::vector<int> recv_sizes(dest_ranks.size());
559 send_sizes.reserve(1);
560 recv_sizes.reserve(1);
561 MPI_Neighbor_alltoall(send_sizes.data(), 1, MPI_INT, recv_sizes.data(), 1,
562 MPI_INT, _comm.comm());
563
564 // Build send/recv displacement
565 std::vector<int> send_disp = {0};
566 std::partial_sum(send_sizes.begin(), send_sizes.end(),
567 std::back_inserter(send_disp));
568 recv_disp = {0};
569 std::partial_sum(recv_sizes.begin(), recv_sizes.end(),
570 std::back_inserter(recv_disp));
571
572 ghost_index_array.resize(recv_disp.back());
573 MPI_Neighbor_alltoallv(ghost_index_data.data(), send_sizes.data(),
574 send_disp.data(), MPI_INT64_T,
575 ghost_index_array.data(), recv_sizes.data(),
576 recv_disp.data(), MPI_INT64_T, _comm.comm());
577 }
578
579 // Store receive displacements for future use, when transferring
580 // data values
581 _val_recv_disp.resize(recv_disp.size());
582 const int bs2 = _bs[0] * _bs[1];
583 std::transform(recv_disp.begin(), recv_disp.end(), _val_recv_disp.begin(),
584 [&bs2](auto d) { return bs2 * d / 2; });
585 std::transform(_val_send_disp.begin(), _val_send_disp.end(),
586 _val_send_disp.begin(), [&bs2](auto d) { return d * bs2; });
587
588 // Global-to-local map for ghost columns
589 std::vector<std::pair<std::int64_t, std::int32_t>> global_to_local;
590 global_to_local.reserve(ghosts1.size());
591 for (std::int64_t idx : ghosts1)
592 global_to_local.push_back({idx, global_to_local.size() + local_size[1]});
593 std::sort(global_to_local.begin(), global_to_local.end());
594
595 // Compute location in which data for each index should be stored
596 // when received
597 for (std::size_t i = 0; i < ghost_index_array.size(); i += 2)
598 {
599 // Row must be on this process
600 const std::int32_t local_row = ghost_index_array[i] - local_range[0][0];
601 assert(local_row >= 0 and local_row < local_size[0]);
602
603 // Column may be owned or unowned
604 std::int32_t local_col = ghost_index_array[i + 1] - local_range[1][0];
605 if (local_col < 0 or local_col >= local_size[1])
606 {
607 auto it = std::lower_bound(global_to_local.begin(), global_to_local.end(),
608 std::pair(ghost_index_array[i + 1], -1),
609 [](auto& a, auto& b)
610 { return a.first < b.first; });
611 assert(it != global_to_local.end()
612 and it->first == ghost_index_array[i + 1]);
613 local_col = it->second;
614 }
615 auto cit0 = std::next(_cols.begin(), _row_ptr[local_row]);
616 auto cit1 = std::next(_cols.begin(), _row_ptr[local_row + 1]);
617
618 // Find position of column index and insert data
619 auto cit = std::lower_bound(cit0, cit1, local_col);
620 assert(cit != cit1);
621 assert(*cit == local_col);
622 std::size_t d = std::distance(_cols.begin(), cit);
623 _unpack_pos.push_back(d);
624 }
625}
626//-----------------------------------------------------------------------------
627template <typename U, typename V, typename W, typename X>
628std::vector<typename MatrixCSR<U, V, W, X>::value_type>
630{
631 const std::size_t nrows = num_all_rows();
632 const std::size_t ncols
633 = _index_maps[1]->size_local() + _index_maps[1]->num_ghosts();
634 std::vector<value_type> A(nrows * ncols * _bs[0] * _bs[1], 0.0);
635 for (std::size_t r = 0; r < nrows; ++r)
636 for (std::int32_t j = _row_ptr[r]; j < _row_ptr[r + 1]; ++j)
637 for (int i0 = 0; i0 < _bs[0]; ++i0)
638 for (int i1 = 0; i1 < _bs[1]; ++i1)
639 {
640 A[(r * _bs[1] + i0) * ncols * _bs[0] + _cols[j] * _bs[1] + i1]
641 = _data[j * _bs[0] * _bs[1] + i0 * _bs[1] + i1];
642 }
643
644 return A;
645}
646//-----------------------------------------------------------------------------
647template <typename U, typename V, typename W, typename X>
649{
650 const std::int32_t local_size0 = _index_maps[0]->size_local();
651 const std::int32_t num_ghosts0 = _index_maps[0]->num_ghosts();
652 const int bs2 = _bs[0] * _bs[1];
653
654 // For each ghost row, pack and send values to send to neighborhood
655 std::vector<int> insert_pos = _val_send_disp;
656 _ghost_value_data.resize(_val_send_disp.back());
657 for (int i = 0; i < num_ghosts0; ++i)
658 {
659 const int rank = _ghost_row_to_rank[i];
660
661 // Get position in send buffer to place data to send to this
662 // neighbour
663 const std::int32_t val_pos = insert_pos[rank];
664 std::copy(std::next(_data.data(), _row_ptr[local_size0 + i] * bs2),
665 std::next(_data.data(), _row_ptr[local_size0 + i + 1] * bs2),
666 std::next(_ghost_value_data.begin(), val_pos));
667 insert_pos[rank]
668 += bs2 * (_row_ptr[local_size0 + i + 1] - _row_ptr[local_size0 + i]);
669 }
670
671 _ghost_value_data_in.resize(_val_recv_disp.back());
672
673 // Compute data sizes for send and receive from displacements
674 std::vector<int> val_send_count(_val_send_disp.size() - 1);
675 std::adjacent_difference(std::next(_val_send_disp.begin()),
676 _val_send_disp.end(), val_send_count.begin());
677
678 std::vector<int> val_recv_count(_val_recv_disp.size() - 1);
679 std::adjacent_difference(std::next(_val_recv_disp.begin()),
680 _val_recv_disp.end(), val_recv_count.begin());
681
682 int status = MPI_Ineighbor_alltoallv(
683 _ghost_value_data.data(), val_send_count.data(), _val_send_disp.data(),
684 dolfinx::MPI::mpi_type<value_type>(), _ghost_value_data_in.data(),
685 val_recv_count.data(), _val_recv_disp.data(),
686 dolfinx::MPI::mpi_type<value_type>(), _comm.comm(), &_request);
687 assert(status == MPI_SUCCESS);
688}
689//-----------------------------------------------------------------------------
690template <typename U, typename V, typename W, typename X>
692{
693 int status = MPI_Wait(&_request, MPI_STATUS_IGNORE);
694 assert(status == MPI_SUCCESS);
695
696 _ghost_value_data.clear();
697 _ghost_value_data.shrink_to_fit();
698
699 // Add to local rows
700 const int bs2 = _bs[0] * _bs[1];
701 assert(_ghost_value_data_in.size() == _unpack_pos.size() * bs2);
702 for (std::size_t i = 0; i < _unpack_pos.size(); ++i)
703 for (int j = 0; j < bs2; ++j)
704 _data[_unpack_pos[i] * bs2 + j] += _ghost_value_data_in[i * bs2 + j];
705
706 _ghost_value_data_in.clear();
707 _ghost_value_data_in.shrink_to_fit();
708
709 // Set ghost row data to zero
710 const std::int32_t local_size0 = _index_maps[0]->size_local();
711 std::fill(std::next(_data.begin(), _row_ptr[local_size0] * bs2), _data.end(),
712 0);
713}
714//-----------------------------------------------------------------------------
715template <typename U, typename V, typename W, typename X>
717{
718 const std::size_t num_owned_rows = _index_maps[0]->size_local();
719 const int bs2 = _bs[0] * _bs[1];
720 assert(num_owned_rows < _row_ptr.size());
721 double norm_sq_local = std::accumulate(
722 _data.cbegin(), std::next(_data.cbegin(), _row_ptr[num_owned_rows] * bs2),
723 double(0), [](auto norm, value_type y) { return norm + std::norm(y); });
724 double norm_sq;
725 MPI_Allreduce(&norm_sq_local, &norm_sq, 1, MPI_DOUBLE, MPI_SUM, _comm.comm());
726 return norm_sq;
727}
728//-----------------------------------------------------------------------------
729
730} // namespace dolfinx::la
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Definition MatrixCSR.h:50
const container_type & values() const
Definition MatrixCSR.h:337
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Index maps for the row and column space.
Definition MatrixCSR.h:326
const rowptr_container_type & off_diag_offset() const
Definition MatrixCSR.h:354
void set(std::span< const value_type > x, std::span< const std::int32_t > rows, std::span< const std::int32_t > cols)
Set values in the matrix.
Definition MatrixCSR.h:202
RowPtrContainer rowptr_container_type
Row pointer container type.
Definition MatrixCSR.h:64
void scatter_rev_end()
End transfer of ghost row data to owning ranks.
Definition MatrixCSR.h:691
container_type & values()
Definition MatrixCSR.h:333
auto mat_add_values()
Insertion functor for adding values to a matrix. It is typically used in finite element assembly func...
Definition MatrixCSR.h:133
std::vector< value_type > to_dense() const
Definition MatrixCSR.h:629
void add(std::span< const value_type > x, std::span< const std::int32_t > rows, std::span< const std::int32_t > cols)
Accumulate values in the matrix.
Definition MatrixCSR.h:247
std::int32_t num_owned_rows() const
Number of local rows excluding ghost rows.
Definition MatrixCSR.h:274
MatrixCSR(const SparsityPattern &p, BlockMode mode=BlockMode::compact)
Create a distributed matrix.
Definition MatrixCSR.h:406
ColContainer column_container_type
Column index container type.
Definition MatrixCSR.h:61
MatrixCSR(MatrixCSR &&A)=default
double squared_norm() const
Compute the Frobenius norm squared across all processes.
Definition MatrixCSR.h:716
void scatter_rev()
Transfer ghost row data to the owning ranks accumulating received values on the owned rows,...
Definition MatrixCSR.h:293
Container container_type
Matrix entries container type.
Definition MatrixCSR.h:58
Scalar value_type
Scalar type.
Definition MatrixCSR.h:55
void scatter_rev_begin()
Begin transfer of ghost row data to owning ranks, where it will be accumulated into existing owned ro...
Definition MatrixCSR.h:648
const column_container_type & cols() const
Definition MatrixCSR.h:345
void set(value_type x)
Set all non-zero local entries to a value including entries in ghost rows.
Definition MatrixCSR.h:185
std::array< int, 2 > block_size() const
Definition MatrixCSR.h:361
std::int32_t num_all_rows() const
Number of local rows including ghost rows.
Definition MatrixCSR.h:277
const rowptr_container_type & row_ptr() const
Definition MatrixCSR.h:341
auto mat_set_values()
Insertion functor for setting values in a matrix. It is typically used in finite element assembly fun...
Definition MatrixCSR.h:92
Definition SparsityPattern.h:26
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Index map for given dimension dimension. Returns the index map for rows and columns that will be set ...
Definition SparsityPattern.cpp:193
common::IndexMap column_index_map() const
Builds the index map for columns after assembly of the sparsity pattern.
Definition SparsityPattern.cpp:213
int size(MPI_Comm comm)
Definition MPI.cpp:72
int rank(MPI_Comm comm)
Return process rank for the communicator.
Definition MPI.cpp:64
constexpr std::array< std::int64_t, 2 > local_range(int rank, std::int64_t N, int size)
Return local range for the calling process, partitioning the global [0, N - 1] range across all ranks...
Definition MPI.h:91
Linear algebra interface.
Definition sparsitybuild.h:15
BlockMode
Modes for representing block structured matrices.
Definition MatrixCSR.h:24
auto norm(const V &x, Norm type=Norm::l2)
Definition Vector.h:267