Actual source code: sfgather.c
petsc-3.15.0 2021-03-30
Report Typos and Errors

      1: #include <../src/vec/is/sf/impls/basic/gatherv/sfgatherv.h>
      2: #include <../src/vec/is/sf/impls/basic/allgather/sfallgather.h>

      4: /* Reuse the type. The difference is some fields (i.e., displs, recvcounts) are not used in Gather, which is not a big deal */
      5: typedef PetscSF_Allgatherv PetscSF_Gather;

      7: PETSC_INTERN PetscErrorCode PetscSFBcastBegin_Gather(PetscSF sf,MPI_Datatype unit,PetscMemType rootmtype,const void *rootdata,PetscMemType leafmtype,void *leafdata,MPI_Op op)
      8: {
      9:   PetscErrorCode       ierr;
     10:   PetscSFLink          link;
     11:   PetscMPIInt          sendcount;
     12:   MPI_Comm             comm;
     13:   void                 *rootbuf = NULL,*leafbuf = NULL;
     14:   MPI_Request          *req;

     17:   PetscSFLinkCreate(sf,unit,rootmtype,rootdata,leafmtype,leafdata,op,PETSCSF_BCAST,&link);
     18:   PetscSFLinkPackRootData(sf,link,PETSCSF_REMOTE,rootdata);
     19:   PetscSFLinkCopyRootBufferInCaseNotUseGpuAwareMPI(sf,link,PETSC_TRUE/* device2host before sending */);
     20:   PetscObjectGetComm((PetscObject)sf,&comm);
     21:   PetscMPIIntCast(sf->nroots,&sendcount);
     22:   PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_../../../../../..2LEAF,&rootbuf,&leafbuf,&req,NULL);
     23:   PetscSFLinkSyncStreamBeforeCallMPI(sf,link,PETSCSF_../../../../../..2LEAF);
     24:   MPIU_Igather(rootbuf,sendcount,unit,leafbuf,sendcount,unit,0/*rank 0*/,comm,req);
     25:   return(0);
     26: }

     28: static PetscErrorCode PetscSFReduceBegin_Gather(PetscSF sf,MPI_Datatype unit,PetscMemType leafmtype,const void *leafdata,PetscMemType rootmtype,void *rootdata,MPI_Op op)
     29: {
     30:   PetscErrorCode       ierr;
     31:   PetscSFLink          link;
     32:   PetscMPIInt          recvcount;
     33:   MPI_Comm             comm;
     34:   void                 *rootbuf = NULL,*leafbuf = NULL;
     35:   MPI_Request          *req;

     38:   PetscSFLinkCreate(sf,unit,rootmtype,rootdata,leafmtype,leafdata,op,PETSCSF_REDUCE,&link);
     39:   PetscSFLinkPackLeafData(sf,link,PETSCSF_REMOTE,leafdata);
     40:   PetscSFLinkCopyLeafBufferInCaseNotUseGpuAwareMPI(sf,link,PETSC_TRUE/* device2host before sending */);
     41:   PetscObjectGetComm((PetscObject)sf,&comm);
     42:   PetscMPIIntCast(sf->nroots,&recvcount);
     43:   PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_LEAF2../../../../../..,&rootbuf,&leafbuf,&req,NULL);
     44:   PetscSFLinkSyncStreamBeforeCallMPI(sf,link,PETSCSF_LEAF2../../../../../..);
     45:   MPIU_Iscatter(leafbuf,recvcount,unit,rootbuf,recvcount,unit,0/*rank 0*/,comm,req);
     46:   return(0);
     47: }

     49: PETSC_INTERN PetscErrorCode PetscSFCreate_Gather(PetscSF sf)
     50: {
     51:   PetscErrorCode  ierr;
     52:   PetscSF_Gather  *dat = (PetscSF_Gather*)sf->data;

     55:   sf->ops->BcastEnd        = PetscSFBcastEnd_Basic;
     56:   sf->ops->ReduceEnd       = PetscSFReduceEnd_Basic;

     58:   /* Inherit from Allgatherv */
     59:   sf->ops->Reset           = PetscSFReset_Allgatherv;
     60:   sf->ops->Destroy         = PetscSFDestroy_Allgatherv;
     61:   sf->ops->GetGraph        = PetscSFGetGraph_Allgatherv;
     62:   sf->ops->GetRootRanks    = PetscSFGetRootRanks_Allgatherv;
     63:   sf->ops->GetLeafRanks    = PetscSFGetLeafRanks_Allgatherv;
     64:   sf->ops->FetchAndOpEnd   = PetscSFFetchAndOpEnd_Allgatherv;
     65:   sf->ops->CreateLocalSF   = PetscSFCreateLocalSF_Allgatherv;

     67:   /* Inherit from Allgather */
     68:   sf->ops->SetUp           = PetscSFSetUp_Allgather;

     70:   /* Inherit from Gatherv */
     71:   sf->ops->FetchAndOpBegin = PetscSFFetchAndOpBegin_Gatherv;

     73:   /* Gather stuff */
     74:   sf->ops->BcastBegin      = PetscSFBcastBegin_Gather;
     75:   sf->ops->ReduceBegin     = PetscSFReduceBegin_Gather;

     77:   PetscNewLog(sf,&dat);
     78:   sf->data = (void*)dat;
     79:   return(0);
     80: }