deal.II version GIT relicensing-6960-g70e9c5b7be 2026-10-22 20:10: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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
16
18
19#include <psb_c_base.h>
20
21
22#ifdef DEAL_II_WITH_PSBLAS
24
26
27namespace PSCToolkitWrappers
28{
29 // SparsityPattern
31 const MPI_Comm communicator)
32 {
33 SparsityPatternBase::resize(index_set.size(), index_set.size());
34
35 Assert(communicator != MPI_COMM_NULL,
36 ExcMessage("MPI_COMM_NULL passed to SparseMatrix::reinit()."));
37
38 psblas_descriptor.reset(psb_c_new_descriptor(),
39 PSCToolkitWrappers::internal::DescriptorDeleter());
40
41 // Use get_index_vector() from IndexSet to get the indexes
42 const std::vector<types::global_dof_index> &indexes =
43 index_set.get_index_vector();
44
45 psb_i_t number_of_local_indexes = indexes.size(); // Number of local indexes
46 // Copy the indexes into a psb_l_t vector
47 std::vector<psb_l_t> vl(number_of_local_indexes);
48 for (psb_i_t i = 0; i < number_of_local_indexes; ++i)
49 {
50 const auto psblas_index = static_cast<psb_l_t>(indexes[i]);
51 AssertIntegerConversion(psblas_index, indexes[i]);
52 vl[i] = psblas_index;
53 }
54
55 // Insert the indexes into the descriptor
56 psb_c_cdall_vl(number_of_local_indexes,
57 vl.data(),
58 *InitFinalize::get_psblas_context(),
59 psblas_descriptor.get());
60 }
61
62
63
64 void
65 SparsityPattern::add(const PSCToolkitWrappers::SparsityPattern::size_type i,
66 const PSCToolkitWrappers::SparsityPattern::size_type j)
67 {
68 add_entries(i, &j, &j + 1);
69 }
70
71
72
73 template <typename ForwardIterator>
74 void
76 const PSCToolkitWrappers::SparsityPattern::size_type row,
77 ForwardIterator begin,
78 ForwardIterator end,
79 const bool indices_are_sorted)
80 {
81 Assert(psblas_descriptor.get() != nullptr,
82 ExcMessage("PSBLAS descriptor is null."));
83 if (begin == end)
84 return;
85
86 (void)indices_are_sorted;
87 psb_i_t nz = static_cast<int>(end - begin);
88 std::vector<psb_l_t> ia(nz);
89 std::vector<psb_l_t> ja(nz);
90
91 for (int k = 0; k < nz; ++k)
92 {
93 ia[k] = row; // row index
94 ja[k] = *(begin + k); // column index
95 }
96 int err = psb_c_cdins(nz, ia.data(), ja.data(), psblas_descriptor.get());
97 Assert(err == 0, ExcInsertionInPSBLASMatrix(err));
98 }
99
100
101
102 void
103 SparsityPattern::add_row_entries(const size_type &row,
104 const ArrayView<const size_type> &columns,
105 const bool indices_are_sorted)
106 {
107 add_entries(row, columns.begin(), columns.end(), indices_are_sorted);
108 }
109
110
111
112 void
114 {
115 Assert(psblas_descriptor.get() != nullptr,
116 ExcMessage("PSBLAS descriptor is null."));
117 int err = -1;
118 if (!psb_c_cd_is_asb(psblas_descriptor.get()))
119 {
120 err = psb_c_cdasb(psblas_descriptor.get());
121 Assert(
122 err == 0,
123 ExcCallingPSBLASFunction(
124 err,
125 "Error while finalizing SparsityPattern through psb_c_cdasb."));
126 }
127 }
128} // namespace PSCToolkitWrappers
129
131#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)