Actual source code: ex4.c

petsc-3.3-p7 2013-05-11
  2: static char help[] = "Demonstrates using ISLocalToGlobalMappings.\n\n";

  4: /*T
  5:     Concepts: local to global mappings
  6:     Concepts: global to local mappings

  8:     Description:  Creates an index set based on blocks of integers. Views that index set
  9:     and then destroys it.
 10: T*/

 12: #include <petscis.h>

 16: int main(int argc,char **argv)
 17: {
 18:   PetscErrorCode         ierr;
 19:   PetscInt               i,n = 4,indices[] = {0,3,9,12},m = 2,input[] = {0,2};
 20:   PetscInt               output[2],inglobals[13],outlocals[13];
 21:   ISLocalToGlobalMapping mapping;

 23:   PetscInitialize(&argc,&argv,(char*)0,help);

 25:   /*
 26:       Create a local to global mapping. Each processor independently
 27:      creates a mapping  
 28:   */
 29:   ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,n,indices,PETSC_COPY_VALUES,&mapping);

 31:   /*
 32:      Map a set of local indices to their global values 
 33:   */
 34:   ISLocalToGlobalMappingApply(mapping,m,input,output);
 35:   PetscIntView(m,output,PETSC_VIEWER_STDOUT_SELF);
 36: 
 37:   /*
 38:      Map some global indices to local, retaining the ones without a local index by -1
 39:   */
 40:   for (i=0; i<13; i++) {
 41:     inglobals[i] = i;
 42:   }
 43:   ISGlobalToLocalMappingApply(mapping,IS_GTOLM_MASK,13,inglobals,PETSC_NULL,outlocals);
 44:   PetscIntView(13,outlocals,PETSC_VIEWER_STDOUT_SELF);

 46:   /*
 47:      Map some global indices to local, dropping the ones without a local index.
 48:   */
 49:   ISGlobalToLocalMappingApply(mapping,IS_GTOLM_DROP,13,inglobals,&m,outlocals);
 50:   PetscIntView(m,outlocals,PETSC_VIEWER_STDOUT_SELF);

 52:   /*
 53:      Free the space used by the local to global mapping
 54:   */
 55:   ISLocalToGlobalMappingDestroy(&mapping);


 58:   PetscFinalize();
 59:   return 0;
 60: }