SpM Handbook 1.2.4
Loading...
Searching...
No Matches
spmf_driver.F90
Go to the documentation of this file.
1!>
2!> @file spmf_driver.F90
3!>
4!> @brief Fortran 90 example using a matrix read with the spm driver.
5!>
6!> @copyright 2017-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
7!> Univ. Bordeaux. All rights reserved.
8!>
9!> @version 1.2.4
10!> @author Mathieu Faverge
11!> @author Alycia Lisito
12!> @date 2024-05-29
13!>
14!> @ingroup examples_fortran
15!>
16#ifndef DOXYGEN_SHOULD_SKIP_THIS
17program spmf_driver
18 use iso_c_binding
19 use spmf
20#if defined(SPM_WITH_MPI)
21 use mpi_f08
22#endif
23 implicit none
24
25 type(spmatrix_t), target :: spm
26 real(kind=c_double) :: norma
27 real(kind=c_double) :: eps = 1.e-15
28 integer(c_int) :: info
29 integer(kind=spm_int_t) :: nrhs
30 real(kind=c_double), dimension(:,:), allocatable, target :: x0, x, b
31
32#if defined(SPM_WITH_MPI)
33 ! SPM is compiled with MPI, thus MPI must be initialized
34 ! before any spm call
35 call mpi_init( info )
36#endif
37
38 !
39 ! Initialize the problem
40 ! 1- The matrix
41 call spmreaddriver( spmdriverlaplacian, "d:10:10:10:4.", spm, info )
42 call spmprintinfo( spm )
43
44 ! Scale A for better stability with low-rank computations
45 call spmnorm( spmfrobeniusnorm, spm, norma )
46 call spmscal( 1. / norma, spm )
47
48 ! 2- The right hand side
49 nrhs = 10
50 allocate(x0(spm%nexp, nrhs))
51 allocate(x( spm%nexp, nrhs))
52 allocate(b( spm%nexp, nrhs))
53
54 ! Compute b = A * x, with x random
55 call spmgenrhs( spmrhsrndx, nrhs, spm, x0, spm%nexp, b, spm%nexp, info )
56
57 ! Copy x0 into x
58 x = x0
59
60 !
61 ! Check the solution
62 !
63 call spmcheckaxb( eps, nrhs, spm, x0, spm%nexp, b, spm%nexp, x, spm%nexp, info )
64
65 call spmexit( spm )
66 deallocate(x0)
67 deallocate(x)
68 deallocate(b)
69
70#if defined(SPM_WITH_MPI)
71 call mpi_finalize( info )
72#endif
73
74end program spmf_driver
75
76#endif