[petsc-dev] SETERRQ in fortran

Jed Brown jed at jedbrown.org
Fri Jan 5 12:45:42 CST 2018


"Smith, Barry F." <bsmith at mcs.anl.gov> writes:

>> On Jan 4, 2018, at 5:10 PM, Blaise A Bourdin <bourdin at lsu.edu> wrote:
>> 
>> 
>> 
>>> On Jan 4, 2018, at 3:16 PM, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
>>> 
>>> 
>>> It's changed a bit.  It is better but you need to understand how the new one works, so take a few minutes to see how it works before converting.
>> Got it.
>> An example or a link to the fortran macro definition from the man page would be nice 
>> I am confused about the rationale for putting the endif in the macro, though.
>
>   It matches the C paradigm

Hardly.  This Fortran:

  #define SETERRQ(c,ierr,s)  ;call PetscError(c,ierr,0,s);return;endif

This would be like writing this C

  #define SETERRQ(c,ierr,s) return PetscError(...); }

to be used like

  if (BAD) { SETERRQ(comm, ierr, "why")

which is just bananas and still not as gross as the Fortran.  You might
not have noticed this because SETERRQ is not called from any of PETSc's
Fortran examples.

>> Beside not having unmatched if / end if in my code, in a select case construct, I have to write something as ugly as
>> 
>> select case (i)
>> 	case(1) 
>> 		!do something
>> 	case(2)
>> 		!do something else
>> 	case default
>> 		if (0 == 0) then
>> 			SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANG,”invalid value”)
>> end select
>> 
>   What is ugly about this ? except that you put the SETERRQ on a new line which you did not need to do.

Reread the above code.  Requiring the dummy opening if statement is nuts.

>   How do you want to write it so it is prettier?

SETERRQ should not include that endif.  CHKERRQ has the opening if and
thus needs the closing too (so it's as intended).  Also note that your
first reply to Blaise was talking about CHKERRQ when he was asking about
SETERRQ.


More information about the petsc-dev mailing list