Actual source code: ex4.c

  2: /*      "$Id: ex4.c,v 1.13 2001/03/23 23:21:14 balay Exp $"; */

  4: static char help[] = "Demonstrates using ISLocalToGlobalMappings.nn";

  6: /*T
  7:     Concepts: local to global mappings
  8:     Concepts: global to local mappings

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

 14:  #include petscis.h

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

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

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

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

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

 55:   /*
 56:      Free the space used by the local to global mapping
 57:   */
 58:   ISLocalToGlobalMappingDestroy(mapping);


 61:   PetscFinalize();
 62:   return 0;
 63: }