<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jan 11, 2017 at 7:00 AM, Florian Lindner <span dir="ltr"><<a href="mailto:mailinglists@xgm.de" target="_blank">mailinglists@xgm.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey,<br>
<br>
Am 10.01.2017 um 14:20 schrieb Barry Smith:<br>
><br>
> I do not understand what you mean. I hope this is C.<br>
<br>
Yes, I'm talking about C(++).<br>
<br>
I'm using PETSc functions like that:<br>
<br>
ierr = ISDestroy(&ISlocal); CHKERRV(ierr);<br>
<br>
Unfortunately that is not alway possible, e.g. in this function:<br>
<br>
std::pair<PetscInt, PetscInt> Vector::ownerRange()<br>
{<br>
PetscInt range_start, range_end;<br>
VecGetOwnershipRange(vector, &range_start, &range_end);<br>
return std::make_pair(range_start, range_end);<br>
}<br>
<br>
CHKERRV would returns void, CHKERRQ returns an int (iirc). Neither is possible here. But that is not my main issue here.<br>
<br>
For non PETSc related functions, I do not use CHKERRV and alike.<br>
<br>
><br>
> By default when an error is detected PetscError using PetscTraceBackErrorHandler returns up the stack printing the<br>
> function/line number then returning to the next function which prints the function/line number until it gets up to<br>
> the function main where it calls MPI_Abort.<br>
<br>
Ok, we use petsc like that:<br>
<br>
void myFunc() {<br>
PetscErrorCode ierr = 0;<br>
ierr = MatMultTranspose(_matrixA, in, Au); CHKERRV(ierr);<br>
[... no further error checking ...]<br>
}<br>
<br>
with the standard error handler this gives a nice traceback, but the application continues to run.<br>
<br>
With a PetscPushErrorHandler(&<wbr>PetscMPIAbortErrorHandler, nullptr); above these lines, that gives no traceback, just<br>
<br>
[0]PETSC ERROR: MatMult() line 2244 in /home/florian/software/petsc/<wbr>src/mat/interface/matrix.c<br>
Null Object: Parameter # 1<br>
<br>
and the application aborts.<br>
<br>
I want to combine these two traits. Print a nice traceback like the first example, then abort, like the second example.<br></blockquote><div><br></div><div>The problematic part of this strategy is that you want the handler to "know" where it is. Right now, the handler has no</div><div>idea where the top of the stack is, it just executes some action. In the normal case, it adds a line to the sack and returns.</div><div>In the latter, it aborts.</div><div><br></div><div>If you want different behavior, one option is to change the check at the level which you think is the top. So, at the uppermost</div><div>check of a PETSc function, you use CHKERRA instead.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> Now if one of the functions in the stack of functions is a user function that DOES NOT check a return code with<br>
> CHKERRQ(ierr) then bad stuff happens because PetscError will print part of the stack of functions but then the user<br>
> code (that ignores the error code) continues running generally causing bad and confusing things to happen. This is<br>
> why we recommend always using CHKERRQ() in user code.<br>
><br>
> From the perspective of PETSc error handling there really isn't any difference between user code and PETSc code.<br>
<br>
I understand that. But changing our application so that every function returns an error code and is checked using<br>
CHKERR* is not an option. The PETSc code is buried deeply in the framework.<br>
<br>
<br>
>> However, I want my application to be aborted with the PetscMPIAbortErrorHandler when an error occures.<br>
><br>
> Do you mean that in your code when you detect an error you want SETERRQ() to call PetscMPIAbortErrorHandler() but in<br>
> PETSc code you want it to try to return through the stack printing the PETSc function/line numbers? You can do this<br>
> by making your own macro mySETERRQ() that is defined to be a call to PetscMPIAbortErrorHandler and using mySETERRQ()<br>
> to mark errors in your code. Though I do not recommend this, better to use CHKERRQ() in your code and get error<br>
> tracebacks for PETSc code and your code.<br>
<br>
Ok, I'll keep that option in mind...<br>
<br>
Best,<br>
Florian<br>
<br>
>> On Jan 10, 2017, at 6:42 AM, Florian Lindner <<a href="mailto:mailinglists@xgm.de">mailinglists@xgm.de</a>> wrote:<br>
>><br>
>> Hello,<br>
>><br>
>> I really enjoy the verbosity (line number) of the default PetscTraceBackErrorHandler. However, I want my<br>
>> application to be aborted with the PetscMPIAbortErrorHandler when an error occures.<br>
>><br>
>> Can I instruct PETSc to call first one handler, then another one?<br>
>><br>
>> Thanks, Florian<br>
><br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>