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