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: /*
 10:    DALocalToLocalCreate - Creates the local to local scatter

 12:    Collective on DA

 14:    Input Parameter:
 15: .  da - the distributed array

 17: */
 18: int DALocalToLocalCreate(DA da)
 19: {
 20:   int *idx,left,j,ierr,count,up,down,i,bottom,top,k;


 25:   if (da->ltol) return(0);
 26:   /* 
 27:      We simply remap the values in the from part of 
 28:      global to local to read from an array with the ghost values 
 29:      rather then from the plain array.
 30:   */
 31:   VecScatterCopy(da->gtol,&da->ltol);
 32:   PetscLogObjectParent(da,da->ltol);
 33:   if (da->dim == 1) {
 34:     left = da->xs - da->Xs;
 35:     PetscMalloc((da->xe-da->xs)*sizeof(int),&idx);
 36:     for (j=0; j<da->xe-da->xs; j++) {
 37:       idx[j] = left + j;
 38:     }
 39:   } else if (da->dim == 2) {
 40:     left  = da->xs - da->Xs; down  = da->ys - da->Ys; up    = down + da->ye-da->ys;
 41:     PetscMalloc((da->xe-da->xs)*(up - down)*sizeof(int),&idx);
 42:     count = 0;
 43:     for (i=down; i<up; i++) {
 44:       for (j=0; j<da->xe-da->xs; j++) {
 45:         idx[count++] = left + i*(da->Xe-da->Xs) + j;
 46:       }
 47:     }
 48:   } else if (da->dim == 3) {
 49:     left   = da->xs - da->Xs;
 50:     bottom = da->ys - da->Ys; top = bottom + da->ye-da->ys ;
 51:     down   = da->zs - da->Zs; up  = down + da->ze-da->zs;
 52:     count  = (da->xe-da->xs)*(top-bottom)*(up-down);
 53:     PetscMalloc(count*sizeof(int),&idx);
 54:     count  = 0;
 55:     for (i=down; i<up; i++) {
 56:       for (j=bottom; j<top; j++) {
 57:         for (k=0; k<da->xe-da->xs; k++) {
 58:           idx[count++] = (left+j*(da->Xe-da->Xs))+i*(da->Xe-da->Xs)*(da->Ye-da->Ys) + k;
 59:         }
 60:       }
 61:     }
 62:   } else SETERRQ1(1,"DA has invalid dimension %d",da->dim);

 64:   VecScatterRemap(da->ltol,idx,PETSC_NULL);
 65:   PetscFree(idx);
 66:   return(0);
 67: }

 69: /*@
 70:    DALocalToLocalBegin - Maps from a local vector (including ghost points
 71:    that contain irrelevant values) to another local vector where the ghost
 72:    points in the second are set correctly. Must be followed by DALocalToLocalEnd().

 74:    Collective on DA and Vec

 76:    Input Parameters:
 77: +  da - the distributed array context
 78: .  g - the original local vector
 79: -  mode - one of INSERT_VALUES or ADD_VALUES

 81:    Output Parameter:
 82: .  l  - the local vector with correct ghost values

 84:    Level: intermediate

 86:    Notes:
 87:    The local vectors used here need not be the same as those
 88:    obtained from DACreateLocalVector(), BUT they
 89:    must have the same parallel data layout; they could, for example, be 
 90:    obtained with VecDuplicate() from the DA originating vectors.

 92: .keywords: distributed array, local-to-local, begin

 94: .seealso: DALocalToLocalEnd(), DALocalToGlobal(), DAGlobalToLocal()
 95: @*/
 96: int DALocalToLocalBegin(DA da,Vec g,InsertMode mode,Vec l)
 97: {

102:   if (!da->ltol) {
103:     DALocalToLocalCreate(da);
104:   }
105:   VecScatterBegin(g,l,mode,SCATTER_FORWARD,da->ltol);
106:   return(0);
107: }

109: /*@
110:    DALocalToLocalEnd - Maps from a local vector (including ghost points
111:    that contain irrelevant values) to another local vector where the ghost
112:    points in the second are set correctly.  Must be preceeded by 
113:    DALocalToLocalBegin().

115:    Collective on DA and Vec

117:    Input Parameters:
118: +  da - the distributed array context
119: .  g - the original local vector
120: -  mode - one of INSERT_VALUES or ADD_VALUES

122:    Output Parameter:
123: .  l  - the local vector with correct ghost values

125:    Level: intermediate

127:    Note:
128:    The local vectors used here need not be the same as those
129:    obtained from DACreateLocalVector(), BUT they
130:    must have the same parallel data layout; they could, for example, be 
131:    obtained with VecDuplicate() from the DA originating vectors.

133: .keywords: distributed array, local-to-local, end

135: .seealso: DALocalToLocalBegin(), DALocalToGlobal(), DAGlobalToLocal()
136: @*/
137: int DALocalToLocalEnd(DA da,Vec g,InsertMode mode,Vec l)
138: {

143:   VecScatterEnd(g,l,mode,SCATTER_FORWARD,da->ltol);
144:   return(0);
145: }