[petsc-dev] Petsc functions must ALWAYS return error codes

Barry Smith bsmith at mcs.anl.gov
Sun Mar 25 12:20:52 CDT 2012


   Mark,

     Complicated iterators are fine in languages like C++ and Python that can handle error conditions via exceptions.  In C we are stuck using returned values to indicate errors so yes you have to do iterators, for example, in your second example below where you still check error codes for everything (including get next value from iterators).

  Thanks

   Barry



On Mar 25, 2012, at 10:53 AM, Mark F. Adams wrote:

> Barry,
> 
> The iterators are a problem.  THe code now looks like:
> 
> for(pos=PetscCDGetHeadPos(agg_llists,kk) ; 
>     pos ; 
>     pos=PetscCDGetNextPos(agg_llists,kk,pos)){
>   ....
> } 
> 
> I could use:
> 
> ierr = PetscCDGetHeadPos(agg_llists,kk, &pos);
> while( pos ){
> 
>   ...
> 
>  ierr = PetscCDGetNextPos(agg_llists, kk, &pos );
> } 
> 
> Is this what you would like or do you have another API suggestion?
> 
> Mark
> 
> On Mar 24, 2012, at 11:21 PM, Barry Smith wrote:
> 
>> 
>> There are a bunch of these functions that don't return error codes and need to be fixed.
>> 
>>  Barry
>> 
>> PetscInt LLNGetID( const PetscCDIntNd *a_this );
>> PetscErrorCode PetscCDAppendID( PetscCoarsenData *ail, PetscInt a_idx, PetscInt a_gid );
>> PetscErrorCode PetscCDAppendRemove( PetscCoarsenData *ail, PetscInt a_destidx, PetscInt a_srcidx );
>> PetscErrorCode PetscCDAppendNode( PetscCoarsenData *ail, PetscInt a_idx,  PetscCDIntNd *a_n );
>> PetscErrorCode PetscCDRemoveNextNode( PetscCoarsenData *ail, PetscInt a_idx, PetscCDIntNd *a_last );
>> PetscErrorCode PetscCDRemoveAllAt( PetscCoarsenData *ail, PetscInt a_idx );
>> PetscInt PetscCDSizeAt( const PetscCoarsenData *ail, PetscInt a_idx );
>> PetscErrorCode PetscCDSetChuckSize( PetscCoarsenData *ail, PetscInt a_sz );
>> PetscErrorCode PetscCDPrint( const PetscCoarsenData *ail, MPI_Comm comm  );
>> PetscErrorCode PetscCDGetMIS( PetscCoarsenData *ail, IS * );
>> PetscErrorCode PetscCDGetMat( const PetscCoarsenData *ail, Mat * );
>> PetscErrorCode PetscCDSetMat( PetscCoarsenData *ail, Mat );
>> typedef PetscCDIntNd* PetscCDPos;
>> const PetscCDPos PetscCDGetHeadPos( const PetscCoarsenData *ail, PetscInt idx );
>> const PetscCDPos PetscCDGetNextPos( const PetscCoarsenData *ail, PetscInt idx, PetscCDPos cpos);
>> 
>> 
>> 
>> 
> 




More information about the petsc-dev mailing list