[Carpet] potential integer overflow in Grid setup
Thomas Radke
tradke at aei.mpg.de
Thu Mar 20 18:28:26 CET 2008
Erik Schnetter wrote:
> Thanks. With this command, and after a complete rebuild, this test
> case passes when I run it manually.
>
> I pushed some unrelated changes recently. Maybe they were not really
> unrelated.
Hmm, it doesn't pass for me yet. This is with a standard configuration
compiled with DEBUG=yes and OPTIMISE=yes.
I have tried to isolate the problem and came to the conclusion that it
must be compiler-related. This is the function in bbox.cc where the
abort is triggered, added with a few debug output statements:
> template<class T, int D>
> void bbox<T,D>::assert_bbox_limits () const
> {
> assert (all(_stride>T(0)));
> assert (all((_upper-_lower)%_stride == T(0)));
> if (numeric_limits<T>::is_integer) {
> // prevent accidental wrap-around
> if (any (_lower >= numeric_limits<T>::max() / 2) or
> any (_lower <= numeric_limits<T>::min() / 2) or
> any (_upper >= numeric_limits<T>::max() / 2) or
> any (_upper <= numeric_limits<T>::min() / 2))
> {
> std::cerr << "=== _lower: " << _lower << " _upper: " << _upper
> << " min/2: " << (numeric_limits<T>::min() / 2)
> << " max/2: " << (numeric_limits<T>::max() / 2)
> << std::endl;
> std::cerr << "=== _lower >= max: "
> << any (_lower >= numeric_limits<T>::max() / 2)
> << " _lower <= min: "
> << any (_lower <= numeric_limits<T>::min() / 2)
> << std::endl
> << "=== _upper >= max: "
> << any (_upper >= numeric_limits<T>::max() / 2)
> << " _upper <= min: "
> << any (_upper <= numeric_limits<T>::min() / 2)
> << std::endl;
> CCTK_WARN (CCTK_WARN_ABORT,
> "Tried to create a very large bbox -- it is likely that this would lead to an integer overflow");
> }
> }
> }
The runtime output looks like this:
> INFO (Carpet): Base grid specification for map 0:
> number of grid points : [20,20,20]
> number of ghost points: [[2,2,2],[2,2,2]]
> === _lower: [0,0,0] _upper: [38,38,38] min/2: -1073741824 max/2: 1073741823
> === _lower >= max: 0 _lower <= min: 1
> === _upper >= max: 0 _upper <= min: 1
> WARNING level 0 in thorn CarpetLib processor 0 host peg304.hpc.lsu.edu
> (line 45 of /mnt/gpfs.work/tradke/cactus/configs/mpich-opt/build/CarpetLib/bbox.cc):
> -> Tried to create a very large bbox -- it is likely that this would lead to an integer overflow
Note that the comparisons against numeric_limits<int>::min()/2 are all
true, hence the level 0 warning. When I emulate the inlined any()
function and compare individual vector elements, everything works fine.
--
Cheers, Thomas.
More information about the developers
mailing list