Actual source code: ex3.cxx
petsc-3.4.2 2013-07-02

      2: static char help[] = "AO test contributed by Sebastian Steiger <steiger@purdue.edu>, March 2011\n\n";

      4: /*
      5:   Example of usage:
      6:     mpiexec -n 12 ./ex3
      7:     mpiexec -n 30 ./ex3 -ao_type basic
      8: */

     10: #include <iostream>
     11: #include <fstream>
     12: #include <vector>
     13: #include <assert.h>
     14: #include <petscao.h>
     15: #include <mpi.h>

     17: using namespace std;

     19: int main(int argc, char** argv)
     20: {
     22:   AO ao;
     23:   IS isapp;
     24:   char infile[PETSC_MAX_PATH_LEN],datafiles[PETSC_MAX_PATH_LEN];
     25:   PetscBool flg;

     27:   PetscInitialize(&argc, &argv, (char*)0, help);
     28:   int size=-1;   MPI_Comm_size(PETSC_COMM_WORLD, &size);
     29:   int myrank=-1; MPI_Comm_rank(PETSC_COMM_WORLD, &myrank);

     31:   PetscOptionsGetString(PETSC_NULL,"-datafiles",datafiles,sizeof(datafiles),&flg);
     32:   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must specify -datafiles ${DATAFILESPATH}/ao");

     34:   // read in application indices
     35:   PetscSNPrintf(infile,sizeof(infile),"%s/AO%dCPUs/ao_p%d_appindices.txt",datafiles,size,myrank);
     36:   //cout << infile << endl;
     37:   ifstream fin(infile);
     38:   if (!fin) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"File not found: %s",infile);
     39:   vector<int>  myapp;
     40:   int tmp=-1;
     41:   while (!fin.eof()) {
     42:     tmp=-1;
     43:     fin >> tmp;
     44:     if (tmp==-1) break;
     45:     myapp.push_back(tmp);
     46:   }
     47:   PetscSynchronizedPrintf(PETSC_COMM_WORLD,"[%d] has %D indices.\n",
     48:           myrank,myapp.size());
     49:   PetscSynchronizedFlush(PETSC_COMM_WORLD);

     51:   ISCreateGeneral(PETSC_COMM_WORLD, myapp.size(), &(myapp[0]), PETSC_USE_POINTER, &isapp);
     52:   //ISView(isapp,PETSC_VIEWER_STDOUT_WORLD);

     54:   AOCreate(PETSC_COMM_WORLD, &ao);
     55:   AOSetIS(ao, isapp, NULL);
     56:   AOSetType(ao, AOMEMORYSCALABLE);
     57:   AOSetFromOptions(ao);

     59:   if (myrank==0) cout << "AO has been set up." << endl;

     61:   AODestroy(&ao);
     62:   ISDestroy(&isapp);

     64:   if (myrank==0) cout << "AO is done." << endl;

     66:   PetscFinalize();
     67:   return 0;
     68: }