Actual source code: dadist.c
petsc-3.3-p7 2013-05-11
2: /*
3: Code for manipulating distributed regular arrays in parallel.
4: */
6: #include <petsc-private/daimpl.h> /*I "petscdmda.h" I*/
10: PetscErrorCode VecDuplicate_MPI_DA(Vec g,Vec* gg)
11: {
13: DM da;
16: PetscObjectQuery((PetscObject)g,"DM",(PetscObject*)&da);
17: DMCreateGlobalVector(da,gg);
18: PetscLayoutReference(g->map,&(*gg)->map);
19: return(0);
20: }
25: PetscErrorCode DMCreateGlobalVector_DA(DM da,Vec* g)
26: {
28: DM_DA *dd = (DM_DA*)da->data;
33: VecCreate(((PetscObject)da)->comm,g);
34: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
35: VecSetBlockSize(*g,dd->w);
36: VecSetType(*g,da->vectype);
37: VecSetFromOptions(*g);
38: PetscObjectCompose((PetscObject)*g,"DM",(PetscObject)da);
39: VecSetLocalToGlobalMapping(*g,da->ltogmap);
40: VecSetLocalToGlobalMappingBlock(*g,da->ltogmapb);
41: VecSetOperation(*g,VECOP_VIEW,(void(*)(void))VecView_MPI_DA);
42: VecSetOperation(*g,VECOP_LOAD,(void(*)(void))VecLoad_Default_DA);
43: VecSetOperation(*g,VECOP_DUPLICATE,(void(*)(void))VecDuplicate_MPI_DA);
44: return(0);
45: }
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 on DMDA
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(((PetscObject)da)->comm,g);
96: VecSetSizes(*g,dd->Nlocal,PETSC_DETERMINE);
97: VecSetBlockSize(*g, dd->w);
98: VecSetType(*g,VECMPI);
99: PetscObjectReference((PetscObject)*g);
100: dd->natural = *g;
101: }
102: return(0);
103: }