@@ -13,11 +13,11 @@ module m_lapack_example
1313 implicit none
1414
1515 private ; public :: s_lapack_example_solve_linear_system, &
16- s_lapack_example_eigenvalues
16+ s_lapack_example_eigenvalues
1717
1818contains
1919
20- ! > @brief Example subroutine demonstrating LAPACK usage for solving
20+ ! > @brief Example subroutine demonstrating LAPACK usage for solving
2121 ! ! a linear system Ax = b using DGESV/SGESV
2222 ! ! This routine shows how to use LAPACK with MFC's precision system
2323 impure subroutine s_lapack_example_solve_linear_system ()
@@ -27,35 +27,35 @@ impure subroutine s_lapack_example_solve_linear_system()
2727 real (wp), dimension (n, n) :: A ! Coefficient matrix
2828 real (wp), dimension (n) :: b ! Right-hand side vector
2929 real (wp), dimension (n) :: x ! Solution vector
30-
30+
3131 ! LAPACK variables
3232 integer , dimension (n) :: ipiv ! Pivot indices
3333 integer :: info ! Return status
34- integer :: nrhs = 1 ! Number of right-hand sides
35-
34+ integer , parameter :: nrhs = 1 ! Number of right-hand sides
35+
3636 ! Only run on the root process to avoid duplicate output
3737 if (proc_rank /= 0 ) return
38-
38+
3939 ! Set up a simple 3x3 linear system: Ax = b
40- ! Example:
40+ ! Example:
4141 ! 2x + y + z = 8
42- ! x + 3y + z = 10
42+ ! x + 3y + z = 10
4343 ! x + y + 4z = 16
4444 A(1 , :) = [2.0_wp , 1.0_wp , 1.0_wp ]
4545 A(2 , :) = [1.0_wp , 3.0_wp , 1.0_wp ]
4646 A(3 , :) = [1.0_wp , 1.0_wp , 4.0_wp ]
47-
47+
4848 b = [8.0_wp , 10.0_wp , 16.0_wp ]
49-
49+
5050 print * , " === LAPACK Linear System Solver Example ==="
5151 print * , " Solving the system Ax = b where:"
5252 print * , " A = [2 1 1; 1 3 1; 1 1 4]"
5353 print * , " b = [8; 10; 16]"
5454 print * , " "
55-
55+
5656 ! Copy b to x (LAPACK will overwrite the right-hand side with solution)
5757 x = b
58-
58+
5959 ! Call appropriate LAPACK routine based on precision
6060#ifdef MFC_SINGLE_PRECISION
6161 call sgesv(n, nrhs, A, n, ipiv, x, n, info)
@@ -64,7 +64,7 @@ impure subroutine s_lapack_example_solve_linear_system()
6464 call dgesv(n, nrhs, A, n, ipiv, x, n, info)
6565 print * , " Using double precision LAPACK (DGESV)"
6666#endif
67-
67+
6868 ! Check for success
6969 if (info == 0 ) then
7070 print * , " Linear system solved successfully!"
@@ -75,13 +75,13 @@ impure subroutine s_lapack_example_solve_linear_system()
7575 else
7676 print * , " LAPACK error: matrix is singular, solution could not be computed"
7777 end if
78-
78+
7979 print * , " === End LAPACK Example ==="
8080 print * , " "
81-
81+
8282 end subroutine s_lapack_example_solve_linear_system
8383
84- ! > @brief Example subroutine demonstrating LAPACK usage for computing
84+ ! > @brief Example subroutine demonstrating LAPACK usage for computing
8585 ! ! eigenvalues of a symmetric matrix using DSYEV/SSYEV
8686 impure subroutine s_lapack_example_eigenvalues ()
8787
@@ -90,24 +90,24 @@ impure subroutine s_lapack_example_eigenvalues()
9090 real (wp), dimension (n, n) :: A ! Symmetric matrix
9191 real (wp), dimension (n) :: w ! Eigenvalues
9292 real (wp), dimension (3 * n) :: work ! Work array
93- integer :: lwork = 3 * n ! Size of work array
93+ integer , parameter :: lwork = 3 * n ! Size of work array
9494 integer :: info ! Return status
95- character :: jobz = ' N' ! Compute eigenvalues only
96- character :: uplo = ' U' ! Upper triangular part of A
97-
95+ character , parameter :: jobz = ' N' ! Compute eigenvalues only
96+ character , parameter :: uplo = ' U' ! Upper triangular part of A
97+
9898 ! Only run on the root process to avoid duplicate output
9999 if (proc_rank /= 0 ) return
100-
100+
101101 ! Set up a simple symmetric 3x3 matrix
102102 A(1 , :) = [4.0_wp , 1.0_wp , 1.0_wp ]
103103 A(2 , :) = [1.0_wp , 4.0_wp , 1.0_wp ]
104104 A(3 , :) = [1.0_wp , 1.0_wp , 4.0_wp ]
105-
105+
106106 print * , " === LAPACK Eigenvalue Example ==="
107107 print * , " Computing eigenvalues of symmetric matrix:"
108108 print * , " A = [4 1 1; 1 4 1; 1 1 4]"
109109 print * , " "
110-
110+
111111 ! Call appropriate LAPACK routine based on precision
112112#ifdef MFC_SINGLE_PRECISION
113113 call ssyev(jobz, uplo, n, A, n, w, work, lwork, info)
@@ -116,7 +116,7 @@ impure subroutine s_lapack_example_eigenvalues()
116116 call dsyev(jobz, uplo, n, A, n, w, work, lwork, info)
117117 print * , " Using double precision LAPACK (DSYEV)"
118118#endif
119-
119+
120120 ! Check for success
121121 if (info == 0 ) then
122122 print * , " Eigenvalues computed successfully!"
@@ -127,10 +127,10 @@ impure subroutine s_lapack_example_eigenvalues()
127127 else
128128 print * , " LAPACK error: algorithm failed to converge"
129129 end if
130-
130+
131131 print * , " === End LAPACK Eigenvalue Example ==="
132132 print * , " "
133-
133+
134134 end subroutine s_lapack_example_eigenvalues
135135
136- end module m_lapack_example
136+ end module m_lapack_example
0 commit comments