Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LVARRAY_ERROR_IF_PRINTF() macro to prinnt fancyer messages on errors #255

Closed
wants to merge 26 commits into from

Conversation

XL64
Copy link
Contributor

@XL64 XL64 commented Mar 25, 2022

Attempt to solve issue #254.
Added new macro to use printf on device with clearer message.
Still not perfect, we don't know were we are when the error is raised.

Now the dimensions are correctly printed:
***** ERROR
***** LOCATION: /work206/workrd/users/lacoste_x/remote_builds/GEOSX/src/coreComponents/LvArray/src/ArraySlice.hpp:295
***** Block: [3, 0, 0]
***** Thread: [16, 0, 0]
***** Controlling expression (should be false): index < 0 || index >= m_dims[ 0 ]
***** MSG: Array Bounds Check Failed: index=8 m_dims[0]=8

@corbett5 corbett5 self-requested a review March 29, 2022 04:32
Copy link
Collaborator

@corbett5 corbett5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks! Before merging this you'll need to create a PR in the GEOSX repo updating the LvArray submodule. Once that is approved and has passed the checks you can merge this then update and merge the GEOSX PR.

@@ -130,8 +130,8 @@ class SparsityPattern : protected SparsityPatternView< COL_TYPE, INDEX_TYPE, BUF
void resizeFromRowCapacities( INDEX_TYPE const nRows, INDEX_TYPE const nCols, INDEX_TYPE const * const rowCapacities )
{
LVARRAY_ERROR_IF( !arrayManipulation::isPositive( nCols ), "nCols must be positive." );
LVARRAY_ERROR_IF( nCols - 1 > std::numeric_limits< COL_TYPE >::max(),
"COL_TYPE must be able to hold the range of columns: [0, " << nCols - 1 << "]." );
LVARRAY_ERROR_IF_PRINTF( nCols - 1 > std::numeric_limits< COL_TYPE >::max(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not device code so I'm not sure it makes sense to change.

@@ -438,8 +439,8 @@ class SparsityPatternView : protected ArrayOfSetsView< COL_TYPE, INDEX_TYPE, BUF
{
LVARRAY_ERROR_IF( !arrayManipulation::isPositive( nrows ), "nrows must be positive." );
LVARRAY_ERROR_IF( !arrayManipulation::isPositive( ncols ), "ncols must be positive." );
LVARRAY_ERROR_IF( ncols - 1 > std::numeric_limits< COL_TYPE >::max(),
"COL_TYPE must be able to hold the range of columns: [0, " << ncols - 1 << "]." );
LVARRAY_ERROR_IF_PRINTF( ncols - 1 > std::numeric_limits< COL_TYPE >::max(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@XL64
Copy link
Contributor Author

XL64 commented Mar 29, 2022

Ok thanks, I'll change the code. I was indeed wondering how we tested LVArray, thanks for the explanation i'll do so.

LVARRAY_ERROR_IF( !arrayManipulation::isPositive( i ) || i >= this->size(), \
"Bounds Check Failed: i=" << i << " size()=" << this->size() )
LVARRAY_ERROR_IF_PRINTF( !arrayManipulation::isPositive( i ) || i >= this->size(), \
"Bounds Check Failed: i=%" PRId64 " size()=%" PRId64, (int64_t)i, (int64_t)this->size() )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is PRId64 defined, and what if the index is not 64 bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRId64 is in inttypes.h https://www.cplusplus.com/reference/cinttypes/,
Int are casted into int64 to be sure not to have overflow.

@XL64 XL64 closed this Jun 7, 2022
@corbett5
Copy link
Collaborator

corbett5 commented Jun 7, 2022

Any reason you closed this, it seems quite nice.

@XL64
Copy link
Contributor Author

XL64 commented Jun 7, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants