#ifndef FESA_SRC_FESA_SOLVERS_LINEAR_PARDISO_SESSION_H_ #define FESA_SRC_FESA_SOLVERS_LINEAR_PARDISO_SESSION_H_ #include #include #include #include "fesa/core/status.h" namespace fesa { class SparseMatrix; class Vector; namespace pardiso_internal { /// @brief Retains the two existing CSR and pivot policies. enum class PardisoMatrixPolicy { kSpdUpper, kUnsymmetricFull }; /// @brief Owns one backend factorization, CSR storage and phase lifecycle. /// @note No symbolic reuse is performed across Factorize calls. class PardisoSession final { public: explicit PardisoSession(PardisoMatrixPolicy policy); ~PardisoSession(); PardisoSession(const PardisoSession&) = delete; PardisoSession& operator=(const PardisoSession&) = delete; Status Factorize(const SparseMatrix& matrix); Status Solve(const Vector& rhs, Vector& solution); private: Status CopyValidatedUpperTriangle(const SparseMatrix& matrix); Status CopyValidatedFullCsr(const SparseMatrix& matrix); void CallPardiso(MKL_INT phase, double* rhs, double* solution, MKL_INT& error); MKL_INT Release() noexcept; void ClearOwnedArrays() noexcept; std::array pt_{}; std::array iparm_{}; std::vector row_offsets_; std::vector column_indices_; std::vector permutation_; std::vector values_; MKL_INT equation_count_{0}; MKL_INT max_factorizations_{1}; MKL_INT matrix_number_{1}; const PardisoMatrixPolicy policy_; MKL_INT mtype_; MKL_INT rhs_count_{1}; MKL_INT message_level_{0}; bool owns_pardiso_state_{false}; bool factorized_{false}; }; } // namespace pardiso_internal } // namespace fesa #endif // FESA_SRC_FESA_SOLVERS_LINEAR_PARDISO_SESSION_H_