Date: 2021-03-03T22:26:04+00:00

Actual source code: sfgather.c
petsc-3.14.5 2021-03-03
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 PetscSFBcastAndOpBegin_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:   PetscObjectGetComm((PetscObject)sf,&comm);
     20:   PetscMPIIntCast(sf->nroots,&sendcount);
     21:   PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_../../../../../..2LEAF,&rootbuf,&leafbuf,&req,NULL);
     22:   MPIU_Igather(rootbuf,sendcount,unit,leafbuf,sendcount,unit,0/*rank 0*/,comm,req);
     23:   return(0);
     24: }

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

     36:   PetscSFLinkCreate(sf,unit,rootmtype,rootdata,leafmtype,leafdata,op,PETSCSF_REDUCE,&link);
     37:   PetscSFLinkPackLeafData(sf,link,PETSCSF_REMOTE,leafdata);
     38:   PetscObjectGetComm((PetscObject)sf,&comm);
     39:   PetscMPIIntCast(sf->nroots,&recvcount);
     40:   PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_LEAF2../../../../../..,&rootbuf,&leafbuf,&req,NULL);
     41:   MPIU_Iscatter(leafbuf,recvcount,unit,rootbuf,recvcount,unit,0/*rank 0*/,comm,req);
     42:   return(0);
     43: }

     45: PETSC_INTERN PetscErrorCode PetscSFCreate_Gather(PetscSF sf)
     46: {
     47:   PetscErrorCode  ierr;
     48:   PetscSF_Gather  *dat = (PetscSF_Gather*)sf->data;

     51:   sf->ops->BcastAndOpEnd   = PetscSFBcastAndOpEnd_Basic;
     52:   sf->ops->ReduceEnd       = PetscSFReduceEnd_Basic;

     54:   /* Inherit from Allgatherv */
     55:   sf->ops->Reset           = PetscSFReset_Allgatherv;
     56:   sf->ops->Destroy         = PetscSFDestroy_Allgatherv;
     57:   sf->ops->GetGraph        = PetscSFGetGraph_Allgatherv;
     58:   sf->ops->GetRootRanks    = PetscSFGetRootRanks_Allgatherv;
     59:   sf->ops->GetLeafRanks    = PetscSFGetLeafRanks_Allgatherv;
     60:   sf->ops->FetchAndOpEnd   = PetscSFFetchAndOpEnd_Allgatherv;
     61:   sf->ops->CreateLocalSF   = PetscSFCreateLocalSF_Allgatherv;

     63:   /* Inherit from Allgather */
     64:   sf->ops->SetUp           = PetscSFSetUp_Allgather;

     66:   /* Inherit from Gatherv */
     67:   sf->ops->FetchAndOpBegin = PetscSFFetchAndOpBegin_Gatherv;

     69:   /* Gather stuff */
     70:   sf->ops->BcastAndOpBegin = PetscSFBcastAndOpBegin_Gather;
     71:   sf->ops->ReduceBegin     = PetscSFReduceBegin_Gather;

     73:   PetscNewLog(sf,&dat);
     74:   sf->data = (void*)dat;
     75:   return(0);
     76: }