ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
petsc_solver.hpp
Go to the documentation of this file.
1#ifndef SRC_SOLVERS_NATIVE_PETSC_SOLVER_HPP_
2#define SRC_SOLVERS_NATIVE_PETSC_SOLVER_HPP_
3
4/* ============================================================================
5 Copyright (c) 2011-2019, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8
9 -----------------
10 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
11 -----------------
12
13 http://viennashe.sourceforge.net/
14
15 License: MIT (X11), see file LICENSE in the base directory
16 =============================================================================== */
17
18// viennashe
21#include "viennashe/log/log.hpp"
25#include <petscksp.h>
26#include <mpi.h>
27#include "petsc.hpp"
28
29namespace viennashe
30 {
31 namespace solvers
32 {
33 template <typename NumericT, typename VectorType>
34 VectorType
36 VectorType const &b,
39 {
40
41 viennashe::util::timer stopwatch;
42
46 PETSC_HANDLER &ref = PETSC_HANDLER::get_handler (config.getArgc (),
47 config.getArgv ());
48 // Check size nnz
49
50
51 // copy A and b to work system Ax = b
52 PETSC_MATRIX Ap (A); // work matrix
53 PetscBarrier (NULL);
54
55 //printf ("\n Matric Pointer: %p \n",&Ap );
56 PETSC_VECTOR Bp (b, Ap);
57 PetscBarrier (NULL);
58
59 stopwatch.start ();
60 Ap.solve (Bp);
61 PetscBarrier (NULL);
62 KSPConvergedReason reason = Ap.get_Creason ();
63 if (reason < 0)
64 {
65 log::info<log_linear_solver> () << "Divergence.\n";
66 }
67 else
68 {
69 log::info<log_linear_solver> () << "Convergence in"
70 << Ap.get_Citer () << "iterations." << std::endl;
71 }
72
73 VectorType newVector(Bp);
74 printf ("\n [%d]Solver Time (%d): %f Reason %d\n",ref.getRankW(),Ap.get_Citer() ,stopwatch.get (),reason);
75 return newVector;
76 }
77
78 }
79 }
80#endif /* SRC_SOLVERS_NATIVE_PETSC_SOLVER_HPP_ */
Defines a set of checker functors for micro-tests within ViennaSHE.
The main SHE configuration class. To be adjusted by the user for his/her needs.
Definition: config.hpp:124
Sparse matrix class based on a vector of binary trees for holding the entries.
Definition: linalg_util.hpp:69
Wrapper class to the PETSC matrix.
Definition: petsc.hpp:132
Class Encapsulate The PETSc COMM WORLD -Should be singleton.
Definition: petsc.hpp:437
A configuration class holding options for use within the different linear solvers.
Definition: config.hpp:57
Internal tag used for the specification of a CPU-based PETSC solver.
Definition: forwards.h:212
A simple timer class.
Definition: timer.hpp:74
void start()
Starts the timer.
Definition: timer.hpp:80
double get() const
Returns the number of seconds elapsed.
Definition: timer.hpp:88
Implementation of various utilities related to linear algebra.
A logging facility providing fine-grained control over logging in ViennaSHE.
std::vector< double > solve(viennashe::math::sparse_matrix< double > &A, std::vector< double > const &b, linear_solver_config const &config)
Public interface for solving a system of linear equations represented using a sparse matrix.
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
The SHE configuration class is defined here.
Defines all the log keys used within the viennashe::solvers namespace.
Contains a timer class. Contains one windows implementation and one *NIX implementation.