DPsim
GpuMagmaAdapter.h
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #pragma once
10 
11 #include <bitset>
12 #include <iostream>
13 #include <list>
14 #include <memory>
15 #include <unordered_map>
16 #include <vector>
17 
18 #include <dpsim/Config.h>
19 #include <dpsim/Definitions.h>
20 #include <dpsim/DirectLinearSolver.h>
21 
22 #include <cusolverSp.h>
23 #include <magma_v2.h>
24 #include <magmasparse.h>
25 
26 namespace DPsim {
28 protected:
29  std::unique_ptr<Eigen::PermutationMatrix<Eigen::Dynamic>> mTransp;
30  // #### Attributes required for GPU ####
32  magma_dopts mMagmaOpts;
33  magma_queue_t mMagmaQueue;
34 
36  magma_d_matrix mHostSysMat;
37  magma_d_matrix mDevSysMat;
38 
40  magma_d_matrix mHostRhsVec;
41  magma_d_matrix mDevRhsVec;
43  magma_d_matrix mHostLhsVec;
44  magma_d_matrix mDevLhsVec;
45 
46  // TODO: fix mSLog for solvers (all solvers)
47  // using Solver::mSLog;
48 
49  void iluPreconditioner();
50 
51  void performFactorization(SparseMatrix &systemMatrix);
52 
53 public:
56 
58  virtual ~GpuMagmaAdapter();
59 
62 
64  virtual void preprocessing(SparseMatrix &systemMatrix,
65  std::vector<std::pair<UInt, UInt>>
66  &listVariableSystemMatrixEntries) override;
67 
69  virtual void factorize(SparseMatrix &systemMatrix) override;
70 
72  virtual void refactorize(SparseMatrix &systemMatrix) override;
73 
75  virtual void partialRefactorize(SparseMatrix &systemMatrix,
76  std::vector<std::pair<UInt, UInt>> &
77  listVariableSystemMatrixEntries) override;
78 
80  virtual Matrix solve(Matrix &rightSideVector) override;
81 };
82 } // namespace DPsim
DirectLinearSolver()=default
Constructor.
magma_d_matrix mHostLhsVec
LHS-Vector.
virtual void factorize(SparseMatrix &systemMatrix) override
factorization function with partial pivoting
virtual ~GpuMagmaAdapter()
Destructor.
virtual void refactorize(SparseMatrix &systemMatrix) override
refactorization without partial pivoting
magma_dopts mMagmaOpts
Solver-Handle.
magma_d_matrix mHostRhsVec
RHS-Vector.
virtual Matrix solve(Matrix &rightSideVector) override
solution function for a right hand side
magma_d_matrix mHostSysMat
Systemmatrix.
virtual void preprocessing(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries) override
preprocessing function pre-ordering and scaling the matrix
virtual void partialRefactorize(SparseMatrix &systemMatrix, std::vector< std::pair< UInt, UInt >> &listVariableSystemMatrixEntries) override
partial refactorization withouth partial pivoting
GpuMagmaAdapter()
Constructor.