147c6ae99SBarry Smith #define PETSCDM_DLL 247c6ae99SBarry Smith 347c6ae99SBarry Smith /* 447c6ae99SBarry Smith Tools to help solve the coarse grid problem redundantly. 547c6ae99SBarry Smith Provides two scatter contexts that (1) map from the usual global vector 647c6ae99SBarry Smith to all processors the entire vector in NATURAL numbering and (2) 747c6ae99SBarry Smith from the entire vector on each processor in natural numbering extracts 847c6ae99SBarry Smith out this processors piece in GLOBAL numbering 947c6ae99SBarry Smith */ 1047c6ae99SBarry Smith 11e1589f56SBarry Smith #include "private/daimpl.h" /*I "petscdm.h" I*/ 1247c6ae99SBarry Smith 1347c6ae99SBarry Smith #undef __FUNCT__ 14aa219208SBarry Smith #define __FUNCT__ "DMDAGlobalToNaturalAllCreate" 1547c6ae99SBarry Smith /*@ 16aa219208SBarry Smith DMDAGlobalToNaturalAllCreate - Creates a scatter context that maps from the 1747c6ae99SBarry Smith global vector the entire vector to each processor in natural numbering 1847c6ae99SBarry Smith 19aa219208SBarry Smith Collective on DMDA 2047c6ae99SBarry Smith 2147c6ae99SBarry Smith Input Parameter: 2247c6ae99SBarry Smith . da - the distributed array context 2347c6ae99SBarry Smith 2447c6ae99SBarry Smith Output Parameter: 2547c6ae99SBarry Smith . scatter - the scatter context 2647c6ae99SBarry Smith 2747c6ae99SBarry Smith Level: advanced 2847c6ae99SBarry Smith 2947c6ae99SBarry Smith .keywords: distributed array, global to local, begin, coarse problem 3047c6ae99SBarry Smith 31aa219208SBarry Smith .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(), 32aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector() 3347c6ae99SBarry Smith @*/ 34*7087cfbeSBarry Smith PetscErrorCode DMDAGlobalToNaturalAllCreate(DM da,VecScatter *scatter) 3547c6ae99SBarry Smith { 3647c6ae99SBarry Smith PetscErrorCode ierr; 3747c6ae99SBarry Smith PetscInt N; 3847c6ae99SBarry Smith IS from,to; 3947c6ae99SBarry Smith Vec tmplocal,global; 4047c6ae99SBarry Smith AO ao; 4147c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 4247c6ae99SBarry Smith 4347c6ae99SBarry Smith PetscFunctionBegin; 4447c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 4547c6ae99SBarry Smith PetscValidPointer(scatter,2); 46aa219208SBarry Smith ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr); 4747c6ae99SBarry Smith 4847c6ae99SBarry Smith /* create the scatter context */ 4947c6ae99SBarry Smith ierr = VecCreateMPIWithArray(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,0,&global);CHKERRQ(ierr); 5047c6ae99SBarry Smith ierr = VecGetSize(global,&N);CHKERRQ(ierr); 5147c6ae99SBarry Smith ierr = ISCreateStride(((PetscObject)da)->comm,N,0,1,&to);CHKERRQ(ierr); 5247c6ae99SBarry Smith ierr = AOPetscToApplicationIS(ao,to);CHKERRQ(ierr); 5347c6ae99SBarry Smith ierr = ISCreateStride(((PetscObject)da)->comm,N,0,1,&from);CHKERRQ(ierr); 5447c6ae99SBarry Smith ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,N,0,&tmplocal);CHKERRQ(ierr); 5547c6ae99SBarry Smith ierr = VecSetBlockSize(tmplocal,dd->w);CHKERRQ(ierr); 5647c6ae99SBarry Smith ierr = VecSetBlockSize(global,dd->w);CHKERRQ(ierr); 5747c6ae99SBarry Smith ierr = VecScatterCreate(global,from,tmplocal,to,scatter);CHKERRQ(ierr); 5847c6ae99SBarry Smith ierr = VecDestroy(tmplocal);CHKERRQ(ierr); 5947c6ae99SBarry Smith ierr = VecDestroy(global);CHKERRQ(ierr); 6047c6ae99SBarry Smith ierr = ISDestroy(from);CHKERRQ(ierr); 6147c6ae99SBarry Smith ierr = ISDestroy(to);CHKERRQ(ierr); 6247c6ae99SBarry Smith PetscFunctionReturn(0); 6347c6ae99SBarry Smith } 6447c6ae99SBarry Smith 6547c6ae99SBarry Smith #undef __FUNCT__ 66aa219208SBarry Smith #define __FUNCT__ "DMDANaturalAllToGlobalCreate" 6747c6ae99SBarry Smith /*@ 68aa219208SBarry Smith DMDANaturalAllToGlobalCreate - Creates a scatter context that maps from a copy 6947c6ae99SBarry Smith of the entire vector on each processor to its local part in the global vector. 7047c6ae99SBarry Smith 71aa219208SBarry Smith Collective on DMDA 7247c6ae99SBarry Smith 7347c6ae99SBarry Smith Input Parameter: 7447c6ae99SBarry Smith . da - the distributed array context 7547c6ae99SBarry Smith 7647c6ae99SBarry Smith Output Parameter: 7747c6ae99SBarry Smith . scatter - the scatter context 7847c6ae99SBarry Smith 7947c6ae99SBarry Smith Level: advanced 8047c6ae99SBarry Smith 8147c6ae99SBarry Smith .keywords: distributed array, global to local, begin, coarse problem 8247c6ae99SBarry Smith 83aa219208SBarry Smith .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(), 84aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector() 8547c6ae99SBarry Smith @*/ 86*7087cfbeSBarry Smith PetscErrorCode DMDANaturalAllToGlobalCreate(DM da,VecScatter *scatter) 8747c6ae99SBarry Smith { 8847c6ae99SBarry Smith PetscErrorCode ierr; 8947c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 9047c6ae99SBarry Smith PetscInt M,m = dd->Nlocal,start; 9147c6ae99SBarry Smith IS from,to; 9247c6ae99SBarry Smith Vec tmplocal,global; 9347c6ae99SBarry Smith AO ao; 9447c6ae99SBarry Smith 9547c6ae99SBarry Smith PetscFunctionBegin; 9647c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 9747c6ae99SBarry Smith PetscValidPointer(scatter,2); 98aa219208SBarry Smith ierr = DMDAGetAO(da,&ao);CHKERRQ(ierr); 9947c6ae99SBarry Smith 10047c6ae99SBarry Smith /* create the scatter context */ 10147c6ae99SBarry Smith ierr = MPI_Allreduce(&m,&M,1,MPIU_INT,MPI_SUM,((PetscObject)da)->comm);CHKERRQ(ierr); 10247c6ae99SBarry Smith ierr = VecCreateMPIWithArray(((PetscObject)da)->comm,m,PETSC_DETERMINE,0,&global);CHKERRQ(ierr); 10347c6ae99SBarry Smith ierr = VecGetOwnershipRange(global,&start,PETSC_NULL);CHKERRQ(ierr); 10447c6ae99SBarry Smith ierr = ISCreateStride(((PetscObject)da)->comm,m,start,1,&from);CHKERRQ(ierr); 10547c6ae99SBarry Smith ierr = AOPetscToApplicationIS(ao,from);CHKERRQ(ierr); 10647c6ae99SBarry Smith ierr = ISCreateStride(((PetscObject)da)->comm,m,start,1,&to);CHKERRQ(ierr); 10747c6ae99SBarry Smith ierr = VecCreateSeqWithArray(PETSC_COMM_SELF,M,0,&tmplocal);CHKERRQ(ierr); 10847c6ae99SBarry Smith ierr = VecSetBlockSize(tmplocal,dd->w);CHKERRQ(ierr); 10947c6ae99SBarry Smith ierr = VecSetBlockSize(global,dd->w);CHKERRQ(ierr); 11047c6ae99SBarry Smith ierr = VecScatterCreate(tmplocal,from,global,to,scatter);CHKERRQ(ierr); 11147c6ae99SBarry Smith ierr = VecDestroy(tmplocal);CHKERRQ(ierr); 11247c6ae99SBarry Smith ierr = VecDestroy(global);CHKERRQ(ierr); 11347c6ae99SBarry Smith ierr = ISDestroy(from);CHKERRQ(ierr); 11447c6ae99SBarry Smith ierr = ISDestroy(to);CHKERRQ(ierr); 11547c6ae99SBarry Smith PetscFunctionReturn(0); 11647c6ae99SBarry Smith } 11747c6ae99SBarry Smith 118