Skip to content

Commit cfc5cfd

Browse files
committed
updates indexing in scotch partitioning for newer gcc versions (>= 13.x)
1 parent 917e4e0 commit cfc5cfd

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/decompose_mesh/partition_scotch.F90

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ subroutine partition_scotch()
173173
stop 'Scotch ERROR : MAIN : Invalid check'
174174
endif
175175

176-
call scotchfgraphpart (scotchgraph(1), nparts, scotchstrat(1),part(1),ier)
176+
call scotchfgraphpart (scotchgraph(1), nparts, scotchstrat(1), part(1),ier)
177177
if (ier /= 0) then
178178
stop 'Scotch ERROR : MAIN : Cannot part graph'
179179
endif
@@ -271,11 +271,15 @@ subroutine lts_partition_scotch()
271271
enddo
272272
if (inum /= nspec_p) stop 'Error number of p-vertices not equals to number of p-elements'
273273

274+
! note: newer gcc compilers (version >= 13.x) seem to work only if the adjaceny arrays start indexing from 0.
275+
! that is, we use scotchfgraphbuild(..) with a baseval == 0 and use index values from 0 to nspec_p-1 in
276+
! xadj_tmp() and adjncy_tmp() arrays.
277+
274278
! builds up local arrays only for p-elements
275279
xadj_tmp(:) = 0
276280
adjncy_tmp(:) = -1
277281
elmnts_load_tmp(:) = 0
278-
nb_edges_tmp = 1
282+
nb_edges_tmp = 0
279283
do inum = 1,nspec_p
280284
ispec = ispec_global(inum)
281285

@@ -284,11 +288,9 @@ subroutine lts_partition_scotch()
284288

285289
! number of neighbors
286290
! note: xadj() values start from 0; adjncy() values start from 0 to nspec-1
287-
! we shift these by +1 since arrays in this subroutine are defined between 1 to ..
288291
!
289292
! xadj(i) -> adjncy( . ) : values in xadj point to the first index in adjncy() for vertex i
290293
! adjncy() holds all indices of neighbor vertices(=elements)
291-
! note: for xadj_tmp and adjncy_tmp we start indexing at 1
292294
xadj_tmp(inum) = nb_edges_tmp
293295
do j = xadj(ispec),xadj(ispec+1)-1
294296
! gets neighbor index
@@ -299,14 +301,20 @@ subroutine lts_partition_scotch()
299301
if (ispec_p_refine(k) == p) then
300302
! we store the local index between 1 and nspec_p
301303
i = ispec_local( k )
302-
adjncy_tmp(nb_edges_tmp) = i
304+
if (i < 1 .or. i > nspec_p) then
305+
print *,'Error: invalid local index ',i,'ispec k',k,'p',ispec_p_refine(k),'ilevel/p',ilevel,p
306+
stop 'Error local index'
307+
endif
308+
adjncy_tmp(nb_edges_tmp+1) = i - 1 ! shift index to start at 0
303309
nb_edges_tmp = nb_edges_tmp + 1
304310
endif
305311
enddo
306312
enddo
307313
! last entry for xadj for a contiguous range of indices ("compact edge array")
308314
xadj_tmp(nspec_p+1) = nb_edges_tmp
309-
nb_edges_tmp = nb_edges_tmp - 1
315+
316+
! since we start counting at 0, the total number is nb_edges_tmp not nb_edges_tmp-1
317+
!nb_edges_tmp = nb_edges_tmp - 1
310318

311319
! debug
312320
!print *,'xadj:',xadj(ispec_global(1):ispec_global(1)+1),xadj(nspec-1:nspec+1)
@@ -324,8 +332,8 @@ subroutine lts_partition_scotch()
324332
! print *,j-xadj_tmp(1)+1,j,adjncy_tmp(j),ispec_global(adjncy_tmp(j))
325333
!enddo
326334

327-
! checks ranges
328-
if (minval(adjncy_tmp(1:nb_edges_tmp)) < 1 .or. maxval(adjncy_tmp(1:nb_edges_tmp)) > nspec_p) then
335+
! checks ranges (index values in adjncy_tmp() start at 0)
336+
if (minval(adjncy_tmp(1:nb_edges_tmp)) < 0 .or. maxval(adjncy_tmp(1:nb_edges_tmp)) > nspec_p - 1) then
329337
print *,'Error adjncy bounds invalid', minval(adjncy_tmp(1:nb_edges_tmp)),maxval(adjncy_tmp(1:nb_edges_tmp))
330338
stop 'Error adjncy bounds invalid'
331339
endif
@@ -349,7 +357,7 @@ subroutine lts_partition_scotch()
349357
! Setting vendtab to refer to one cell after verttab yields the same result,
350358
! as it is the exact semantics of a compact vertex array.
351359

352-
call scotchfgraphbuild (scotchgraph(1), 1, nspec_p, &
360+
call scotchfgraphbuild (scotchgraph(1), 0, nspec_p, &
353361
xadj_tmp(1), xadj_tmp(1), &
354362
elmnts_load_tmp(1), xadj_tmp(1), &
355363
nb_edges_tmp, adjncy_tmp(1), &
@@ -372,19 +380,22 @@ subroutine lts_partition_scotch()
372380
'using subset maximum',P_LEVEL_PARTIAL_SUBSET_MINIMUM
373381

374382
! partitions among subset nparts_partial processes
375-
call scotchfgraphpart (scotchgraph(1), nparts_partial, scotchstrat(1),part_tmp(1),ier)
383+
call scotchfgraphpart (scotchgraph(1), nparts_partial, scotchstrat(1), part_tmp(1), ier)
376384
if (ier /= 0) stop 'Scotch ERROR : MAIN : Cannot part graph'
377385

378386
else
387+
! parition over all nparts processes
388+
! user output
389+
print *,' partitioning: nparts =',nparts
379390

380391
! partitions among all nparts processes
381-
call scotchfgraphpart (scotchgraph(1), nparts, scotchstrat(1),part_tmp(1),ier)
392+
call scotchfgraphpart (scotchgraph(1), nparts, scotchstrat(1), part_tmp(1), ier)
382393
if (ier /= 0) stop 'Scotch ERROR : MAIN : Cannot part graph'
383394

384395
endif
385396

386397
! frees scotch graph for subsequent calls of scotch again
387-
call scotchfgraphfree (scotchgraph(1),ier)
398+
call scotchfgraphfree (scotchgraph(1), ier)
388399
if (ier /= 0) stop 'Scotch ERROR : MAIN : Cannot free graph'
389400

390401
! stitch partitioning together

0 commit comments

Comments
 (0)