Actual source code: dadist.c
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: {
10: DM da;
11: PetscLayout map;
13: VecGetDM(g, &da);
14: DMCreateGlobalVector(da,gg);
15: VecGetLayout(g,&map);
16: VecSetLayout(*gg,map);
17: return 0;
18: }
20: PetscErrorCode DMCreateGlobalVector_DA(DM da,Vec *g)
21: {
22: DM_DA *dd = (DM_DA*)da->data;
26: VecCreate(PetscObjectComm((PetscObject)da),g);
27: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
28: VecSetBlockSize(*g,dd->w);
29: VecSetType(*g,da->vectype);
30: if (dd->Nlocal < da->bind_below) {
31: VecSetBindingPropagates(*g,PETSC_TRUE);
32: VecBindToCPU(*g,PETSC_TRUE);
33: }
34: VecSetDM(*g, da);
35: VecSetLocalToGlobalMapping(*g,da->ltogmap);
36: VecSetOperation(*g,VECOP_VIEW,(void (*)(void))VecView_MPI_DA);
37: VecSetOperation(*g,VECOP_LOAD,(void (*)(void))VecLoad_Default_DA);
38: VecSetOperation(*g,VECOP_DUPLICATE,(void (*)(void))VecDuplicate_MPI_DA);
39: return 0;
40: }
42: /*@
43: DMDACreateNaturalVector - Creates a parallel PETSc vector that
44: will hold vector values in the natural numbering, rather than in
45: the PETSc parallel numbering associated with the DMDA.
47: Collective
49: Input Parameter:
50: . da - the distributed array
52: Output Parameter:
53: . g - the distributed global vector
55: Level: developer
57: Note:
58: The output parameter, g, is a regular PETSc vector that should be destroyed
59: with a call to VecDestroy() when usage is finished.
61: The number of local entries in the vector on each process is the same
62: as in a vector created with DMCreateGlobalVector().
64: .seealso: DMCreateLocalVector(), VecDuplicate(), VecDuplicateVecs(),
65: DMDACreate1d(), DMDACreate2d(), DMDACreate3d(), DMGlobalToLocalBegin(),
66: DMGlobalToLocalEnd(), DMLocalToGlobalBegin()
67: @*/
68: PetscErrorCode DMDACreateNaturalVector(DM da,Vec *g)
69: {
70: PetscInt cnt;
71: DM_DA *dd = (DM_DA*)da->data;
75: if (dd->natural) {
76: PetscObjectGetReference((PetscObject)dd->natural,&cnt);
77: if (cnt == 1) { /* object is not currently used by anyone */
78: PetscObjectReference((PetscObject)dd->natural);
79: *g = dd->natural;
80: } else {
81: VecDuplicate(dd->natural,g);
82: }
83: } else { /* create the first version of this guy */
84: VecCreate(PetscObjectComm((PetscObject)da),g);
85: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
86: VecSetBlockSize(*g, dd->w);
87: VecSetType(*g,da->vectype);
88: PetscObjectReference((PetscObject)*g);
90: dd->natural = *g;
91: }
92: return 0;
93: }