Date: 2022-08-02T03:13:39+00:00

Actual source code: ex4.c

      2: static char help[] = "Demonstrates using ISLocalToGlobalMappings.\n\n";

      4: #include <petscis.h>
      5: #include <petscviewer.h>

      7: int main(int argc,char **argv)
      8: {
      9:   PetscInt               i,n = 4,indices[] = {0,3,9,12},m = 2,input[] = {0,2};
     10:   PetscInt               output[2],inglobals[13],outlocals[13];
     11:   ISLocalToGlobalMapping mapping;

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

     15:   /*
     16:       Create a local to global mapping. Each processor independently
     17:      creates a mapping
     18:   */
     19:   ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,1,n,indices,PETSC_COPY_VALUES,&mapping);
     20:   ISLocalToGlobalMappingSetFromOptions(mapping);

     22:   /*
     23:      Map a set of local indices to their global values
     24:   */
     25:   ISLocalToGlobalMappingApply(mapping,m,input,output);
     26:   PetscIntView(m,output,PETSC_VIEWER_STDOUT_WORLD);

     28:   /*
     29:      Map some global indices to local, retaining the ones without a local index by -1
     30:   */
     31:   for (i=0; i<13; i++) inglobals[i] = i;
     32:   ISGlobalToLocalMappingApply(mapping,IS_GTOLM_MASK,13,inglobals,NULL,outlocals);
     33:   PetscIntView(13,outlocals,PETSC_VIEWER_STDOUT_WORLD);

     35:   /*
     36:      Map some global indices to local, dropping the ones without a local index.
     37:   */
     38:   ISGlobalToLocalMappingApply(mapping,IS_GTOLM_DROP,13,inglobals,&m,outlocals);
     39:   PetscIntView(m,outlocals,PETSC_VIEWER_STDOUT_WORLD);

     41:   ISLocalToGlobalMappingView(mapping,PETSC_VIEWER_STDOUT_WORLD);
     42:   /*
     43:      Free the space used by the local to global mapping
     44:   */
     45:   ISLocalToGlobalMappingDestroy(&mapping);

     47:   PetscFinalize();
     48:   return 0;
     49: }

     51: /*TEST

     53:    test:

     55:    test:
     56:       suffix: 2
     57:       args: -islocaltoglobalmapping_type hash

     59: TEST*/