Skip to content

Commit c8512ec

Browse files
Refactor error handling in linalg_state and stdlib_error; optimize loops in stdlib_lapack_blas_like_l2
1 parent ab2e4ee commit c8512ec

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

example/io/example.dat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
1.00000000E+00 1.00000000E+00
2-
1.00000000E+00 1.00000000E+00
3-
1.00000000E+00 1.00000000E+00
1+
This is an example for open

src/core/stdlib_error.fypp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,11 @@ contains
258258
!> Update the location of the error message
259259
pure subroutine state_update_location(this, where_at)
260260
class(state_type), intent(inout) :: this
261-
character(len=*), intent(in) :: where_at
261+
character(len=*), optional, intent(in) :: where_at
262262

263-
if (len_trim(where_at) > 0) this%where_at = adjustl(where_at)
263+
if (present(where_at)) then
264+
if (len_trim(where_at) > 0) this%where_at = adjustl(where_at)
265+
end if
264266

265267
end subroutine state_update_location
266268

src/lapack/stdlib_lapack_blas_like_l2.fypp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5698,10 +5698,8 @@ submodule(stdlib_lapack_base) stdlib_lapack_blas_like_l2
56985698
! Local Scalars
56995699
integer(${ik}$) :: i, j
57005700
! Executable Statements
5701-
do j = 1, n
5702-
do i = 1, m
5703-
x(i,j) = d(i) * x(i,j)
5704-
end do
5701+
do concurrent(j=1:n, i=1:m)
5702+
x(i,j) = d(i) * x(i,j)
57055703
end do
57065704
return
57075705
end subroutine stdlib${ii}$_${ri}$lascl2
@@ -5721,10 +5719,8 @@ submodule(stdlib_lapack_base) stdlib_lapack_blas_like_l2
57215719
! Local Scalars
57225720
integer(${ik}$) :: i, j
57235721
! Executable Statements
5724-
do j = 1, n
5725-
do i = 1, m
5726-
x(i,j) = d(i) * x(i,j)
5727-
end do
5722+
do concurrent(j=1:n, i=1:m)
5723+
x(i,j) = d(i) * x(i,j)
57285724
end do
57295725
return
57305726
end subroutine stdlib${ii}$_${ci}$lascl2

src/linalg_core/stdlib_linalg_state.fypp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ module stdlib_linalg_state
8080
character(len=*),optional,intent(in) :: where_at
8181

8282
character(len=:),allocatable :: err_msg
83+
type(linalg_state_type) :: local_err
8384

8485
if (present(ierr_out)) then
8586
! Return error flag
8687
ierr_out = ierr
87-
! Update location if requested
88-
if (present(where_at)) call ierr_out%update_location(where_at)
88+
! Update location if requested (update_location handles optional internally)
89+
call ierr_out%update_location(where_at)
8990
elseif (ierr%error()) then
90-
if (present(where_at)) then
91-
err_msg = '['//trim(where_at)//'] returned '//ierr%print_msg()
92-
else
93-
err_msg = ierr%print()
94-
end if
91+
! Use local copy to update location, then print
92+
local_err = ierr
93+
call local_err%update_location(where_at)
94+
err_msg = local_err%print()
9595
error stop err_msg
9696
end if
9797

0 commit comments

Comments
 (0)