deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
psblas_sparsity_pattern.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
18
20
21#include <psb_c_base.h>
22
23
24#ifdef DEAL_II_WITH_PSBLAS
26
28
29namespace PSCToolkitWrappers
30{
31 // SparsityPattern
33 const MPI_Comm communicator)
34 {
35 SparsityPatternBase::resize(index_set.size(), index_set.size());
36
37 Assert(communicator != MPI_COMM_NULL,
38 ExcMessage("MPI_COMM_NULL passed to SparseMatrix::reinit()."));
39
40 psblas_descriptor.reset(psb_c_new_descriptor(),
41 PSCToolkitWrappers::internal::DescriptorDeleter());
42
43 // Use get_index_vector() from IndexSet to get the indexes
44 const std::vector<types::global_dof_index> &indexes =
45 index_set.get_index_vector();
46
47 psb_i_t number_of_local_indexes = indexes.size(); // Number of local indexes
48 // Copy the indexes into a psb_l_t vector
49 std::vector<psb_l_t> vl(number_of_local_indexes);
50 for (psb_i_t i = 0; i < number_of_local_indexes; ++i)
51 {
52 const auto psblas_index = static_cast<psb_l_t>(indexes[i]);
53 AssertIntegerConversion(psblas_index, indexes[i]);
54 vl[i] = psblas_index;
55 }
56
57 // Insert the indexes into the descriptor
58 psb_c_cdall_vl(number_of_local_indexes,
59 vl.data(),
60 *InitFinalize::get_psblas_context(),
61 psblas_descriptor.get());
62 }
63
64
65
66 void
67 SparsityPattern::add(const PSCToolkitWrappers::SparsityPattern::size_type i,
68 const PSCToolkitWrappers::SparsityPattern::size_type j)
69 {
70 add_entries(i, &j, &j + 1);
71 }
72
73
74
75 template <typename ForwardIterator>
76 void
78 const PSCToolkitWrappers::SparsityPattern::size_type row,
79 ForwardIterator begin,
80 ForwardIterator end,
81 const bool indices_are_sorted)
82 {
83 Assert(psblas_descriptor.get() != nullptr,
84 ExcMessage("PSBLAS descriptor is null."));
85 if (begin == end)
86 return;
87
88 (void)indices_are_sorted;
89 psb_i_t nz = static_cast<int>(end - begin);
90 std::vector<psb_l_t> ia(nz);
91 std::vector<psb_l_t> ja(nz);
92
93 for (int k = 0; k < nz; ++k)
94 {
95 ia[k] = row; // row index
96 ja[k] = *(begin + k); // column index
97 }
98 int err = psb_c_cdins(nz, ia.data(), ja.data(), psblas_descriptor.get());
99 Assert(err == 0, ExcInsertionInPSBLASMatrix(err));
100 }
101
102
103
104 void
105 SparsityPattern::add_row_entries(const size_type &row,
106 const ArrayView<const size_type> &columns,
107 const bool indices_are_sorted)
108 {
109 add_entries(row, columns.begin(), columns.end(), indices_are_sorted);
110 }
111
112
113
114 void
116 {
117 Assert(psblas_descriptor.get() != nullptr,
118 ExcMessage("PSBLAS descriptor is null."));
119 int err = -1;
120 if (!psb_c_cd_is_asb(psblas_descriptor.get()))
121 {
122 err = psb_c_cdasb(psblas_descriptor.get());
123 Assert(
124 err == 0,
125 ExcCallingPSBLASFunction(
126 err,
127 "Error while finalizing SparsityPattern through psb_c_cdasb."));
128 }
129 }
130} // namespace PSCToolkitWrappers
131
133#endif
*  iterator end()
*  *  iterator begin()
iterator begin() const
Definition array_view.h:755
iterator end() const
Definition array_view.h:764
size_type size() const
Definition index_set.h:1759
std::vector< size_type > get_index_vector() const
Definition index_set.cc:911
virtual void resize(const size_type rows, const size_type cols)
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false) override
void add(const size_type i, const size_type j)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertIntegerConversion(index1, index2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)