Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_paralution.F90
Go to the documentation of this file.
2 #include "sll_working_precision.h"
3 #include "sll_memory.h"
4  use, intrinsic :: iso_c_binding
5 
6  implicit none
7 
9 
10  integer(kind=C_INT) :: num_rows
11  integer(kind=C_INT) :: num_cols
12  integer(kind=C_INT) :: num_nz
13  integer(kind=C_INT), pointer :: row_ptr(:)
14  integer(kind=C_INT), pointer :: col_ind(:)
15  real(kind=c_double), pointer :: val(:)
16 
17  end type paralution_solver
18 
19  interface
20 
21  subroutine paralution_init() BIND(C)
22  end subroutine paralution_init
23 
24  subroutine paralution_stop() BIND(C)
25  end subroutine paralution_stop
26 
27  subroutine paralution_fortran_solve_csr(n, m, nnz, solver, &
28  mformat, preconditioner, &
29  pformat, rows, cols, &
30  rval, rhs, atol, rtol, &
31  div, maxiter, basis, &
32  p, q, x, iter, resnorm, &
33  ierr) BIND(C)
34 
35  use, intrinsic :: iso_c_binding, only: c_int, c_ptr, c_double, c_char
36 
37  integer(kind=C_INT), value, intent(in) :: n, m, nnz, maxiter, basis, p, q
38  real(kind=c_double), value, intent(in) :: atol, rtol, div
39  integer(kind=C_INT), intent(out) :: iter, ierr
40  real(kind=c_double), intent(out) :: resnorm
41  type(c_ptr), value, intent(in) :: rows, cols, rval, rhs
42  type(c_ptr), value :: x
43  character(kind=C_CHAR) :: solver
44  character(kind=C_CHAR) :: mformat
45  character(kind=C_CHAR) :: preconditioner
46  character(kind=C_CHAR) :: pformat
47 
48  end subroutine paralution_fortran_solve_csr
49 
50  end interface
51 
52  interface initialize
53  module procedure init_paralution
54  end interface initialize
55 
56  interface solve
57  module procedure solve_paralution_with_rhs
58  end interface solve
59 
60  interface factorize
61  module procedure factorize_paralution
62  end interface factorize
63 
64  interface delete
65  module procedure free_paralution
66  end interface delete
67 
68 contains
69 
70  subroutine init_paralution(self, n, nnz)
71 
72  type(paralution_solver) :: self
73  sll_int32, intent(in) :: n
74  sll_int32, intent(in) :: nnz
75  sll_int32 :: error
76 
77  ! Allocate memory for CSR format specific arrays
78  self%num_rows = n
79  self%num_cols = n
80  self%num_nz = nnz
81  sll_allocate(self%val(nnz), error)
82  sll_allocate(self%col_ind(nnz), error)
83  sll_allocate(self%row_ptr(n + 1), error)
84 
85  ! Initialize PARALUTION backend
86  call paralution_init
87 
88  end subroutine init_paralution
89 
90  subroutine factorize_paralution(self)
91 
92  type(paralution_solver) :: self
93 
94  end subroutine factorize_paralution
95 
96  subroutine solve_paralution_with_rhs(self, rhs, sol)
97 
98  type(paralution_solver) :: self
99  real(kind=c_double), target :: sol(:)
100  real(kind=c_double), target :: rhs(:)
101 
102  integer(kind=C_INT) :: iter
103  integer(kind=C_INT) :: ierr
104  real(kind=c_double) :: resnorm
105 
106  ! Run paralution C function for CSR matrices
107  ! Doing a GMRES with MultiColored ILU(1,2) preconditioner
108  ! Check paralution documentation for a detailed argument explanation
110  self%num_rows, &
111  self%num_cols, &
112  self%num_nz, &
113  'CG'//c_null_char, &
114  'CSR'//c_null_char, &
115  'MultiColoredILU'//c_null_char, &
116  'CSR'//c_null_char, &
117  c_loc(self%row_ptr(1)), &
118  c_loc(self%col_ind(1)), &
119  c_loc(self%val(1)), &
120  c_loc(rhs), &
121  1e-15_c_double, &
122  1e-8_c_double, &
123  1e+8_c_double, &
124  5000, &
125  30, &
126  0, &
127  1, &
128  c_loc(sol), &
129  iter, &
130  resnorm, &
131  ierr)
132 
133  ! Print solver details
134  if (ierr .eq. 0) then
135  write (*, fmt='(A,I0,A,E12.5,A)') '(Fortran) Solver took ', iter, ' iterations with residual norm ', resnorm, '.'
136  else
137  write (*, fmt='(A,I0)') '(Fortran) Solver returned status code ', ierr
138  end if
139 
140  end subroutine solve_paralution_with_rhs
141 
142  subroutine free_paralution(self)
143 
144  type(paralution_solver) :: self
145 
146  ! Stop PARALUTION backend
147  call paralution_stop
148 
149  end subroutine free_paralution
150 
151 end module sll_m_paralution
subroutine solve_paralution_with_rhs(self, rhs, sol)
subroutine factorize_paralution(self)
subroutine free_paralution(self)
subroutine init_paralution(self, n, nnz)
subroutine sol(vkgs, vkgd, vkgi, vfg, kld, vu, neq, mp, ifac, isol, nsym, energ, ier, nsky)
Definition: sol.f:3
    Report Typos and Errors