Actual source code: ex4.c
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>
13: #include <petscviewer.h>
15: int main(int argc,char **argv)
16: {
17: PetscInt i,n = 4,indices[] = {0,3,9,12},m = 2,input[] = {0,2};
18: PetscInt output[2],inglobals[13],outlocals[13];
19: ISLocalToGlobalMapping mapping;
21: PetscInitialize(&argc,&argv,(char*)0,help);
23: /*
24: Create a local to global mapping. Each processor independently
25: creates a mapping
26: */
27: ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD,1,n,indices,PETSC_COPY_VALUES,&mapping);
28: ISLocalToGlobalMappingSetFromOptions(mapping);
30: /*
31: Map a set of local indices to their global values
32: */
33: ISLocalToGlobalMappingApply(mapping,m,input,output);
34: PetscIntView(m,output,PETSC_VIEWER_STDOUT_WORLD);
36: /*
37: Map some global indices to local, retaining the ones without a local index by -1
38: */
39: for (i=0; i<13; i++) inglobals[i] = i;
40: ISGlobalToLocalMappingApply(mapping,IS_GTOLM_MASK,13,inglobals,NULL,outlocals);
41: PetscIntView(13,outlocals,PETSC_VIEWER_STDOUT_WORLD);
43: /*
44: Map some global indices to local, dropping the ones without a local index.
45: */
46: ISGlobalToLocalMappingApply(mapping,IS_GTOLM_DROP,13,inglobals,&m,outlocals);
47: PetscIntView(m,outlocals,PETSC_VIEWER_STDOUT_WORLD);
49: ISLocalToGlobalMappingView(mapping,PETSC_VIEWER_STDOUT_WORLD);
50: /*
51: Free the space used by the local to global mapping
52: */
53: ISLocalToGlobalMappingDestroy(&mapping);
55: PetscFinalize();
56: return 0;
57: }
59: /*TEST
61: test:
63: test:
64: suffix: 2
65: args: -islocaltoglobalmapping_type hash
67: TEST*/