1 #include <../src/vec/is/sf/impls/basic/gatherv/sfgatherv.h> 2 #include <../src/vec/is/sf/impls/basic/allgather/sfallgather.h> 3 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; 6 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; 15 16 PetscFunctionBegin; 17 ierr = PetscSFLinkCreate(sf,unit,rootmtype,rootdata,leafmtype,leafdata,op,PETSCSF_BCAST,&link);CHKERRQ(ierr); 18 ierr = PetscSFLinkPackRootData(sf,link,PETSCSF_REMOTE,rootdata);CHKERRQ(ierr); 19 ierr = PetscObjectGetComm((PetscObject)sf,&comm);CHKERRQ(ierr); 20 ierr = PetscMPIIntCast(sf->nroots,&sendcount);CHKERRQ(ierr); 21 ierr = PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_ROOT2LEAF,&rootbuf,&leafbuf,&req,NULL);CHKERRQ(ierr); 22 ierr = MPIU_Igather(rootbuf,sendcount,unit,leafbuf,sendcount,unit,0/*rank 0*/,comm,req);CHKERRQ(ierr); 23 PetscFunctionReturn(0); 24 } 25 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; 34 35 PetscFunctionBegin; 36 ierr = PetscSFLinkCreate(sf,unit,rootmtype,rootdata,leafmtype,leafdata,op,PETSCSF_REDUCE,&link);CHKERRQ(ierr); 37 ierr = PetscSFLinkPackLeafData(sf,link,PETSCSF_REMOTE,leafdata);CHKERRQ(ierr); 38 ierr = PetscObjectGetComm((PetscObject)sf,&comm);CHKERRQ(ierr); 39 ierr = PetscMPIIntCast(sf->nroots,&recvcount);CHKERRQ(ierr); 40 ierr = PetscSFLinkGetMPIBuffersAndRequests(sf,link,PETSCSF_LEAF2ROOT,&rootbuf,&leafbuf,&req,NULL);CHKERRQ(ierr); 41 ierr = MPIU_Iscatter(leafbuf,recvcount,unit,rootbuf,recvcount,unit,0/*rank 0*/,comm,req);CHKERRQ(ierr); 42 PetscFunctionReturn(0); 43 } 44 45 PETSC_INTERN PetscErrorCode PetscSFCreate_Gather(PetscSF sf) 46 { 47 PetscErrorCode ierr; 48 PetscSF_Gather *dat = (PetscSF_Gather*)sf->data; 49 50 PetscFunctionBegin; 51 sf->ops->BcastAndOpEnd = PetscSFBcastAndOpEnd_Basic; 52 sf->ops->ReduceEnd = PetscSFReduceEnd_Basic; 53 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; 62 63 /* Inherit from Allgather */ 64 sf->ops->SetUp = PetscSFSetUp_Allgather; 65 66 /* Inherit from Gatherv */ 67 sf->ops->FetchAndOpBegin = PetscSFFetchAndOpBegin_Gatherv; 68 69 /* Gather stuff */ 70 sf->ops->BcastAndOpBegin = PetscSFBcastAndOpBegin_Gather; 71 sf->ops->ReduceBegin = PetscSFReduceBegin_Gather; 72 73 ierr = PetscNewLog(sf,&dat);CHKERRQ(ierr); 74 sf->data = (void*)dat; 75 PetscFunctionReturn(0); 76 } 77 78