Skip to content

Commit 85a70ba

Browse files
committed
small simplifications for working data
1 parent 71c2630 commit 85a70ba

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

example/linalg/example_solve_custom.f90

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ subroutine solve_pccg_custom(A,b,x,di,tol,maxiter,restart,workspace)
3939
end if
4040

4141
if(present(workspace)) then
42-
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,4) )
4342
workspace_ => workspace
4443
else
4544
allocate( workspace_ )
46-
allocate( workspace_%tmp(n,4) , source = 0._dp )
4745
end if
46+
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,4) , source = 0.d0 )
47+
!-------------------------
48+
! Jacobi preconditionner factorization
4849
call diag(A,diagonal)
4950
where(abs(diagonal)>epsilon(0.d0)) diagonal = 1._dp/diagonal
5051
!-------------------------
@@ -53,17 +54,14 @@ subroutine solve_pccg_custom(A,b,x,di,tol,maxiter,restart,workspace)
5354

5455
!-------------------------
5556
! internal memory cleanup
56-
if(present(di))then
57-
di_ => null()
58-
else
59-
deallocate(di_)
60-
end if
61-
if(present(workspace)) then
62-
workspace_ => null()
63-
else
57+
if(.not.present(di)) deallocate(di_)
58+
di_ => null()
59+
60+
if(.not.present(workspace)) then
6461
deallocate( workspace_%tmp )
6562
deallocate( workspace_ )
6663
end if
64+
workspace_ => null()
6765
contains
6866

6967
subroutine my_matvec(x,y)

src/stdlib_linalg_iterative_solvers_cg.fypp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,25 @@ contains
108108
end if
109109

110110
if(present(workspace)) then
111-
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,3) )
112111
workspace_ => workspace
113112
else
114113
allocate( workspace_ )
115-
allocate( workspace_%tmp(n,3), source = zero_${s}$ )
116114
end if
115+
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,3), source = zero_${s}$ )
117116
!-------------------------
118117
! main call to the solver
119118
call solve_cg_generic(op,b,x,di_,tol_,maxiter_,restart_,workspace_)
120119

121120
!-------------------------
122121
! internal memory cleanup
123-
if(present(di))then
124-
di_ => null()
125-
else
126-
deallocate(di_)
127-
end if
128-
if(present(workspace)) then
129-
workspace_ => null()
130-
else
122+
if(.not.present(di)) deallocate(di_)
123+
di_ => null()
124+
125+
if(.not.present(workspace)) then
131126
deallocate( workspace_%tmp )
132127
deallocate( workspace_ )
133128
end if
129+
workspace_ => null()
134130
contains
135131

136132
subroutine default_matvec(x,y)

src/stdlib_linalg_iterative_solvers_pccg.fypp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,25 @@ contains
119119
end if
120120

121121
if(present(workspace)) then
122-
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,4) )
123122
workspace_ => workspace
124123
else
125124
allocate( workspace_ )
126-
allocate( workspace_%tmp(n,4) , source = zero_${s}$ )
127125
end if
126+
if(.not.allocated(workspace_%tmp)) allocate( workspace_%tmp(n,4) , source = zero_${s}$ )
128127
!-------------------------
129128
! main call to the solver
130129
call solve_pccg_generic(op,b,x,di_,tol_,maxiter_,restart_,workspace_)
131130

132131
!-------------------------
133132
! internal memory cleanup
134-
if(present(di))then
135-
di_ => null()
136-
else
137-
deallocate(di_)
138-
end if
139-
if(present(workspace)) then
140-
workspace_ => null()
141-
else
133+
if(.not.present(di)) deallocate(di_)
134+
di_ => null()
135+
136+
if(.not.present(workspace)) then
142137
deallocate( workspace_%tmp )
143138
deallocate( workspace_ )
144139
end if
140+
workspace_ => null()
145141
contains
146142

147143
subroutine default_matvec(x,y)

0 commit comments

Comments
 (0)