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__ 92dcb2ebcSBarry Smith #define __FUNCT__ "VecDuplicate_MPI_DA" 107087cfbeSBarry Smith PetscErrorCode VecDuplicate_MPI_DA(Vec g,Vec *gg) 112dcb2ebcSBarry Smith { 122dcb2ebcSBarry Smith PetscErrorCode ierr; 132dcb2ebcSBarry Smith DM da; 14077aedafSJed Brown PetscLayout map; 152dcb2ebcSBarry Smith 162dcb2ebcSBarry Smith PetscFunctionBegin; 17c688c046SMatthew G Knepley ierr = VecGetDM(g, &da);CHKERRQ(ierr); 182dcb2ebcSBarry Smith ierr = DMCreateGlobalVector(da,gg);CHKERRQ(ierr); 19077aedafSJed Brown ierr = VecGetLayout(g,&map);CHKERRQ(ierr); 20077aedafSJed Brown ierr = VecSetLayout(*gg,map);CHKERRQ(ierr); 212dcb2ebcSBarry Smith PetscFunctionReturn(0); 222dcb2ebcSBarry Smith } 232dcb2ebcSBarry Smith 242dcb2ebcSBarry Smith 252dcb2ebcSBarry Smith #undef __FUNCT__ 26564755cdSBarry Smith #define __FUNCT__ "DMCreateGlobalVector_DA" 277087cfbeSBarry Smith PetscErrorCode DMCreateGlobalVector_DA(DM da,Vec *g) 2847c6ae99SBarry Smith { 2947c6ae99SBarry Smith PetscErrorCode ierr; 3047c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 3147c6ae99SBarry Smith 3247c6ae99SBarry Smith PetscFunctionBegin; 3347c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 3447c6ae99SBarry Smith PetscValidPointer(g,2); 3511689aebSJed Brown if (da->defaultSection) { 3611689aebSJed Brown ierr = DMCreateGlobalVector_Section_Private(da,g);CHKERRQ(ierr); 37*20001361SMatthew G. Knepley /* The view and load functions break for general layouts */ 38*20001361SMatthew G. Knepley PetscFunctionReturn(0); 3911689aebSJed Brown } else { 40ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)da),g);CHKERRQ(ierr); 4147c6ae99SBarry Smith ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr); 42401ddaa8SBarry Smith ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr); 4347c6ae99SBarry Smith ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr); 441ca04561SShri Abhyankar ierr = VecSetFromOptions(*g);CHKERRQ(ierr); 45c688c046SMatthew G Knepley ierr = VecSetDM(*g, da);CHKERRQ(ierr); 461411c6eeSJed Brown ierr = VecSetLocalToGlobalMapping(*g,da->ltogmap);CHKERRQ(ierr); 471411c6eeSJed Brown ierr = VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);CHKERRQ(ierr); 4811689aebSJed Brown } 4947c6ae99SBarry Smith ierr = VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);CHKERRQ(ierr); 5047c6ae99SBarry Smith ierr = VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);CHKERRQ(ierr); 512dcb2ebcSBarry Smith ierr = VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);CHKERRQ(ierr); 5247c6ae99SBarry Smith PetscFunctionReturn(0); 5347c6ae99SBarry Smith } 5447c6ae99SBarry Smith 5547c6ae99SBarry Smith #undef __FUNCT__ 56aa219208SBarry Smith #define __FUNCT__ "DMDACreateNaturalVector" 5747c6ae99SBarry Smith /*@ 58aa219208SBarry Smith DMDACreateNaturalVector - Creates a parallel PETSc vector that 5947c6ae99SBarry Smith will hold vector values in the natural numbering, rather than in 60aa219208SBarry Smith the PETSc parallel numbering associated with the DMDA. 6147c6ae99SBarry Smith 62aa219208SBarry Smith Collective on DMDA 6347c6ae99SBarry Smith 6447c6ae99SBarry Smith Input Parameter: 6547c6ae99SBarry Smith . da - the distributed array 6647c6ae99SBarry Smith 6747c6ae99SBarry Smith Output Parameter: 6847c6ae99SBarry Smith . g - the distributed global vector 6947c6ae99SBarry Smith 7047c6ae99SBarry Smith Level: developer 7147c6ae99SBarry Smith 7247c6ae99SBarry Smith Note: 7347c6ae99SBarry Smith The output parameter, g, is a regular PETSc vector that should be destroyed 7447c6ae99SBarry Smith with a call to VecDestroy() when usage is finished. 7547c6ae99SBarry Smith 7647c6ae99SBarry Smith The number of local entries in the vector on each process is the same 77564755cdSBarry Smith as in a vector created with DMCreateGlobalVector(). 7847c6ae99SBarry Smith 7947c6ae99SBarry Smith .keywords: distributed array, create, global, distributed, vector 8047c6ae99SBarry Smith 81564755cdSBarry Smith .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(), 82aa219208SBarry Smith DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(), 83aa219208SBarry Smith DMGlobalToLocalEnd(), DMDALocalToGlobalBegin() 8447c6ae99SBarry Smith @*/ 857087cfbeSBarry Smith PetscErrorCode DMDACreateNaturalVector(DM da,Vec *g) 8647c6ae99SBarry Smith { 8747c6ae99SBarry Smith PetscErrorCode ierr; 8847c6ae99SBarry Smith PetscInt cnt; 8947c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 9047c6ae99SBarry Smith 9147c6ae99SBarry Smith PetscFunctionBegin; 9247c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 9347c6ae99SBarry Smith PetscValidPointer(g,2); 9447c6ae99SBarry Smith if (dd->natural) { 9547c6ae99SBarry Smith ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr); 9647c6ae99SBarry Smith if (cnt == 1) { /* object is not currently used by anyone */ 9747c6ae99SBarry Smith ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr); 9847c6ae99SBarry Smith *g = dd->natural; 9947c6ae99SBarry Smith } else { 10047c6ae99SBarry Smith ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr); 10147c6ae99SBarry Smith } 10247c6ae99SBarry Smith } else { /* create the first version of this guy */ 103ce94432eSBarry Smith ierr = VecCreate(PetscObjectComm((PetscObject)da),g);CHKERRQ(ierr); 104a34bdc0bSBarry Smith ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr); 10547c6ae99SBarry Smith ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr); 106a34bdc0bSBarry Smith ierr = VecSetType(*g,VECMPI);CHKERRQ(ierr); 10747c6ae99SBarry Smith ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr); 1088865f1eaSKarl Rupp 10947c6ae99SBarry Smith dd->natural = *g; 11047c6ae99SBarry Smith } 11147c6ae99SBarry Smith PetscFunctionReturn(0); 11247c6ae99SBarry Smith } 11347c6ae99SBarry Smith 11447c6ae99SBarry Smith 11547c6ae99SBarry Smith 116