Actual source code: dadist.c
1: #define PETSCDM_DLL
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include src/dm/da/daimpl.h
11: /*@C
12: DACreateGlobalVector - Creates a parallel PETSc vector that
13: may be used with the DAXXX routines.
15: Collective on DA
17: Input Parameter:
18: . da - the distributed array
20: Output Parameter:
21: . g - the distributed global vector
23: Level: beginner
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.
29: .keywords: distributed array, create, global, distributed, vector
31: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
32: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
33: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateNaturalVector()
34: @*/
35: PetscErrorCode PETSCDM_DLLEXPORT DACreateGlobalVector(DA da,Vec* g)
36: {
42: VecCreateMPI(da->comm,da->Nlocal,PETSC_DETERMINE,g);
43: PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
44: VecSetLocalToGlobalMapping(*g,da->ltogmap);
45: VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);
46: VecSetBlockSize(*g,da->w);
47: VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);
48: VecSetOperation(*g,VECOP_LOADINTOVECTOR,(void(*)(void))VecLoadIntoVector_Binary_DA);
49: return(0);
50: }
54: /*@C
55: DACreateNaturalVector - Creates a parallel PETSc vector that
56: will hold vector values in the natural numbering, rather than in
57: the PETSc parallel numbering associated with the DA.
59: Collective on DA
61: Input Parameter:
62: . da - the distributed array
64: Output Parameter:
65: . g - the distributed global vector
67: Level: developer
69: Note:
70: The output parameter, g, is a regular PETSc vector that should be destroyed
71: with a call to VecDestroy() when usage is finished.
73: The number of local entries in the vector on each process is the same
74: as in a vector created with DACreateGlobalVector().
76: .keywords: distributed array, create, global, distributed, vector
78: .seealso: DACreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
79: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
80: DAGlobalToLocalEnd(), DALocalToGlobal()
81: @*/
82: PetscErrorCode PETSCDM_DLLEXPORT DACreateNaturalVector(DA da,Vec* g)
83: {
85: PetscInt cnt;
90: if (da->natural) {
91: PetscObjectGetReference((PetscObject)da->natural,&cnt);
92: if (cnt == 1) { /* object is not currently used by anyone */
93: PetscObjectReference((PetscObject)da->natural);
94: *g = da->natural;
95: } else {
96: VecDuplicate(da->natural,g);
97: }
98: } else { /* create the first version of this guy */
99: VecCreateMPI(da->comm,da->Nlocal,PETSC_DETERMINE,g);
100: VecSetBlockSize(*g, da->w);
101: PetscObjectReference((PetscObject)*g);
102: da->natural = *g;
103: }
104: return(0);
105: }