Closed zhou13 closed 7 years ago
A bound check was added in #207. You can enable it with cmake -DXTENSOR_ENABLE_ASSERT=ON
or g++ -DXTENSOR_ENABLE_ASSERT main.cpp
.
It is disabled by default.
@zhou13 note that this bound check really degrades the performances, so it should only be used for debugging.
Generally, bound check will not degrade performance. From the modern computer architecture perspective, boundary check can be done in parallel when doing the memory fetching, which is almost free. In additional, the boundary check is only utilizing the interger ALU, while most applications for scientific computing are either memory bounded or float-point operation bounded.
Some not so rigorous real-world benchmarks show that the performance hit of bound check is usually in 1% magnitude: https://blogs.msdn.microsoft.com/ricom/2006/07/12/cost-of-array-bounds-checking-one-experiment/ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4487316/
In the N-D setting it complicates a bit the picture, so I expect more than 1% hit.
So this has been fixed in #207
Obviously, I forget to reshape the array before usage. I compile the above code use
g++ main.cpp -fsanitize=address -I.
. This code runs fine. No runtime error. It is also "valgrind-clean".I wish:
-fsanitize=address
and valgrind;g++ -DXTENSOR_NDEBUG main.cpp
to disable it.