@@ -56,8 +56,8 @@ subroutine coo2csr( nrow, &
5656 integer (kind= 8 ), dimension (nnz), intent (in ) :: ir
5757 integer (kind= 8 ), dimension (nnz), intent (in ) :: jc
5858 real (8 ), dimension (nnz), intent (out ) :: acsr
59- integer , dimension (nnz), intent (out ) :: ja
60- integer , dimension (nrow+1 ), intent (out ) :: ia
59+ integer (kind = 8 ) , dimension (nnz), intent (out ) :: ja
60+ integer (kind = 8 ) , dimension (nrow+1 ), intent (out ) :: ia
6161
6262 ! Local variables.
6363 integer (kind= 8 ) :: i, iad, j, k, k0
@@ -240,7 +240,8 @@ subroutine solve_pardiso( acsr, &
240240 integer , dimension (:), allocatable :: iparm
241241 integer ,dimension (1 ) :: idum
242242 real (8 ),dimension (1 ) :: ddum
243-
243+ integer :: badcol, missing_diag, k
244+ logical :: found
244245 n = size (b,1 )
245246 nnz = size (acsr,1 )
246247 nrhs = 1
@@ -284,7 +285,60 @@ subroutine solve_pardiso( acsr, &
284285 do i= 1 ,64
285286 pt(i)% dummy = 0
286287 end do
287-
288+
289+ !- --------------- CSR integrity / diagnostic checks ----------------
290+
291+ badcol = 0
292+
293+ write (* ,* ) ' PARDISO debug:'
294+ write (* ,* ) ' n =' , n
295+ write (* ,* ) ' nnz =' , nnz
296+ write (* ,* ) ' ia(1) =' , ia(1 ), ' ia(n+1)=' , ia(n+1 ), ' ia(n+1)-1=' , ia(n+1 )- 1
297+
298+ if (ia(1 ) /= 1 ) stop ' ERROR: ia(1) must be 1'
299+ if (ia(n+1 )- 1 /= nnz) stop ' ERROR: ia end mismatch'
300+
301+ do i= 1 ,n
302+ if (ia(i) > ia(i+1 )) then
303+ write (* ,* ) ' Row pointer decreases at row' , i
304+ stop ' ERROR: ia not monotone'
305+ end if
306+ end do
307+
308+ do k= 1 ,nnz
309+ if (ja(k) < 1 .or. ja(k) > n) then
310+ badcol = badcol + 1
311+ if (badcol <= 10 ) write (* ,* ) ' Bad column index k=' ,k,' ja=' ,ja(k)
312+ end if
313+ end do
314+ if (badcol > 0 ) then
315+ write (* ,* ) ' Total bad columns =' , badcol
316+ stop ' ERROR: invalid ja entries'
317+ end if
318+
319+ ! Check each row has a diagonal and (optionally) detect duplicates
320+ missing_diag = 0
321+ do i= 1 ,n
322+ found = .false.
323+ if (ia(i) < ia(i+1 )) then
324+ ! simple duplicate check (requires row segment unsorted ascending to be meaningful)
325+ do k = ia(i), ia(i+1 )- 1
326+ if (ja(k) == i) then
327+ if (acsr(k) == 0.0d0 ) then
328+ write (* ,* ) ' Zero diagonal at row' , i
329+ stop ' ERROR: zero diagonal'
330+ end if
331+ found = .true.
332+ end if
333+ end do
334+ end if
335+ if (.not. found) then
336+ missing_diag = missing_diag + 1
337+ if (missing_diag <= 10 ) write (* ,* ) ' Missing diagonal at row' , i
338+ end if
339+ end do
340+ if (missing_diag > 0 ) stop ' ERROR: missing diagonals'
341+ !- ------------------------------------------------------------------
288342 phase = 11 ! Only reordering and symbolic factorization
289343
290344 call pardiso (pt,maxfct,mnum,mtype,phase,n,acsr,ia,ja, &
0 commit comments