Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
NativeMultiplier.cpp
Go to the documentation of this file.
1#include "NativeMultiplier.h"
2
3#include "storm-config.h"
4
6
8
12
14
15namespace storm {
16namespace solver {
17
18template<typename ValueType>
20 // Intentionally left empty.
21}
22
23template<typename ValueType>
25 return false;
26}
27
28template<typename ValueType>
29void NativeMultiplier<ValueType>::multiply(Environment const& env, std::vector<ValueType> const& x, std::vector<ValueType> const* b,
30 std::vector<ValueType>& result) const {
31 std::vector<ValueType>* target = &result;
32 if (&x == &result) {
33 target = &this->provideCachedVector(x.size());
34 }
35 if (parallelize(env)) {
36 multAddParallel(x, b, *target);
37 } else {
38 multAdd(x, b, *target);
39 }
40 if (&x == &result) {
41 std::swap(result, *target);
42 }
43}
44
45template<typename ValueType>
46void NativeMultiplier<ValueType>::multiplyGaussSeidel(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b,
47 bool backwards) const {
48 if (backwards) {
49 this->matrix.multiplyWithVectorBackward(x, x, b);
50 } else {
51 this->matrix.multiplyWithVectorForward(x, x, b);
52 }
53}
54
55template<typename ValueType>
56void NativeMultiplier<ValueType>::multiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
57 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
58 std::vector<uint_fast64_t>* choices) const {
59 std::vector<ValueType>* target = &result;
60 if (&x == &result) {
61 target = &this->provideCachedVector(x.size());
62 }
63 if (parallelize(env)) {
64 multAddReduceParallel(dir, rowGroupIndices, x, b, *target, choices);
65 } else {
66 multAddReduce(dir, rowGroupIndices, x, b, *target, choices);
67 }
68 if (&x == &result) {
69 std::swap(result, *target);
70 }
71}
72
73template<typename ValueType>
75 std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType>& x,
76 std::vector<ValueType> const* b, std::vector<uint_fast64_t>* choices, bool backwards) const {
77 if (backwards) {
78 this->matrix.multiplyAndReduceBackward(dir, rowGroupIndices, x, b, x, choices);
79 } else {
80 this->matrix.multiplyAndReduceForward(dir, rowGroupIndices, x, b, x, choices);
81 }
82}
83
84template<typename ValueType>
85void NativeMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const {
86 for (auto const& entry : this->matrix.getRow(rowIndex)) {
87 value += entry.getValue() * x[entry.getColumn()];
88 }
89}
90
91template<typename ValueType>
92void NativeMultiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2,
93 ValueType& val2) const {
94 for (auto const& entry : this->matrix.getRow(rowIndex)) {
95 val1 += entry.getValue() * x1[entry.getColumn()];
96 val2 += entry.getValue() * x2[entry.getColumn()];
97 }
98}
99
100template<typename ValueType>
101void NativeMultiplier<ValueType>::multAdd(std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const {
102 this->matrix.multiplyWithVector(x, result, b);
103}
104
105template<typename ValueType>
106void NativeMultiplier<ValueType>::multAddReduce(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
107 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
108 std::vector<uint64_t>* choices) const {
109 this->matrix.multiplyAndReduce(dir, rowGroupIndices, x, b, result, choices);
110}
111
112template<typename ValueType>
113void NativeMultiplier<ValueType>::multAddParallel(std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const {
114#ifdef STORM_HAVE_INTELTBB
115 this->matrix.multiplyWithVectorParallel(x, result, b);
116#else
117 STORM_LOG_WARN("Storm was built without support for Intel TBB, defaulting to sequential version.");
118 multAdd(x, b, result);
119#endif
120}
121
122template<typename ValueType>
123void NativeMultiplier<ValueType>::multAddReduceParallel(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
124 std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result,
125 std::vector<uint64_t>* choices) const {
126#ifdef STORM_HAVE_INTELTBB
127 this->matrix.multiplyAndReduceParallel(dir, rowGroupIndices, x, b, result, choices);
128#else
129 STORM_LOG_WARN("Storm was built without support for Intel TBB, defaulting to sequential version.");
130 multAddReduce(dir, rowGroupIndices, x, b, result, choices);
131#endif
132}
133
134template class NativeMultiplier<double>;
135template class NativeMultiplier<storm::RationalNumber>;
136template class NativeMultiplier<storm::RationalFunction>;
137template class NativeMultiplier<storm::Interval>;
138
139} // namespace solver
140} // namespace storm
virtual void multiplyAndReduceGaussSeidel(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > &x, std::vector< ValueType > const *b, std::vector< uint_fast64_t > *choices=nullptr, bool backwards=true) const override
void multiplyRow(uint64_t const &rowIndex, std::vector< ValueType > const &x, ValueType &value) const
Multiplies the row with the given index with x and adds the result to the provided value.
NativeMultiplier(storm::storage::SparseMatrix< ValueType > const &matrix)
void multiplyRow2(uint64_t const &rowIndex, std::vector< ValueType > const &x1, ValueType &val1, std::vector< ValueType > const &x2, ValueType &val2) const
Multiplies the row with the given index with x1 and x2 and adds the given offset o1 and o2,...
virtual void multiplyAndReduce(Environment const &env, OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint_fast64_t > *choices=nullptr) const override
virtual void multiplyGaussSeidel(Environment const &env, std::vector< ValueType > &x, std::vector< ValueType > const *b, bool backwards=true) const override
Performs a matrix-vector multiplication in gauss-seidel style.
virtual void multiply(Environment const &env, std::vector< ValueType > const &x, std::vector< ValueType > const *b, std::vector< ValueType > &result) const override
Performs a matrix-vector multiplication x' = A*x + b.
A class that holds a possibly non-square matrix in the compressed row storage format.
#define STORM_LOG_WARN(message)
Definition logging.h:30
LabParser.cpp.
Definition cli.cpp:18