1*47c6ae99SBarry Smith #define PETSCDM_DLL 2*47c6ae99SBarry Smith 3*47c6ae99SBarry Smith /* 4*47c6ae99SBarry Smith Code for manipulating distributed regular arrays in parallel. 5*47c6ae99SBarry Smith */ 6*47c6ae99SBarry Smith 7*47c6ae99SBarry Smith #include "private/daimpl.h" /*I "petscda.h" I*/ 8*47c6ae99SBarry Smith 9*47c6ae99SBarry Smith #undef __FUNCT__ 10*47c6ae99SBarry Smith #define __FUNCT__ "DACreateGlobalVector" 11*47c6ae99SBarry Smith /*@ 12*47c6ae99SBarry Smith DACreateGlobalVector - Creates a parallel PETSc vector that 13*47c6ae99SBarry Smith may be used with the DAXXX routines. 14*47c6ae99SBarry Smith 15*47c6ae99SBarry Smith Collective on DA 16*47c6ae99SBarry Smith 17*47c6ae99SBarry Smith Input Parameter: 18*47c6ae99SBarry Smith . da - the distributed array 19*47c6ae99SBarry Smith 20*47c6ae99SBarry Smith Output Parameter: 21*47c6ae99SBarry Smith . g - the distributed global vector 22*47c6ae99SBarry Smith 23*47c6ae99SBarry Smith Level: beginner 24*47c6ae99SBarry Smith 25*47c6ae99SBarry Smith Note: 26*47c6ae99SBarry Smith The output parameter, g, is a regular PETSc vector that should be destroyed 27*47c6ae99SBarry Smith with a call to VecDestroy() when usage is finished. 28*47c6ae99SBarry Smith 29*47c6ae99SBarry Smith When you view this vector (or one obtained via VecDuplicate()) it is printed in the global natural ordering NOT 30*47c6ae99SBarry Smith in the PETSc parallel global ordering that is used internally. Similarly VecLoad() into this vector loads from a global natural ordering. 31*47c6ae99SBarry Smith This means that vectors saved to disk from one DA parallel distribution can be reloaded into a different DA parallel distribution correctly. 32*47c6ae99SBarry Smith 33*47c6ae99SBarry Smith .keywords: distributed array, create, global, distributed, vector 34*47c6ae99SBarry Smith 35*47c6ae99SBarry Smith .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(), 36*47c6ae99SBarry Smith DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(), 37*47c6ae99SBarry Smith DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateNaturalVector() 38*47c6ae99SBarry Smith @*/ 39*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DACreateGlobalVector(DA da,Vec* g) 40*47c6ae99SBarry Smith { 41*47c6ae99SBarry Smith PetscErrorCode ierr; 42*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 43*47c6ae99SBarry Smith 44*47c6ae99SBarry Smith PetscFunctionBegin; 45*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 46*47c6ae99SBarry Smith PetscValidPointer(g,2); 47*47c6ae99SBarry Smith ierr = VecCreate(((PetscObject)da)->comm,g);CHKERRQ(ierr); 48*47c6ae99SBarry Smith ierr = VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);CHKERRQ(ierr); 49*47c6ae99SBarry Smith ierr = VecSetType(*g,da->vectype);CHKERRQ(ierr); 50*47c6ae99SBarry Smith ierr = PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);CHKERRQ(ierr); 51*47c6ae99SBarry Smith ierr = VecSetLocalToGlobalMapping(*g,dd->ltogmap);CHKERRQ(ierr); 52*47c6ae99SBarry Smith ierr = VecSetLocalToGlobalMappingBlock(*g,dd->ltogmapb);CHKERRQ(ierr); 53*47c6ae99SBarry Smith ierr = VecSetBlockSize(*g,dd->w);CHKERRQ(ierr); 54*47c6ae99SBarry Smith ierr = VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);CHKERRQ(ierr); 55*47c6ae99SBarry Smith ierr = VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);CHKERRQ(ierr); 56*47c6ae99SBarry Smith PetscFunctionReturn(0); 57*47c6ae99SBarry Smith } 58*47c6ae99SBarry Smith 59*47c6ae99SBarry Smith #undef __FUNCT__ 60*47c6ae99SBarry Smith #define __FUNCT__ "DACreateNaturalVector" 61*47c6ae99SBarry Smith /*@ 62*47c6ae99SBarry Smith DACreateNaturalVector - Creates a parallel PETSc vector that 63*47c6ae99SBarry Smith will hold vector values in the natural numbering, rather than in 64*47c6ae99SBarry Smith the PETSc parallel numbering associated with the DA. 65*47c6ae99SBarry Smith 66*47c6ae99SBarry Smith Collective on DA 67*47c6ae99SBarry Smith 68*47c6ae99SBarry Smith Input Parameter: 69*47c6ae99SBarry Smith . da - the distributed array 70*47c6ae99SBarry Smith 71*47c6ae99SBarry Smith Output Parameter: 72*47c6ae99SBarry Smith . g - the distributed global vector 73*47c6ae99SBarry Smith 74*47c6ae99SBarry Smith Level: developer 75*47c6ae99SBarry Smith 76*47c6ae99SBarry Smith Note: 77*47c6ae99SBarry Smith The output parameter, g, is a regular PETSc vector that should be destroyed 78*47c6ae99SBarry Smith with a call to VecDestroy() when usage is finished. 79*47c6ae99SBarry Smith 80*47c6ae99SBarry Smith The number of local entries in the vector on each process is the same 81*47c6ae99SBarry Smith as in a vector created with DACreateGlobalVector(). 82*47c6ae99SBarry Smith 83*47c6ae99SBarry Smith .keywords: distributed array, create, global, distributed, vector 84*47c6ae99SBarry Smith 85*47c6ae99SBarry Smith .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(), 86*47c6ae99SBarry Smith DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(), 87*47c6ae99SBarry Smith DAGlobalToLocalEnd(), DALocalToGlobal() 88*47c6ae99SBarry Smith @*/ 89*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT DACreateNaturalVector(DA da,Vec* g) 90*47c6ae99SBarry Smith { 91*47c6ae99SBarry Smith PetscErrorCode ierr; 92*47c6ae99SBarry Smith PetscInt cnt; 93*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 94*47c6ae99SBarry Smith 95*47c6ae99SBarry Smith PetscFunctionBegin; 96*47c6ae99SBarry Smith PetscValidHeaderSpecific(da,DM_CLASSID,1); 97*47c6ae99SBarry Smith PetscValidPointer(g,2); 98*47c6ae99SBarry Smith if (dd->natural) { 99*47c6ae99SBarry Smith ierr = PetscObjectGetReference((PetscObject)dd->natural,&cnt);CHKERRQ(ierr); 100*47c6ae99SBarry Smith if (cnt == 1) { /* object is not currently used by anyone */ 101*47c6ae99SBarry Smith ierr = PetscObjectReference((PetscObject)dd->natural);CHKERRQ(ierr); 102*47c6ae99SBarry Smith *g = dd->natural; 103*47c6ae99SBarry Smith } else { 104*47c6ae99SBarry Smith ierr = VecDuplicate(dd->natural,g);CHKERRQ(ierr); 105*47c6ae99SBarry Smith } 106*47c6ae99SBarry Smith } else { /* create the first version of this guy */ 107*47c6ae99SBarry Smith ierr = VecCreateMPI(((PetscObject)da)->comm,dd->Nlocal,PETSC_DETERMINE,g);CHKERRQ(ierr); 108*47c6ae99SBarry Smith ierr = VecSetBlockSize(*g, dd->w);CHKERRQ(ierr); 109*47c6ae99SBarry Smith ierr = PetscObjectReference((PetscObject)*g);CHKERRQ(ierr); 110*47c6ae99SBarry Smith dd->natural = *g; 111*47c6ae99SBarry Smith } 112*47c6ae99SBarry Smith PetscFunctionReturn(0); 113*47c6ae99SBarry Smith } 114*47c6ae99SBarry Smith 115*47c6ae99SBarry Smith 116*47c6ae99SBarry Smith 117