Re: [petsc-users] counter->tag = *maxval - 128

2021-01-13 Thread Barry Smith

  Yes, definitely not easy to debug. If you have concerns in your code about 
running out and then producing bugs you can fix it  by just keeping an array of 
returned tags and use these tags when needed. You'll also have to add something 
like PetscObject/CommRestoreTag() to return ones no longer needed.

  Barry

> On Jan 13, 2021, at 12:04 PM, Fande Kong  wrote:
> 
> 
> 
> On Tue, Jan 12, 2021 at 6:49 PM Barry Smith  > wrote:
> 
>Fande,
> 
>/* hope that any still active tags were issued right at the beginning of 
> the run */
> 
>PETSc actually starts with *maxval (see line 130). It is only when it runs 
> out that it does this silly thing for the reason indicated in the comment. 
> 
>PETSc should actually keep track which of which tags have been "returned" 
> and if the counter gets to zero use those returned tags instead of starting 
> again at the top which could clash with the same value used for another 
> reason. In other words the current code is buggy,  but it has always been 
> "good enough".
> 
> I agreed that it is "good enough" for most people for most cases. However, I 
> was worried that there is almost no way to debug once we reuse active tags. 
> At least it is not easy to debug.
> 
> Thanks,
> 
> Fande
>  
> 
>   Barry
> 
> 
> 
>> On Jan 12, 2021, at 10:41 AM, Fande Kong > > wrote:
>> 
>> Hi All,
>> 
>> I am curious about why we subtract 128 from the max value of tag? Can we 
>> directly use the max tag value?
>> 
>> Thanks,
>> 
>> Fande,
>> 
>> 
>> PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)
>> {
>>   PetscErrorCode   ierr;
>>   PetscCommCounter *counter;
>>PetscMPIInt  *maxval,flg;
>> 
>> 
>>   MPI_Comm_get_attr(comm,Petsc_Counter_keyval,,);
>>   if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI 
>> communicator supplied; must be a PETSc communicator");
>> 
>>  if (counter->tag < 1) {
>>   PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm 
>> reference count %d\n",counter->refcount);
>>   MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,,);
>> if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error: 
>> MPI_Comm_get_attr() is not returning a MPI_TAG_UB");
>> counter->tag = *maxval - 128; /* hope that any still active tags were 
>> issued right at the beginning of the run */
>>   }
>> 
>>   *tag = counter->tag--;
>>if (PetscDefined(USE_DEBUG)) {
>>  /*
>>  Hanging here means that some processes have called PetscCommGetNewTag() 
>> and others have not.
>>   */
>> MPI_Barrier(comm);
>>   }
>>   return(0);
>> }
> 



Re: [petsc-users] counter->tag = *maxval - 128

2021-01-13 Thread Fande Kong
On Tue, Jan 12, 2021 at 6:49 PM Barry Smith  wrote:

>
>Fande,
>
>/* hope that any still active tags were issued right at the beginning
> of the run */
>
>PETSc actually starts with *maxval (see line 130). It is only when it
> runs out that it does this silly thing for the reason indicated in the
> comment.
>
>PETSc should actually keep track which of which tags have been
> "returned" and if the counter gets to zero use those returned tags instead
> of starting again at the top which could clash with the same value used for
> another reason. In other words the current code is buggy,  but it has
> always been "good enough".
>

I agreed that it is "good enough" for most people for most cases. However,
I was worried that there is almost no way to debug once we reuse active
tags. At least it is not easy to debug.

Thanks,

Fande


>
>   Barry
>
>
>
> On Jan 12, 2021, at 10:41 AM, Fande Kong  wrote:
>
> Hi All,
>
> I am curious about why we subtract 128 from the max value of tag? Can we
> directly use the max tag value?
>
> Thanks,
>
> Fande,
>
>
> PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)
> {
>   PetscErrorCode   ierr;
>   PetscCommCounter *counter;
>PetscMPIInt  *maxval,flg;
>
>
>   MPI_Comm_get_attr(comm,Petsc_Counter_keyval,,);
>   if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI
> communicator supplied; must be a PETSc communicator");
>
>  if (counter->tag < 1) {
>   PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm
> reference count %d\n",counter->refcount);
>   MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,,);
> if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error:
> MPI_Comm_get_attr() is not returning a MPI_TAG_UB");
> counter->tag = *maxval - 128; /* hope that any still active tags were
> issued right at the beginning of the run */
>   }
>
>   *tag = counter->tag--;
>if (PetscDefined(USE_DEBUG)) {
>  /*
>  Hanging here means that some processes have called
> PetscCommGetNewTag() and others have not.
>   */
> MPI_Barrier(comm);
>   }
>   return(0);
> }
>
>
>


Re: [petsc-users] counter->tag = *maxval - 128

2021-01-12 Thread Barry Smith

   Fande,

   /* hope that any still active tags were issued right at the beginning of the 
run */

   PETSc actually starts with *maxval (see line 130). It is only when it runs 
out that it does this silly thing for the reason indicated in the comment. 

   PETSc should actually keep track which of which tags have been "returned" 
and if the counter gets to zero use those returned tags instead of starting 
again at the top which could clash with the same value used for another reason. 
In other words the current code is buggy,  but it has always been "good enough".

  Barry



> On Jan 12, 2021, at 10:41 AM, Fande Kong  wrote:
> 
> Hi All,
> 
> I am curious about why we subtract 128 from the max value of tag? Can we 
> directly use the max tag value?
> 
> Thanks,
> 
> Fande,
> 
> 
> PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)
> {
>   PetscErrorCode   ierr;
>   PetscCommCounter *counter;
>PetscMPIInt  *maxval,flg;
> 
> 
>   MPI_Comm_get_attr(comm,Petsc_Counter_keyval,,);
>   if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI 
> communicator supplied; must be a PETSc communicator");
> 
>  if (counter->tag < 1) {
>   PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm 
> reference count %d\n",counter->refcount);
>   MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,,);
> if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error: 
> MPI_Comm_get_attr() is not returning a MPI_TAG_UB");
> counter->tag = *maxval - 128; /* hope that any still active tags were 
> issued right at the beginning of the run */
>   }
> 
>   *tag = counter->tag--;
>if (PetscDefined(USE_DEBUG)) {
>  /*
>  Hanging here means that some processes have called PetscCommGetNewTag() 
> and others have not.
>   */
> MPI_Barrier(comm);
>   }
>   return(0);
> }



Re: [petsc-users] counter->tag = *maxval - 128

2021-01-12 Thread Junchao Zhang
I think you can, if you always use PetscCommGetNewTag() to get a tag for
use with a PetscComm.

The -128 is to avoid wrong usages that someone provided their own tag from
the maximal.

--Junchao Zhang


On Tue, Jan 12, 2021 at 10:42 AM Fande Kong  wrote:

> Hi All,
>
> I am curious about why we subtract 128 from the max value of tag? Can we
> directly use the max tag value?
>
> Thanks,
>
> Fande,
>
>
> PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)
> {
>   PetscErrorCode   ierr;
>   PetscCommCounter *counter;
>PetscMPIInt  *maxval,flg;
>
>
>   MPI_Comm_get_attr(comm,Petsc_Counter_keyval,,);
>   if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI
> communicator supplied; must be a PETSc communicator");
>
>  if (counter->tag < 1) {
>   PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm
> reference count %d\n",counter->refcount);
>   MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,,);
> if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error:
> MPI_Comm_get_attr() is not returning a MPI_TAG_UB");
> counter->tag = *maxval - 128; /* hope that any still active tags were
> issued right at the beginning of the run */
>   }
>
>   *tag = counter->tag--;
>if (PetscDefined(USE_DEBUG)) {
>  /*
>  Hanging here means that some processes have called
> PetscCommGetNewTag() and others have not.
>   */
> MPI_Barrier(comm);
>   }
>   return(0);
> }
>


[petsc-users] counter->tag = *maxval - 128

2021-01-12 Thread Fande Kong
Hi All,

I am curious about why we subtract 128 from the max value of tag? Can we
directly use the max tag value?

Thanks,

Fande,


PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)
{
  PetscErrorCode   ierr;
  PetscCommCounter *counter;
   PetscMPIInt  *maxval,flg;


  MPI_Comm_get_attr(comm,Petsc_Counter_keyval,,);
  if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI
communicator supplied; must be a PETSc communicator");

 if (counter->tag < 1) {
  PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm
reference count %d\n",counter->refcount);
  MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,,);
if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error:
MPI_Comm_get_attr() is not returning a MPI_TAG_UB");
counter->tag = *maxval - 128; /* hope that any still active tags were
issued right at the beginning of the run */
  }

  *tag = counter->tag--;
   if (PetscDefined(USE_DEBUG)) {
 /*
 Hanging here means that some processes have called
PetscCommGetNewTag() and others have not.
  */
MPI_Barrier(comm);
  }
  return(0);
}