Date: 2021-03-03T22:26:47+00:00

Actual source code: dagtona.c
petsc-3.14.5 2021-03-03
Report Typos and Errors

      2: /*
      3:      Tools to help solve the coarse grid problem redundantly.
      4:   Provides two scatter contexts that (1) map from the usual global vector
      5:   to all processors the entire vector in NATURAL numbering and (2)
      6:   from the entire vector on each processor in natural numbering extracts
      7:   out this processors piece in GLOBAL numbering
      8: */

     10: #include <petsc/private/dmdaimpl.h>

     12: /*@
     13:    DMDAGlobalToNaturalAllCreate - Creates a scatter context that maps from the
     14:      global vector the entire vector to each processor in natural numbering

     16:    Collective on da

     18:    Input Parameter:
     19: .  da - the distributed array context

     21:    Output Parameter:
     22: .  scatter - the scatter context

     24:    Level: advanced

     26: .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(),
     27:           DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector()
     28: @*/
     29: PetscErrorCode  DMDAGlobalToNaturalAllCreate(DM da,VecScatter *scatter)
     30: {
     32:   PetscInt       N;
     33:   IS             from,to;
     34:   Vec            tmplocal,global;
     35:   AO             ao;
     36:   DM_DA          *dd = (DM_DA*)da->data;

     41:   DMDAGetAO(da,&ao);

     43:   /* create the scatter context */
     44:   VecCreateMPIWithArray(PetscObjectComm((PetscObject)da),dd->w,dd->Nlocal,PETSC_DETERMINE,NULL,&global);
     45:   VecGetSize(global,&N);
     46:   ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&to);
     47:   AOPetscToApplicationIS(ao,to);
     48:   ISCreateStride(PetscObjectComm((PetscObject)da),N,0,1,&from);
     49:   VecCreateSeqWithArray(PETSC_COMM_SELF,dd->w,N,NULL,&tmplocal);
     50:   VecScatterCreate(global,from,tmplocal,to,scatter);
     51:   VecDestroy(&tmplocal);
     52:   VecDestroy(&global);
     53:   ISDestroy(&from);
     54:   ISDestroy(&to);
     55:   return(0);
     56: }

     58: /*@
     59:    DMDANaturalAllToGlobalCreate - Creates a scatter context that maps from a copy
     60:      of the entire vector on each processor to its local part in the global vector.

     62:    Collective on da

     64:    Input Parameter:
     65: .  da - the distributed array context

     67:    Output Parameter:
     68: .  scatter - the scatter context

     70:    Level: advanced

     72: .seealso: DMDAGlobalToNaturalEnd(), DMLocalToGlobalBegin(), DMDACreate2d(),
     73:           DMGlobalToLocalBegin(), DMGlobalToLocalEnd(), DMDACreateNaturalVector()
     74: @*/
     75: PetscErrorCode  DMDANaturalAllToGlobalCreate(DM da,VecScatter *scatter)
     76: {
     78:   DM_DA          *dd = (DM_DA*)da->data;
     79:   PetscInt       M,m = dd->Nlocal,start;
     80:   IS             from,to;
     81:   Vec            tmplocal,global;
     82:   AO             ao;

     87:   DMDAGetAO(da,&ao);

     89:   /* create the scatter context */
     90:   MPIU_Allreduce(&m,&M,1,MPIU_INT,MPI_SUM,PetscObjectComm((PetscObject)da));
     91:   VecCreateMPIWithArray(PetscObjectComm((PetscObject)da),dd->w,m,PETSC_DETERMINE,NULL,&global);
     92:   VecGetOwnershipRange(global,&start,NULL);
     93:   ISCreateStride(PetscObjectComm((PetscObject)da),m,start,1,&from);
     94:   AOPetscToApplicationIS(ao,from);
     95:   ISCreateStride(PetscObjectComm((PetscObject)da),m,start,1,&to);
     96:   VecCreateSeqWithArray(PETSC_COMM_SELF,dd->w,M,NULL,&tmplocal);
     97:   VecScatterCreate(tmplocal,from,global,to,scatter);
     98:   VecDestroy(&tmplocal);
     99:   VecDestroy(&global);
    100:   ISDestroy(&from);
    101:   ISDestroy(&to);
    102:   return(0);
    103: }