147c6ae99SBarry Smith 247c6ae99SBarry Smith /* 347c6ae99SBarry Smith Tools to help solve the coarse grid problem redundantly. 447c6ae99SBarry Smith Provides two scatter contexts that (1) map from the usual global vector 547c6ae99SBarry Smith to all processors the entire vector in NATURAL numbering and (2) 647c6ae99SBarry Smith from the entire vector on each processor in natural numbering extracts 747c6ae99SBarry Smith out this processors piece in GLOBAL numbering 847c6ae99SBarry Smith */ 947c6ae99SBarry Smith 10b45d2f2cSJed Brown #include <petsc-private/daimpl.h> /*I "petscdmda.h" I*/ 1147c6ae99SBarry Smith 1247c6ae99SBarry Smith #undef __FUNCT__ 13aa219208SBarry Smith #define __FUNCT__ "DMDAGlobalToNaturalAllCreate" 1447c6ae99SBarry Smith /*@ 15aa219208SBarry Smith DMDAGlobalToNaturalAllCreate - Creates a scatter context that maps from the 1647c6ae99SBarry Smith global vector the entire vector to each processor in natural numbering 1747c6ae99SBarry Smith 18aa219208SBarry Smith Collective on DMDA 1947c6ae99SBarry Smith 2047c6ae99SBarry Smith Input Parameter: 2147c6ae99SBarry Smith . da - the distributed array context 2247c6ae99SBarry Smith 2347c6ae99SBarry Smith Output Parameter: 2447c6ae99SBarry Smith . scatter - the scatter context 2547c6ae99SBarry Smith 2647c6ae99SBarry Smith Level: advanced 2747c6ae99SBarry Smith 2847c6ae99SBarry Smith .keywords: distributed array, global to local, begin, coarse problem 2947c6ae99SBarry Smith 30aa219208SBarry Smith .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(), 31aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector() 3247c6ae99SBarry Smith @*/ 337087cfbeSBarry Smith PetscErrorCode DMDAGlobalToNaturalAllCreate(DM da,VecScatter *scatter) 3447c6ae99SBarry Smith { 3547c6ae99SBarry Smith PetscErrorCode ierr; 3647c6ae99SBarry Smith PetscInt N; 3747c6ae99SBarry Smith IS from,to; 3847c6ae99SBarry Smith Vec tmplocal,global; 3947c6ae99SBarry Smith AO ao; 4047c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 4147c6ae99SBarry Smith 4247c6ae99SBarry Smith PetscFunctionBegin; 4347c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 4447c6ae99SBarry Smith PetscValidPointer(scatter,2); 45aa219208SBarry Smith ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr); 4647c6ae99SBarry Smith 4747c6ae99SBarry Smith /* create the scatter context */ 48*ce94432eSBarry Smith ierr = VecCreateMPIWithArray(PetscObjectComm((PetscObject)da),dd->w,dd->Nlocal,PETSC_DETERMINE,0,&global);CHKERRQ(ierr); 4947c6ae99SBarry Smith ierr = VecGetSize(global,&N);CHKERRQ(ierr); 50*ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&to);CHKERRQ(ierr); 5147c6ae99SBarry Smith ierr = AOPetscToApplicationIS(ao,to);CHKERRQ(ierr); 52*ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&from);CHKERRQ(ierr); 53778a2246SBarry Smith ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,dd->w,N,0,&tmplocal);CHKERRQ(ierr); 5447c6ae99SBarry Smith ierr = VecScatterCreate(global,from,tmplocal,to,scatter);CHKERRQ(ierr); 55fcfd50ebSBarry Smith ierr = VecDestroy(&tmplocal);CHKERRQ(ierr); 56fcfd50ebSBarry Smith ierr = VecDestroy(&global);CHKERRQ(ierr); 57fcfd50ebSBarry Smith ierr = ISDestroy(&from);CHKERRQ(ierr); 58fcfd50ebSBarry Smith ierr = ISDestroy(&to);CHKERRQ(ierr); 5947c6ae99SBarry Smith PetscFunctionReturn(0); 6047c6ae99SBarry Smith } 6147c6ae99SBarry Smith 6247c6ae99SBarry Smith #undef __FUNCT__ 63aa219208SBarry Smith #define __FUNCT__ "DMDANaturalAllToGlobalCreate" 6447c6ae99SBarry Smith /*@ 65aa219208SBarry Smith DMDANaturalAllToGlobalCreate - Creates a scatter context that maps from a copy 6647c6ae99SBarry Smith of the entire vector on each processor to its local part in the global vector. 6747c6ae99SBarry Smith 68aa219208SBarry Smith Collective on DMDA 6947c6ae99SBarry Smith 7047c6ae99SBarry Smith Input Parameter: 7147c6ae99SBarry Smith . da - the distributed array context 7247c6ae99SBarry Smith 7347c6ae99SBarry Smith Output Parameter: 7447c6ae99SBarry Smith . scatter - the scatter context 7547c6ae99SBarry Smith 7647c6ae99SBarry Smith Level: advanced 7747c6ae99SBarry Smith 7847c6ae99SBarry Smith .keywords: distributed array, global to local, begin, coarse problem 7947c6ae99SBarry Smith 80aa219208SBarry Smith .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(), 81aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector() 8247c6ae99SBarry Smith @*/ 837087cfbeSBarry Smith PetscErrorCode DMDANaturalAllToGlobalCreate(DM da,VecScatter *scatter) 8447c6ae99SBarry Smith { 8547c6ae99SBarry Smith PetscErrorCode ierr; 8647c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 8747c6ae99SBarry Smith PetscInt M,m = dd->Nlocal,start; 8847c6ae99SBarry Smith IS from,to; 8947c6ae99SBarry Smith Vec tmplocal,global; 9047c6ae99SBarry Smith AO ao; 9147c6ae99SBarry Smith 9247c6ae99SBarry Smith PetscFunctionBegin; 9347c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 9447c6ae99SBarry Smith PetscValidPointer(scatter,2); 95aa219208SBarry Smith ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr); 9647c6ae99SBarry Smith 9747c6ae99SBarry Smith /* create the scatter context */ 98*ce94432eSBarry Smith ierr = MPI_Allreduce(&m,&M,1,MPIU_INT,MPI_SUM,PetscObjectComm((PetscObject)da));CHKERRQ(ierr); 99*ce94432eSBarry Smith ierr = VecCreateMPIWithArray(PetscObjectComm((PetscObject)da),dd->w,m,PETSC_DETERMINE,0,&global);CHKERRQ(ierr); 1000298fd71SBarry Smith ierr = VecGetOwnershipRange(global,&start,NULL);CHKERRQ(ierr); 101*ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)da),m,start,1,&from);CHKERRQ(ierr); 10247c6ae99SBarry Smith ierr = AOPetscToApplicationIS(ao,from);CHKERRQ(ierr); 103*ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)da),m,start,1,&to);CHKERRQ(ierr); 104778a2246SBarry Smith ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,dd->w,M,0,&tmplocal);CHKERRQ(ierr); 10547c6ae99SBarry Smith ierr = VecScatterCreate(tmplocal,from,global,to,scatter);CHKERRQ(ierr); 106fcfd50ebSBarry Smith ierr = VecDestroy(&tmplocal);CHKERRQ(ierr); 107fcfd50ebSBarry Smith ierr = VecDestroy(&global);CHKERRQ(ierr); 108fcfd50ebSBarry Smith ierr = ISDestroy(&from);CHKERRQ(ierr); 109fcfd50ebSBarry Smith ierr = ISDestroy(&to);CHKERRQ(ierr); 11047c6ae99SBarry Smith PetscFunctionReturn(0); 11147c6ae99SBarry Smith } 11247c6ae99SBarry Smith 113