Tpetra: logic mistake in map getMinGlobalIndex/getMinAllGlobalIndex
Created by: lucbv
When a rank holds no GIDs the map will return 0 as its min global index.
@trilinos/tpetra
@mhoemmen @csiefer2
Expectations
The map should return the true minimum GID across ranks and not indexBase
when a rank holds no GIDs. A reasonable value needs to be returned by map.getMinGlobalIndex()
on a rank with no GIDs.
Current Behavior
As explained above, a map will map.getMinAllGlobalIndex()
return indexBase
if a process holds no GIDs. That is always wrong if the GIDs in the map are offset from IndexBase.
Motivation and Context
If you have the following distribution of GIDs: p0: [7, 8, 9] p1: [10, 11, 12] p2: [13, 14, 15] p3: []
map.getMinGlobalIndex() returns 0 on rank 3 and map.getMinAllGlobalIndex() returns 0. This type of GID partition happens after repartitioning a problem. I believe that most people will have 0 as the first index in maps, but this is not the case for multi physics problem represented by Xpetra BlockedMatrix.
Definition of Done
-
getMinGlobalIndex()
needs to return a sensible value when no GIDs are on the local rank -
getMinAllGlobalIndex()
needs to compute the min based on the range of GIDs used in the map.
Possible Solution
I think that returning Teuchos::OrdinalTraits<GlobalOrdinal>::max()
when calling getMinGlobalIndex on a rank that holds no GIDs is reasonable. Using Teuchos::OrdinalTraits<GlobalOrdinal>::invalid()
instead of max() can create issues when using MPI_reduce(MIN,...) since invalid could return 0 if the GlobalOrdinal
type is int
or some signed type.
Steps to Reproduce
Create a map using GIDs strictly higher than 0 and assign no GIDs to one rank, then call getMinGlobalIndex()
and getMinAllGlobalIndex()
Additional Information
It might be useful to check what Epetra is doing in this situation, it could have a work around or might have the same bug...