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