<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div>  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.<div class=""><br class=""></div><div class="">  Barry</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 13, 2021, at 12:04 PM, Fande Kong <<a href="mailto:fdkong.jd@gmail.com" class="">fdkong.jd@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 12, 2021 at 6:49 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""></div><div class="">   Fande,</div><div class=""><br class=""></div>   /* hope that any still active tags were issued right at the beginning of the run */<div class=""><br class=""></div><div class="">   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. </div><div class=""><br class=""></div><div class="">   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".</div></div></blockquote><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Fande</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""></div><div class="">  Barry</div><div class=""><br class=""></div><div class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 12, 2021, at 10:41 AM, Fande Kong <<a href="mailto:fdkong.jd@gmail.com" target="_blank" class="">fdkong.jd@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Hi All,<br class=""><div class=""><br class=""></div><div class="">I am curious about why we subtract 128 from the max value of tag? Can we directly use the max tag value?</div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Fande,</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">PetscErrorCode  PetscCommGetNewTag(MPI_Comm comm,PetscMPIInt *tag)</div><div class="">{</div><div class="">  PetscErrorCode   ierr;</div><div class="">  PetscCommCounter *counter;</div><div class="">   PetscMPIInt      *maxval,flg;</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">  MPI_Comm_get_attr(comm,Petsc_Counter_keyval,&counter,&flg);</div><div class="">  if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Bad MPI communicator supplied; must be a PETSc communicator");</div><div class=""><br class=""></div><div class=""> if (counter->tag < 1) {</div><div class="">  PetscInfo1(NULL,"Out of tags for object, starting to recycle. Comm reference count %d\n",counter->refcount);</div><div class="">  MPI_Comm_get_attr(MPI_COMM_WORLD,MPI_TAG_UB,&maxval,&flg);</div><div class="">    if (!flg) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"MPI error: MPI_Comm_get_attr() is not returning a MPI_TAG_UB");</div><div class="">   <font color="#ff0000" class=""> counter->tag = *maxval - 128;</font> /* hope that any still active tags were issued right at the beginning of the run */</div><div class="">  }</div><div class=""><br class=""></div><div class="">  *tag = counter->tag--;</div><div class="">   if (PetscDefined(USE_DEBUG)) {</div><div class="">     /*</div><div class="">     Hanging here means that some processes have called PetscCommGetNewTag() and others have not.</div><div class="">      */</div><div class="">    MPI_Barrier(comm);</div><div class="">  }</div><div class="">  return(0);</div><div class="">}</div></div></div></div>
</div></blockquote></div><br class=""></div></div></blockquote></div></div>
</div></blockquote></div><br class=""></div></body></html>