Actual source code: dadist.c
petsc-3.11.4 2019-09-28
2: /*
3: Code for manipulating distributed regular arrays in parallel.
4: */
6: #include <petsc/private/dmdaimpl.h>
8: PetscErrorCode VecDuplicate_MPI_DA(Vec g,Vec *gg)
9: {
11: DM da;
12: PetscLayout map;
15: VecGetDM(g, &da);
16: DMCreateGlobalVector(da,gg);
17: VecGetLayout(g,&map);
18: VecSetLayout(*gg,map);
19: return(0);
20: }
23: PetscErrorCode DMCreateGlobalVector_DA(DM da,Vec *g)
24: {
26: DM_DA *dd = (DM_DA*)da->data;
31: if (da->defaultSection) {
32: DMCreateGlobalVector_Section_Private(da,g);
33: /* The view and load functions break for general layouts */
34: return(0);
35: } else {
36: VecCreate(PetscObjectComm((PetscObject)da),g);
37: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
38: VecSetBlockSize(*g,dd->w);
39: VecSetType(*g,da->vectype);
40: VecSetDM(*g, da);
41: VecSetLocalToGlobalMapping(*g,da->ltogmap);
42: }
43: VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
44: VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
45: VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
46: return(0);
47: }
49: /*@
50: DMDACreateNaturalVector - Creates a parallel PETSc vector that
51: will hold vector values in the natural numbering, rather than in
52: the PETSc parallel numbering associated with the DMDA.
54: Collective
56: Input Parameter:
57: . da - the distributed array
59: Output Parameter:
60: . g - the distributed global vector
62: Level: developer
64: Note:
65: The output parameter, g, is a regular PETSc vector that should be destroyed
66: with a call to VecDestroy() when usage is finished.
68: The number of local entries in the vector on each process is the same
69: as in a vector created with DMCreateGlobalVector().
71: .keywords: distributed array, create, global, distributed, vector
73: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
74: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
75: DMGlobalToLocalEnd(), DMDALocalToGlobalBegin()
76: @*/
77: PetscErrorCode DMDACreateNaturalVector(DM da,Vec *g)
78: {
80: PetscInt cnt;
81: DM_DA *dd = (DM_DA*)da->data;
86: if (dd->natural) {
87: PetscObjectGetReference((PetscObject)dd->natural,&cnt);
88: if (cnt == 1) { /* object is not currently used by anyone */
89: PetscObjectReference((PetscObject)dd->natural);
90: *g = dd->natural;
91: } else {
92: VecDuplicate(dd->natural,g);
93: }
94: } else { /* create the first version of this guy */
95: VecCreate(PetscObjectComm((PetscObject)da),g);
96: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
97: VecSetBlockSize(*g, dd->w);
98: VecSetType(*g,da->vectype);
99: PetscObjectReference((PetscObject)*g);
101: dd->natural = *g;
102: }
103: return(0);
104: }