Skip to content

Commit b288520

Browse files
committed
cleanup subroutine example; add preallocated pivot
1 parent 449d0a2 commit b288520

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

example/linalg/example_solve3.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
program example_solve3
2-
use stdlib_linalg_constants, only: sp
2+
use stdlib_linalg_constants, only: sp,ilp
33
use stdlib_linalg, only: solve_lu, linalg_state_type
44
implicit none
55

66
integer(ilp) :: test
7+
integer(ilp), allocatable :: pivot(:)
78
complex(sp), allocatable :: A(:,:),b(:),x(:)
89

910
! Solve a system of 3 complex linear equations:
@@ -15,15 +16,16 @@ program example_solve3
1516
A = transpose(reshape([(2.0, 0.0),(0.0, 1.0),(2.0,0.0), &
1617
(0.0,-1.0),(4.0,-3.0),(6.0,0.0), &
1718
(4.0, 0.0),(3.0, 0.0),(1.0,0.0)] , [3,3]))
18-
b = [(5.0,-1.0),(0.0,1.0),(1.0,0.0)]
1919

2020
! Pre-allocate x
21-
allocate(x,source=b)
21+
allocate(b(size(A,2)),pivot(size(A,2)))
22+
allocate(x,mold=b)
2223

2324
! Call system many times avoiding reallocation
2425
do test=1,100
25-
call solve_lu(A,b,x)
26-
print "(i2,'-th solution: ',*(1x,f12.6))", test,x
26+
b = test*[(5.0,-1.0),(0.0,1.0),(1.0,0.0)]
27+
call solve_lu(A,b,x,pivot)
28+
print "(i3,'-th solution: ',*(1x,f12.6))", test,x
2729
end do
2830

2931
end program example_solve3

0 commit comments

Comments
 (0)