New Assert class (Discussion)

29 views
Skip to first unread message

RAJAT ARORA

unread,
Dec 3, 2017, 5:17:48 PM12/3/17
to deal.II User Group
Hello all,

This is more of a discussion than a question.

I was wondering if there is a need for a new class which does something like Assert (Lets call it myAssert for now). Its function is as defined below.

While developing an application code, once I am confident that I am not making a mistake using any of the deal.ii functions (no Asserts are triggered), I switch to release mode.However, there can still be bugs in my own code: physical  or just programming based.

So, lets say my code is bug free from deal.ii point of view (No internal Asserts), I want to find a problem in my own code. 
Lets say that I want to find when in time does a variable become negative and why?


I dont want to use Assert as it causes huge overhead which is not needed at the moment. So, the best thing would be to run code in release mode
and use AssertThrow or print commands to find source of error. Now, once the bug is fixed, all the manual Asserthrow needs to be removed or commented. If they are ever needed again, they need to be uncommented again and this could span several files.

So, my point is if there is a new class "myAssert" that can function just like Assert but in release mode.

One solution could be having a new mode : like debug and release,  "Moderate" mode, where only user-defined myAsserts + AsserThrow will be checked.

So when build in moderate mode:  myAssert (+ Asserthrow) would work like "Assert". This is just to avoid huge overhead that debug mode will cause because of all internal checks.

When built in release mode: No myAssert would be checked. (AssertThrow will still be active).

The other way to thing about this is to have a new mode "Mode 3": where no Asserts or AssertThrow will be checked. In this case, AssertThrow behaves as "myAssert" class.

At the moment, I am not sure if that would be helpful to everyone or not but I am certainly interested in something like that.
If there exists something like that in deal.ii currenlty, please let me know. 

Thanks.




Timo Heister

unread,
Dec 4, 2017, 9:57:12 AM12/4/17
to dea...@googlegroups.com
I have seen other libraries with a release+asserts mode. I don't think
having a third variant of the deal.II internals makes a lot of sense,
but one could talk about having a compile option for it.

If you want something like Assert() in release mode inside your
programs, you could easily do something like this (steal it from
base/exceptions.h):

#if defined(DEBUG) || defined(MODERATE)
#define ModerateAssert(cond, exc)
\
{ \
if (!(cond)) \
::dealii::deal_II_exceptions::internals:: \
issue_error(::dealii::deal_II_exceptions::internals::abort_on_exception,\
__FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
}
#else
#define ModerateAssert(cond, exc)
\
{}
#endif
> --
> The deal.II project is located at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.dealii.org_&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=VspQ49D-XAgpTdrNH5ZSCeSLmdpzK74m-d3BpN8f5H8&s=T6PlLJxIzn0vg-6jF89N4FxbTJUkDqQcZnTPnZA4d9Q&e=
> For mailing list/forum options, see
> https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_forum_dealii-3Fhl-3Den&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=VspQ49D-XAgpTdrNH5ZSCeSLmdpzK74m-d3BpN8f5H8&s=6HOrQfIAELQIdTaYt-pGeNDIVL2kIqBC-oO7tBGJoto&e=
> ---
> You received this message because you are subscribed to the Google Groups
> "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dealii+un...@googlegroups.com.
> For more options, visit https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=VspQ49D-XAgpTdrNH5ZSCeSLmdpzK74m-d3BpN8f5H8&s=mlLuQj3_EKeFWtkVOo_6AHKGS4pzYHEwAkIK3cbItt4&e= .



--
Timo Heister
http://www.math.clemson.edu/~heister/

RAJAT ARORA

unread,
Dec 4, 2017, 1:28:26 PM12/4/17
to deal.II User Group
Hello Timo,

Thanks for your reply. I was thinking of something like that but was not sure how to do it in cmake.
I mean something like "make moderate".

Can you please tell me where should I edit so that code compilation follows from the mode given to "make".

Thanks.

Wolfgang Bangerth

unread,
Dec 4, 2017, 2:42:50 PM12/4/17
to dea...@googlegroups.com

> One solution could be having a new mode : like *debug* and *release*,
> "*Moderate*" mode, where only user-defined myAsserts + AsserThrow will
> be checked.
>
> *So when build in moderate mode*:  myAssert (+ Asserthrow) would work
> like "Assert". This is just to avoid huge overhead that debug mode will
> cause because of all internal checks.
>
> *When built in release mode*: No myAssert would be checked. (AssertThrow
> will still be active).
Rajat -- your request is reasonable, and as Timo pointed out easy to
implement in user projects.

I think I wouldn't like this in the library because it encourages people
to not run deal.II in debug mode. We know that the majority of bugs are
found in debug mode, and so it seems like an invitation to make mistakes
to discourage people from running in debug mode.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Timo Heister

unread,
Dec 4, 2017, 2:55:11 PM12/4/17
to dea...@googlegroups.com
> Thanks for your reply. I was thinking of something like that but was not
> sure how to do it in cmake.
> I mean something like "make moderate".
>
> Can you please tell me where should I edit so that code compilation follows
> from the mode given to "make".

Doing this as a cmake target is somewhat complicated. Easier options:
- just put "#define MODERATE" in your header file with the macro and
comment it out if you don't need it
- instead, put "ADD_DEFINITIONS("-DMODERATE")" to your cmake script
(or comment it out).

If you want to have a "make moderate" that toggles this define, you
need to create a new variable that tracks this setting and a target
"moderate" that toggles/enables it. See how we do this in ASPECT for
enabling tests:
https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_geodynamics_aspect_blob_master_CMakeLists.txt-23L149&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=4k7iKXbjGC8LfYxVJJXiaYVu6FRWmEjX38S7JmlS9Vw&m=8MrChrquRnUcalKx1yzXw8qsWYcILksWk_zaXDnfc20&s=L_VkpxtQJ0ypTXYC5UOaV1rMlEo7Hm-rF3K3d7IGE9A&e=
Reply all
Reply to author
Forward
0 new messages