Browse Source

improved multiplyRow method

tempestpy_adaptions
TimQu 7 years ago
parent
commit
48945d1199
  1. 4
      src/storm/solver/GmmxxMultiplier.cpp
  2. 2
      src/storm/solver/GmmxxMultiplier.h
  3. 10
      src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp
  4. 6
      src/storm/solver/Multiplier.cpp
  5. 15
      src/storm/solver/Multiplier.h
  6. 9
      src/storm/solver/NativeLinearEquationSolver.cpp
  7. 15
      src/storm/solver/NativeMultiplier.cpp
  8. 4
      src/storm/solver/NativeMultiplier.h

4
src/storm/solver/GmmxxMultiplier.cpp

@ -103,9 +103,9 @@ namespace storm {
}
template<typename ValueType>
ValueType GmmxxMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType const& offset) const {
void GmmxxMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const {
initialize();
return vect_sp(gmm::mat_const_row(gmmMatrix, rowIndex), x, typename gmm::linalg_traits<gmm::csr_matrix<ValueType>>::storage_type(), typename gmm::linalg_traits<std::vector<ValueType>>::storage_type()) + offset;
value += vect_sp(gmm::mat_const_row(gmmMatrix, rowIndex), x, typename gmm::linalg_traits<gmm::csr_matrix<ValueType>>::storage_type(), typename gmm::linalg_traits<std::vector<ValueType>>::storage_type());
}
template<typename ValueType>

2
src/storm/solver/GmmxxMultiplier.h

@ -24,7 +24,7 @@ namespace storm {
virtual void multiplyGaussSeidel(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b) const override;
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 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) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType const& offset) const override;
virtual void multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const override;
virtual void clearCache() const override;
private:
void initialize() const;

10
src/storm/solver/IterativeMinMaxLinearEquationSolver.cpp

@ -667,17 +667,9 @@ namespace storm {
}
void multiplyRow(uint64_t const& row, storm::storage::SparseMatrix<ValueType> const& A, storm::solver::Multiplier<ValueType> const& multiplier, ValueType const& bi, ValueType& xi, ValueType& yi) {
xi = multiplier.multiplyRow(row, x, bi);
yi = multiplier.multiplyRow(row, y, storm::utility::zero<ValueType>());
/*
xi = bi;
yi = storm::utility::zero<ValueType>();
for (auto const& entry : A.getRow(row)) {
xi += entry.getValue() * x[entry.getColumn()];
yi += entry.getValue() * y[entry.getColumn()];
}
*/
multiplier.multiplyRow2(row, x, xi, y, yi);
}
template<OptimizationDirection dir>

6
src/storm/solver/Multiplier.cpp

@ -50,6 +50,12 @@ namespace storm {
}
}
template<typename ValueType>
void Multiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2, ValueType& val2) const {
multiplyRow(rowIndex, x1, val1);
multiplyRow(rowIndex, x2, val2);
}
template<typename ValueType>
std::unique_ptr<Multiplier<ValueType>> MultiplierFactory<ValueType>::create(Environment const& env, storm::storage::SparseMatrix<ValueType> const& matrix) {
switch (env.solver().multiplier().getType()) {

15
src/storm/solver/Multiplier.h

@ -113,11 +113,22 @@ namespace storm {
void repeatedMultiplyAndReduce(Environment const& env, OptimizationDirection const& dir, std::vector<ValueType>& x, std::vector<ValueType> const* b, uint64_t n) const;
/*!
* Multiplies the row with the given index with x and adds the given offset
* Multiplies the row with the given index with x and adds the result to the provided value
* @param rowIndex The index of the considered row
* @param x The input vector with which the row is multiplied
* @param value The multiplication result is added to this value.
*/
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType const& offset) const = 0;
virtual void multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const = 0;
/*!
* Multiplies the row with the given index with x1 and x2 and adds the given offset o1 and o2, respectively
* @param rowIndex The index of the considered row
* @param x1 The first input vector with which the row is multiplied
* @param val1 The first multiplication result is added to this value.
* @param x2 The second input vector with which the row is multiplied
* @param val2 The second multiplication result is added to this value.
*/
virtual void multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2, ValueType& val2) const;
protected:
mutable std::unique_ptr<std::vector<ValueType>> cachedVector;

9
src/storm/solver/NativeLinearEquationSolver.cpp

@ -591,16 +591,9 @@ namespace storm {
}
void multiplyRow(uint64_t const& row, storm::storage::SparseMatrix<ValueType> const& A, storm::solver::Multiplier<ValueType> const& multiplier, ValueType const& bi, ValueType& xi, ValueType& yi) {
xi = multiplier.multiplyRow(row, x, bi);
yi = multiplier.multiplyRow(row, y, storm::utility::zero<ValueType>());
/*
xi = bi;
yi = storm::utility::zero<ValueType>();
for (auto const& entry : A.getRow(row)) {
xi += entry.getValue() * x[entry.getColumn()];
yi += entry.getValue() * y[entry.getColumn()];
}
*/
multiplier.multiplyRow2(row, x, xi, y, yi);
}
void performIterationStep(storm::storage::SparseMatrix<ValueType> const& A, storm::solver::Multiplier<ValueType> const& multiplier, std::vector<ValueType> const& b) {

15
src/storm/solver/NativeMultiplier.cpp

@ -83,10 +83,21 @@ namespace storm {
}
template<typename ValueType>
ValueType NativeMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType const& offset) const {
return this->matrix.multiplyRowWithVector(rowIndex, x);
void NativeMultiplier<ValueType>::multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const {
for (auto const& entry : this->matrix.getRow(rowIndex)) {
value += entry.getValue() * x[entry.getColumn()];
}
}
template<typename ValueType>
void NativeMultiplier<ValueType>::multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2, ValueType& val2) const {
for (auto const& entry : this->matrix.getRow(rowIndex)) {
val1 += entry.getValue() * x1[entry.getColumn()];
val2 += entry.getValue() * x2[entry.getColumn()];
}
}
template<typename ValueType>
void NativeMultiplier<ValueType>::multAdd(std::vector<ValueType> const& x, std::vector<ValueType> const* b, std::vector<ValueType>& result) const {
this->matrix.multiplyWithVector(x, result, b);

4
src/storm/solver/NativeMultiplier.h

@ -21,7 +21,9 @@ namespace storm {
virtual void multiplyGaussSeidel(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> const* b) const override;
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 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) const override;
virtual ValueType multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType const& offset) const override;
virtual void multiplyRow(uint64_t const& rowIndex, std::vector<ValueType> const& x, ValueType& value) const override;
virtual void multiplyRow2(uint64_t const& rowIndex, std::vector<ValueType> const& x1, ValueType& val1, std::vector<ValueType> const& x2, ValueType& val2) const override;
private:
bool parallelize(Environment const& env) const;

Loading…
Cancel
Save