Actual source code: ex1.c
2: static char help[] = "Demonstrates constructing an application ordering.\n\n";
4: #include <petscsys.h>
5: #include <petscao.h>
6: #include <petscviewer.h>
8: int main(int argc, char **argv)
9: {
10: PetscInt i, n = 5;
11: PetscInt getpetsc[] = {0, 3, 4}, getapp[] = {2, 1, 9, 7};
12: PetscInt getpetsc1[] = {0, 3, 4}, getapp1[] = {2, 1, 9, 7};
13: PetscInt getpetsc2[] = {0, 3, 4}, getapp2[] = {2, 1, 9, 7};
14: PetscInt getpetsc3[] = {0, 3, 4}, getapp3[] = {2, 1, 9, 7};
15: PetscInt getpetsc4[] = {0, 3, 4}, getapp4[] = {2, 1, 9, 7};
16: PetscMPIInt rank, size;
17: IS ispetsc, isapp;
18: AO ao;
19: const PetscInt *app;
21: PetscFunctionBeginUser;
22: PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
23: PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
24: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
25: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
27: /* create the index sets */
28: PetscCall(ISCreateStride(PETSC_COMM_WORLD, n, rank, size, &isapp));
29: PetscCall(ISCreateStride(PETSC_COMM_WORLD, n, n * rank, 1, &ispetsc)); /* natural numbering */
31: /* create the application ordering */
32: PetscCall(AOCreateBasicIS(isapp, ispetsc, &ao));
33: PetscCall(AOView(ao, PETSC_VIEWER_STDOUT_WORLD));
35: PetscCall(AOPetscToApplication(ao, 4, getapp));
36: PetscCall(AOApplicationToPetsc(ao, 3, getpetsc));
38: PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d] 2,1,9,7 PetscToApplication %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", rank, getapp[0], getapp[1], getapp[2], getapp[3]));
39: PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d] 0,3,4 ApplicationToPetsc %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", rank, getpetsc[0], getpetsc[1], getpetsc[2]));
40: PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
41: PetscCall(AODestroy(&ao));
43: /* test MemoryScalable ao */
44: /*-------------------------*/
45: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nTest AOCreateMemoryScalable: \n"));
46: PetscCall(AOCreateMemoryScalableIS(isapp, ispetsc, &ao));
47: PetscCall(AOView(ao, PETSC_VIEWER_STDOUT_WORLD));
49: PetscCall(AOPetscToApplication(ao, 4, getapp1));
50: PetscCall(AOApplicationToPetsc(ao, 3, getpetsc1));
52: /* Check accuracy */;
53: for (i = 0; i < 4; i++) PetscCheck(getapp1[i] == getapp[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getapp1 %" PetscInt_FMT " != getapp %" PetscInt_FMT, getapp1[i], getapp[i]);
54: for (i = 0; i < 3; i++) PetscCheck(getpetsc1[i] == getpetsc[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getpetsc1 %" PetscInt_FMT " != getpetsc %" PetscInt_FMT, getpetsc1[i], getpetsc[i]);
56: PetscCall(AODestroy(&ao));
58: /* test MemoryScalable ao: ispetsc = NULL */
59: /*-----------------------------------------------*/
60: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nTest AOCreateMemoryScalable with ispetsc=NULL:\n"));
61: PetscCall(AOCreateMemoryScalableIS(isapp, NULL, &ao));
63: PetscCall(AOView(ao, PETSC_VIEWER_STDOUT_WORLD));
65: PetscCall(AOPetscToApplication(ao, 4, getapp2));
66: PetscCall(AOApplicationToPetsc(ao, 3, getpetsc2));
68: /* Check accuracy */;
69: for (i = 0; i < 4; i++) PetscCheck(getapp2[i] == getapp[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getapp2 %" PetscInt_FMT " != getapp %" PetscInt_FMT, getapp2[i], getapp[i]);
70: for (i = 0; i < 3; i++) PetscCheck(getpetsc2[i] == getpetsc[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getpetsc2 %" PetscInt_FMT " != getpetsc %" PetscInt_FMT, getpetsc2[i], getpetsc[i]);
71: PetscCall(AODestroy(&ao));
73: /* test AOCreateMemoryScalable() ao: */
74: PetscCall(ISGetIndices(isapp, &app));
75: PetscCall(AOCreateMemoryScalable(PETSC_COMM_WORLD, n, app, NULL, &ao));
76: PetscCall(ISRestoreIndices(isapp, &app));
78: PetscCall(AOPetscToApplication(ao, 4, getapp4));
79: PetscCall(AOApplicationToPetsc(ao, 3, getpetsc4));
81: /* Check accuracy */;
82: for (i = 0; i < 4; i++) PetscCheck(getapp4[i] == getapp[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getapp4 %" PetscInt_FMT " != getapp %" PetscInt_FMT, getapp4[i], getapp[i]);
83: for (i = 0; i < 3; i++) PetscCheck(getpetsc4[i] == getpetsc[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getpetsc4 %" PetscInt_FMT " != getpetsc %" PetscInt_FMT, getpetsc4[i], getpetsc[i]);
84: PetscCall(AODestroy(&ao));
86: /* test general API */
87: /*------------------*/
88: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "\nTest general API: \n"));
89: PetscCall(AOCreate(PETSC_COMM_WORLD, &ao));
90: PetscCall(AOSetIS(ao, isapp, ispetsc));
91: PetscCall(AOSetType(ao, AOMEMORYSCALABLE));
92: PetscCall(AOSetFromOptions(ao));
94: /* ispetsc and isapp are nolonger used. */
95: PetscCall(ISDestroy(&ispetsc));
96: PetscCall(ISDestroy(&isapp));
98: PetscCall(AOPetscToApplication(ao, 4, getapp3));
99: PetscCall(AOApplicationToPetsc(ao, 3, getpetsc3));
101: PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d] 2,1,9,7 PetscToApplication %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", rank, getapp3[0], getapp3[1], getapp3[2], getapp3[3]));
102: PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d] 0,3,4 ApplicationToPetsc %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", rank, getpetsc3[0], getpetsc3[1], getpetsc3[2]));
103: PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT));
105: /* Check accuracy */;
106: for (i = 0; i < 4; i++) PetscCheck(getapp3[i] == getapp[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getapp3 %" PetscInt_FMT " != getapp %" PetscInt_FMT, getapp3[i], getapp[i]);
107: for (i = 0; i < 3; i++) PetscCheck(getpetsc3[i] == getpetsc[i], PETSC_COMM_SELF, PETSC_ERR_USER, "getpetsc3 %" PetscInt_FMT " != getpetsc %" PetscInt_FMT, getpetsc3[i], getpetsc[i]);
109: PetscCall(AODestroy(&ao));
110: PetscCall(PetscFinalize());
111: return 0;
112: }
114: /*TEST
116: test:
118: test:
119: suffix: 2
120: nsize: 2
122: test:
123: suffix: 3
124: nsize: 3
126: test:
127: suffix: 4
128: nsize: 3
129: args: -ao_type basic
130: output_file: output/ex1_3.out
132: TEST*/