147c6ae99SBarry Smith 247c6ae99SBarry Smith /* 347c6ae99SBarry Smith Code for manipulating distributed regular arrays in parallel. 447c6ae99SBarry Smith */ 547c6ae99SBarry Smith 64035e84dSBarry Smith #include <petsc-private/dmdaimpl.h> /*I "petscdmda.h" I*/ 747c6ae99SBarry Smith 847c6ae99SBarry Smith #undef __FUNCT__ 9aa219208SBarry Smith #define __FUNCT__ "DMDAGetGlobalIndices" 1047c6ae99SBarry Smith /*@C 11aa219208SBarry Smith DMDAGetGlobalIndices - Returns the global node number of all local nodes, 1247c6ae99SBarry Smith including ghost nodes. 1347c6ae99SBarry Smith 1447c6ae99SBarry Smith Not Collective 1547c6ae99SBarry Smith 1647c6ae99SBarry Smith Input Parameter: 1747c6ae99SBarry Smith . da - the distributed array 1847c6ae99SBarry Smith 1947c6ae99SBarry Smith Output Parameters: 200298fd71SBarry Smith + n - the number of local elements, including ghost nodes (or NULL) 2147c6ae99SBarry Smith - idx - the global indices 2247c6ae99SBarry Smith 2347c6ae99SBarry Smith Level: intermediate 2447c6ae99SBarry Smith 2547c6ae99SBarry Smith Note: 26aa219208SBarry Smith For DMDA_STENCIL_STAR stencils the inactive corner ghost nodes are also included 2747c6ae99SBarry Smith in the list of local indices (even though those nodes are not updated 28aa219208SBarry Smith during calls to DMDAXXXToXXX(). 2947c6ae99SBarry Smith 3047c6ae99SBarry Smith Essentially the same data is returned in the form of a local-to-global mapping 31aa219208SBarry Smith with the routine DMDAGetISLocalToGlobalMapping(); 3247c6ae99SBarry Smith 3347c6ae99SBarry Smith Fortran Note: 3447c6ae99SBarry Smith This routine is used differently from Fortran 3547c6ae99SBarry Smith .vb 369a42bb27SBarry Smith DM da 3747c6ae99SBarry Smith integer n,da_array(1) 3847c6ae99SBarry Smith PetscOffset i_da 3947c6ae99SBarry Smith integer ierr 40aa219208SBarry Smith call DMDAGetGlobalIndices(da,n,da_array,i_da,ierr) 4147c6ae99SBarry Smith 4247c6ae99SBarry Smith C Access first local entry in list 4347c6ae99SBarry Smith value = da_array(i_da + 1) 4447c6ae99SBarry Smith .ve 4547c6ae99SBarry Smith 4647c6ae99SBarry Smith See the <A href="../../docs/manual.pdf#nameddest=ch_fortran">Fortran chapter</A> of the users manual for details. 4747c6ae99SBarry Smith 4847c6ae99SBarry Smith .keywords: distributed array, get, global, indices, local-to-global 4947c6ae99SBarry Smith 50aa219208SBarry Smith .seealso: DMDACreate2d(), DMDAGetGhostCorners(), DMDAGetCorners(), DMLocalToGlobalBegin() 51aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDALocalToLocalBegin(), DMDAGetAO(), DMDAGetGlobalIndicesF90() 52aa219208SBarry Smith DMDAGetISLocalToGlobalMapping(), DMDACreate3d(), DMDACreate1d(), DMDALocalToLocalEnd(), DMDAGetOwnershipRanges() 5347c6ae99SBarry Smith @*/ 547087cfbeSBarry Smith PetscErrorCode DMDAGetGlobalIndices(DM da,PetscInt *n,PetscInt **idx) 5547c6ae99SBarry Smith { 5647c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 5747c6ae99SBarry Smith 5847c6ae99SBarry Smith PetscFunctionBegin; 5947c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 6047c6ae99SBarry Smith if (n) *n = dd->Nl; 6147c6ae99SBarry Smith if (idx) *idx = dd->idx; 6247c6ae99SBarry Smith PetscFunctionReturn(0); 6347c6ae99SBarry Smith } 6447c6ae99SBarry Smith 6547c6ae99SBarry Smith #undef __FUNCT__ 66aa219208SBarry Smith #define __FUNCT__ "DMDAGetNatural_Private" 6747c6ae99SBarry Smith /* 6847c6ae99SBarry Smith Gets the natural number for each global number on the process. 6947c6ae99SBarry Smith 70aa219208SBarry Smith Used by DMDAGetAO() and DMDAGlobalToNatural_Create() 7147c6ae99SBarry Smith */ 72aa219208SBarry Smith PetscErrorCode DMDAGetNatural_Private(DM da,PetscInt *outNlocal,IS *isnatural) 7347c6ae99SBarry Smith { 7447c6ae99SBarry Smith PetscErrorCode ierr; 7547c6ae99SBarry Smith PetscInt Nlocal,i,j,k,*lidx,lict = 0; 7647c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 7747c6ae99SBarry Smith 7847c6ae99SBarry Smith PetscFunctionBegin; 7947c6ae99SBarry Smith Nlocal = (dd->xe-dd->xs); 808865f1eaSKarl Rupp if (dd->dim > 1) Nlocal *= (dd->ye-dd->ys); 818865f1eaSKarl Rupp if (dd->dim > 2) Nlocal *= (dd->ze-dd->zs); 8247c6ae99SBarry Smith 8347c6ae99SBarry Smith ierr = PetscMalloc(Nlocal*sizeof(PetscInt),&lidx);CHKERRQ(ierr); 8447c6ae99SBarry Smith 8547c6ae99SBarry Smith if (dd->dim == 1) { 8647c6ae99SBarry Smith for (i=dd->xs; i<dd->xe; i++) { 8747c6ae99SBarry Smith /* global number in natural ordering */ 8847c6ae99SBarry Smith lidx[lict++] = i; 8947c6ae99SBarry Smith } 9047c6ae99SBarry Smith } else if (dd->dim == 2) { 9147c6ae99SBarry Smith for (j=dd->ys; j<dd->ye; j++) { 9247c6ae99SBarry Smith for (i=dd->xs; i<dd->xe; i++) { 9347c6ae99SBarry Smith /* global number in natural ordering */ 9447c6ae99SBarry Smith lidx[lict++] = i + j*dd->M*dd->w; 9547c6ae99SBarry Smith } 9647c6ae99SBarry Smith } 9747c6ae99SBarry Smith } else if (dd->dim == 3) { 9847c6ae99SBarry Smith for (k=dd->zs; k<dd->ze; k++) { 9947c6ae99SBarry Smith for (j=dd->ys; j<dd->ye; j++) { 10047c6ae99SBarry Smith for (i=dd->xs; i<dd->xe; i++) { 10147c6ae99SBarry Smith lidx[lict++] = i + j*dd->M*dd->w + k*dd->M*dd->N*dd->w; 10247c6ae99SBarry Smith } 10347c6ae99SBarry Smith } 10447c6ae99SBarry Smith } 10547c6ae99SBarry Smith } 10647c6ae99SBarry Smith *outNlocal = Nlocal; 107ce94432eSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)da),Nlocal,lidx,PETSC_OWN_POINTER,isnatural);CHKERRQ(ierr); 10847c6ae99SBarry Smith PetscFunctionReturn(0); 10947c6ae99SBarry Smith } 11047c6ae99SBarry Smith 11147c6ae99SBarry Smith #undef __FUNCT__ 112aa219208SBarry Smith #define __FUNCT__ "DMDAGetAO" 11347c6ae99SBarry Smith /*@ 114aa219208SBarry Smith DMDAGetAO - Gets the application ordering context for a distributed array. 11547c6ae99SBarry Smith 116aa219208SBarry Smith Collective on DMDA 11747c6ae99SBarry Smith 11847c6ae99SBarry Smith Input Parameter: 11947c6ae99SBarry Smith . da - the distributed array 12047c6ae99SBarry Smith 12147c6ae99SBarry Smith Output Parameters: 122aa219208SBarry Smith . ao - the application ordering context for DMDAs 12347c6ae99SBarry Smith 12447c6ae99SBarry Smith Level: intermediate 12547c6ae99SBarry Smith 12647c6ae99SBarry Smith Notes: 12747c6ae99SBarry Smith In this case, the AO maps to the natural grid ordering that would be used 128aa219208SBarry Smith for the DMDA if only 1 processor were employed (ordering most rapidly in the 12947c6ae99SBarry Smith x-direction, then y, then z). Multiple degrees of freedom are numbered 13047c6ae99SBarry Smith for each node (rather than 1 component for the whole grid, then the next 13147c6ae99SBarry Smith component, etc.) 13247c6ae99SBarry Smith 13347c6ae99SBarry Smith .keywords: distributed array, get, global, indices, local-to-global 13447c6ae99SBarry Smith 135aa219208SBarry Smith .seealso: DMDACreate2d(), DMDAGetGhostCorners(), DMDAGetCorners(), DMDALocalToGlocal() 136aa219208SBarry Smith DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDALocalToLocalBegin(), DMDALocalToLocalEnd(), DMDAGetGlobalIndices(), DMDAGetOwnershipRanges(), 13747c6ae99SBarry Smith AO, AOPetscToApplication(), AOApplicationToPetsc() 13847c6ae99SBarry Smith @*/ 1397087cfbeSBarry Smith PetscErrorCode DMDAGetAO(DM da,AO *ao) 14047c6ae99SBarry Smith { 14147c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 14247c6ae99SBarry Smith 14347c6ae99SBarry Smith PetscFunctionBegin; 14447c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 14547c6ae99SBarry Smith PetscValidPointer(ao,2); 14647c6ae99SBarry Smith 14747c6ae99SBarry Smith /* 14847c6ae99SBarry Smith Build the natural ordering to PETSc ordering mappings. 14947c6ae99SBarry Smith */ 15047c6ae99SBarry Smith if (!dd->ao) { 15147c6ae99SBarry Smith IS ispetsc,isnatural; 15247c6ae99SBarry Smith PetscErrorCode ierr; 15347c6ae99SBarry Smith PetscInt Nlocal; 15447c6ae99SBarry Smith 155aa219208SBarry Smith ierr = DMDAGetNatural_Private(da,&Nlocal,&isnatural);CHKERRQ(ierr); 156ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)da),Nlocal,dd->base,1,&ispetsc);CHKERRQ(ierr); 15747c6ae99SBarry Smith ierr = AOCreateBasicIS(isnatural,ispetsc,&dd->ao);CHKERRQ(ierr); 158*3bb1ff40SBarry Smith ierr = PetscLogObjectParent((PetscObject)da,(PetscObject)dd->ao);CHKERRQ(ierr); 159fcfd50ebSBarry Smith ierr = ISDestroy(&ispetsc);CHKERRQ(ierr); 160fcfd50ebSBarry Smith ierr = ISDestroy(&isnatural);CHKERRQ(ierr); 16147c6ae99SBarry Smith } 16247c6ae99SBarry Smith *ao = dd->ao; 16347c6ae99SBarry Smith PetscFunctionReturn(0); 16447c6ae99SBarry Smith } 16547c6ae99SBarry Smith 16647c6ae99SBarry Smith /*MC 167aa219208SBarry Smith DMDAGetGlobalIndicesF90 - Returns a Fortran90 pointer to the list of 16847c6ae99SBarry Smith global indices (global node number of all local nodes, including 16947c6ae99SBarry Smith ghost nodes). 17047c6ae99SBarry Smith 17147c6ae99SBarry Smith Synopsis: 172aa219208SBarry Smith DMDAGetGlobalIndicesF90(DM da,integer n,{integer, pointer :: idx(:)},integer ierr) 17347c6ae99SBarry Smith 17447c6ae99SBarry Smith Not Collective 17547c6ae99SBarry Smith 17647c6ae99SBarry Smith Input Parameter: 17747c6ae99SBarry Smith . da - the distributed array 17847c6ae99SBarry Smith 17947c6ae99SBarry Smith Output Parameters: 1800298fd71SBarry Smith + n - the number of local elements, including ghost nodes (or NULL) 18147c6ae99SBarry Smith . idx - the Fortran90 pointer to the global indices 18247c6ae99SBarry Smith - ierr - error code 18347c6ae99SBarry Smith 18447c6ae99SBarry Smith Level: intermediate 18547c6ae99SBarry Smith 18647c6ae99SBarry Smith Notes: 18747c6ae99SBarry Smith Not yet supported for all F90 compilers 18847c6ae99SBarry Smith 18947c6ae99SBarry Smith .keywords: distributed array, get, global, indices, local-to-global, f90 19047c6ae99SBarry Smith 191aa219208SBarry Smith .seealso: DMDAGetGlobalIndices() 19247c6ae99SBarry Smith M*/ 193