Actual source code: dalocal.c
1: /*$Id: dalocal.c,v 1.29 2001/03/23 23:25:00 balay Exp $*/
2:
3: /*
4: Code for manipulating distributed regular arrays in parallel.
5: */
7: #include "src/dm/da/daimpl.h" /*I "petscda.h" I*/
9: /*@C
10: DACreateLocalVector - Creates a Seq PETSc vector that
11: may be used with the DAXXX routines.
13: Not Collective
15: Input Parameter:
16: . da - the distributed array
18: Output Parameter:
19: . g - the local vector
21: Level: beginner
23: Note:
24: The output parameter, g, is a regular PETSc vector that should be destroyed
25: with a call to VecDestroy() when usage is finished.
27: .keywords: distributed array, create, local, vector
29: .seealso: DACreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(),
30: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
31: DAGlobalToLocalEnd(), DALocalToGlobal(), DAGetLocalVector(), DARestoreLocalVector()
32: @*/
33: int DACreateLocalVector(DA da,Vec* g)
34: {
39: VecDuplicate(da->local,g);
40: PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
41: return(0);
42: }
44: /*@C
45: DAGetLocalVector - Gets a Seq PETSc vector that
46: may be used with the DAXXX routines.
48: Not Collective
50: Input Parameter:
51: . da - the distributed array
53: Output Parameter:
54: . g - the local vector
56: Level: beginner
58: Note:
59: The output parameter, g, is a regular PETSc vector that should be returned with
60: DARestoreLocalVector() DO NOT call VecDestroy() on it.
62: .keywords: distributed array, create, local, vector
64: .seealso: DACreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(),
65: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
66: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateLocalVector(), DARestoreLocalVector()
67: @*/
68: int DAGetLocalVector(DA da,Vec* g)
69: {
70: int ierr,i;
74: for (i=0; i<10; i++) {
75: if (da->localin[i]) {
76: *g = da->localin[i];
77: da->localin[i] = PETSC_NULL;
78: goto alldone;
79: }
80: }
81: VecDuplicate(da->local,g);
82: PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
84: alldone:
85: for (i=0; i<10; i++) {
86: if (!da->localout[i]) {
87: da->localout[i] = *g;
88: break;
89: }
90: }
91: return(0);
92: }
94: /*@C
95: DARestoreLocalVector - Returns a Seq PETSc vector that
96: obtained from DAGetLocalVector(). Do not use with vector obtained via
97: DACreateLocalVector().
99: Not Collective
101: Input Parameter:
102: + da - the distributed array
103: - g - the local vector
105: Level: beginner
107: .keywords: distributed array, create, local, vector
109: .seealso: DACreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(),
110: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
111: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateLocalVector(), DAGetLocalVector()
112: @*/
113: int DARestoreLocalVector(DA da,Vec* g)
114: {
115: int ierr,i,j;
119: for (j=0; j<10; j++) {
120: if (*g == da->localout[j]) {
121: da->localout[j] = PETSC_NULL;
122: for (i=0; i<10; i++) {
123: if (!da->localin[i]) {
124: da->localin[i] = *g;
125: goto alldone;
126: }
127: }
128: }
129: }
130: VecDestroy(*g);
131: alldone:
132: return(0);
133: }
135: /*@C
136: DAGetGlobalVector - Gets a MPI PETSc vector that
137: may be used with the DAXXX routines.
139: Collective on DA
141: Input Parameter:
142: . da - the distributed array
144: Output Parameter:
145: . g - the global vector
147: Level: beginner
149: Note:
150: The output parameter, g, is a regular PETSc vector that should be returned with
151: DARestoreGlobalVector() DO NOT call VecDestroy() on it.
153: .keywords: distributed array, create, Global, vector
155: .seealso: DACreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(),
156: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToLocalBegin(),
157: DAGlobalToLocalEnd(), DALocalToGlobal(), DACreateLocalVector(), DARestoreLocalVector()
158: @*/
159: int DAGetGlobalVector(DA da,Vec* g)
160: {
161: int ierr,i;
165: for (i=0; i<10; i++) {
166: if (da->globalin[i]) {
167: *g = da->globalin[i];
168: da->globalin[i] = PETSC_NULL;
169: goto alldone;
170: }
171: }
172: VecDuplicate(da->global,g);
173: PetscObjectCompose((PetscObject)*g,"DA",(PetscObject)da);
175: alldone:
176: for (i=0; i<10; i++) {
177: if (!da->globalout[i]) {
178: da->globalout[i] = *g;
179: break;
180: }
181: }
182: return(0);
183: }
185: /*@C
186: DARestoreGlobalVector - Returns a Seq PETSc vector that
187: obtained from DAGetGlobalVector(). Do not use with vector obtained via
188: DACreateGlobalVector().
190: Not Collective
192: Input Parameter:
193: + da - the distributed array
194: - g - the global vector
196: Level: beginner
198: .keywords: distributed array, create, global, vector
200: .seealso: DACreateGlobalVector(), VecDuplicate(), VecDuplicateVecs(),
201: DACreate1d(), DACreate2d(), DACreate3d(), DAGlobalToGlobalBegin(),
202: DAGlobalToGlobalEnd(), DAGlobalToGlobal(), DACreateLocalVector(), DAGetGlobalVector()
203: @*/
204: int DARestoreGlobalVector(DA da,Vec* g)
205: {
206: int ierr,i,j;
210: for (j=0; j<10; j++) {
211: if (*g == da->globalout[j]) {
212: da->globalout[j] = PETSC_NULL;
213: for (i=0; i<10; i++) {
214: if (!da->globalin[i]) {
215: da->globalin[i] = *g;
216: goto alldone;
217: }
218: }
219: }
220: }
221: VecDestroy(*g);
222: alldone:
223: return(0);
224: }