1 static char help[] = "AO test contributed by Sebastian Steiger <steiger@purdue.edu>, March 2011\n\n"; 2 3 /* 4 Example of usage: 5 mpiexec -n 12 ./ex3 6 mpiexec -n 30 ./ex3 -ao_type basic 7 */ 8 9 #include <iostream> 10 #include <fstream> 11 #include <vector> 12 #include <petscvec.h> 13 #include <petscao.h> 14 15 using namespace std; 16 17 int main(int argc, char **argv) 18 { 19 AO ao; 20 IS isapp; 21 char infile[PETSC_MAX_PATH_LEN], datafiles[PETSC_MAX_PATH_LEN]; 22 PetscBool flg; 23 PetscMPIInt size, rank; 24 25 PetscFunctionBeginUser; 26 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 27 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size)); 28 PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank)); 29 30 PetscCall(PetscOptionsGetString(NULL, NULL, "-datafiles", datafiles, sizeof(datafiles), &flg)); 31 PetscCheck(flg, PETSC_COMM_WORLD, PETSC_ERR_USER, "Must specify -datafiles ${DATAFILESPATH}/ao"); 32 33 // read in application indices 34 PetscCall(PetscSNPrintf(infile, sizeof(infile), "%s/AO%dCPUs/ao_p%d_appindices.txt", datafiles, size, rank)); 35 ifstream fin(infile); 36 PetscCheck(fin, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN, "File not found: %s", infile); 37 vector<PetscInt> myapp; 38 int tmp = -1; 39 while (!fin.eof()) { 40 tmp = -1; 41 fin >> tmp; 42 if (tmp == -1) break; 43 myapp.push_back(tmp); 44 } 45 #if __cplusplus >= 201103L // c++11 46 static_assert(is_same<decltype(myapp.size()), size_t>::value, ""); 47 #endif 48 PetscCall(PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d] has %zu indices.\n", rank, myapp.size())); 49 PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT)); 50 51 PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, myapp.size(), &myapp[0], PETSC_USE_POINTER, &isapp)); 52 53 PetscCall(AOCreate(PETSC_COMM_WORLD, &ao)); 54 PetscCall(AOSetIS(ao, isapp, NULL)); 55 PetscCall(AOSetType(ao, AOMEMORYSCALABLE)); 56 PetscCall(AOSetFromOptions(ao)); 57 58 if (rank == 0) cout << "AO has been set up." << endl; 59 60 PetscCall(AODestroy(&ao)); 61 PetscCall(ISDestroy(&isapp)); 62 63 if (rank == 0) cout << "AO is done." << endl; 64 65 PetscCall(PetscFinalize()); 66 return 0; 67 } 68 69 /*TEST 70 71 build: 72 requires: !defined(PETSC_USE_64BIT_INDICES) 73 74 test: 75 nsize: 12 76 requires: double !complex datafilespath 77 args: -datafiles ${DATAFILESPATH}/ao 78 output_file: output/ex3_1.out 79 80 test: 81 suffix: 2 82 nsize: 12 83 requires: double !complex datafilespath 84 args: -ao_type basic -datafiles ${DATAFILESPATH}/ao 85 output_file: output/ex3_1.out 86 87 test: 88 suffix: 3 89 nsize: 30 90 requires: double !complex datafilespath 91 args: -datafiles ${DATAFILESPATH}/ao 92 93 test: 94 suffix: 4 95 nsize: 30 96 requires: double !complex datafilespath 97 args: -ao_type basic -datafiles ${DATAFILESPATH}/ao 98 output_file: output/ex3_3.out 99 100 TEST*/ 101