Actual source code: daltol.c
1: /*$Id: daltol.c,v 1.24 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
9: #undef __FUNCT__
11: /*
12: DALocalToLocalCreate - Creates the local to local scatter
14: Collective on DA
16: Input Parameter:
17: . da - the distributed array
19: */
20: int DALocalToLocalCreate(DA da)
21: {
22: int *idx,left,j,ierr,count,up,down,i,bottom,top,k;
27: if (da->ltol) return(0);
28: /*
29: We simply remap the values in the from part of
30: global to local to read from an array with the ghost values
31: rather then from the plain array.
32: */
33: VecScatterCopy(da->gtol,&da->ltol);
34: PetscLogObjectParent(da,da->ltol);
35: if (da->dim == 1) {
36: left = da->xs - da->Xs;
37: PetscMalloc((da->xe-da->xs)*sizeof(int),&idx);
38: for (j=0; j<da->xe-da->xs; j++) {
39: idx[j] = left + j;
40: }
41: } else if (da->dim == 2) {
42: left = da->xs - da->Xs; down = da->ys - da->Ys; up = down + da->ye-da->ys;
43: PetscMalloc((da->xe-da->xs)*(up - down)*sizeof(int),&idx);
44: count = 0;
45: for (i=down; i<up; i++) {
46: for (j=0; j<da->xe-da->xs; j++) {
47: idx[count++] = left + i*(da->Xe-da->Xs) + j;
48: }
49: }
50: } else if (da->dim == 3) {
51: left = da->xs - da->Xs;
52: bottom = da->ys - da->Ys; top = bottom + da->ye-da->ys ;
53: down = da->zs - da->Zs; up = down + da->ze-da->zs;
54: count = (da->xe-da->xs)*(top-bottom)*(up-down);
55: PetscMalloc(count*sizeof(int),&idx);
56: count = 0;
57: for (i=down; i<up; i++) {
58: for (j=bottom; j<top; j++) {
59: for (k=0; k<da->xe-da->xs; k++) {
60: idx[count++] = (left+j*(da->Xe-da->Xs))+i*(da->Xe-da->Xs)*(da->Ye-da->Ys) + k;
61: }
62: }
63: }
64: } else SETERRQ1(1,"DA has invalid dimension %d",da->dim);
66: VecScatterRemap(da->ltol,idx,PETSC_NULL);
67: PetscFree(idx);
68: return(0);
69: }
71: #undef __FUNCT__
73: /*@
74: DALocalToLocalBegin - Maps from a local vector (including ghost points
75: that contain irrelevant values) to another local vector where the ghost
76: points in the second are set correctly. Must be followed by DALocalToLocalEnd().
78: Collective on DA and Vec
80: Input Parameters:
81: + da - the distributed array context
82: . g - the original local vector
83: - mode - one of INSERT_VALUES or ADD_VALUES
85: Output Parameter:
86: . l - the local vector with correct ghost values
88: Level: intermediate
90: Notes:
91: The local vectors used here need not be the same as those
92: obtained from DACreateLocalVector(), BUT they
93: must have the same parallel data layout; they could, for example, be
94: obtained with VecDuplicate() from the DA originating vectors.
96: .keywords: distributed array, local-to-local, begin
98: .seealso: DALocalToLocalEnd(), DALocalToGlobal()
99: @*/
100: int DALocalToLocalBegin(DA da,Vec g,InsertMode mode,Vec l)
101: {
106: if (!da->ltol) {
107: DALocalToLocalCreate(da);
108: }
109: VecScatterBegin(g,l,mode,SCATTER_FORWARD,da->ltol);
110: return(0);
111: }
113: #undef __FUNCT__
115: /*@
116: DALocalToLocalEnd - Maps from a local vector (including ghost points
117: that contain irrelevant values) to another local vector where the ghost
118: points in the second are set correctly. Must be preceeded by
119: DALocalToLocalBegin().
121: Collective on DA and Vec
123: Input Parameters:
124: + da - the distributed array context
125: . g - the original local vector
126: - mode - one of INSERT_VALUES or ADD_VALUES
128: Output Parameter:
129: . l - the local vector with correct ghost values
131: Level: intermediate
133: Note:
134: The local vectors used here need not be the same as those
135: obtained from DACreateLocalVector(), BUT they
136: must have the same parallel data layout; they could, for example, be
137: obtained with VecDuplicate() from the DA originating vectors.
139: .keywords: distributed array, local-to-local, end
141: .seealso: DALocalToLocalBegin(), DALocalToGlobal()
142: @*/
143: int DALocalToLocalEnd(DA da,Vec g,InsertMode mode,Vec l)
144: {
149: VecScatterEnd(g,l,mode,SCATTER_FORWARD,da->ltol);
150: return(0);
151: }