Пример #1
0
int main(int argc, char** argv) {


  bool verbose = false;
  int numProcs = 1;
  int localProc = 0;

#ifdef HAVE_MPI
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &localProc);
  MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
#endif
  
  try {
    verbose = ispatest::set_verbose(localProc, argc, argv);
  }
  catch(std::exception& exc) {
    std::cout << "err, setting verbosity: " << exc.what() << std::endl;
    std::cout << "End Result: TEST FAILED" << std::endl;
#ifdef HAVE_MPI
    MPI_Finalize();
#endif /* HAVE_MPI */
    return(-1);
  }

  // Only print on proc 0
  if (localProc != 0) {
    verbose = false;
  }

  bool test_passed = true;
#ifdef HAVE_EPETRA
  //TEST HERE  
  Epetra_CrsMatrix* mat=create_epetra_test_matrix_1(numProcs,localProc,true);
  test_passed=probing_test(*mat,true);
  test_passed=test_passed && probing_test(*mat,false);

  // Cleanup
  delete mat;
  
#else
  std::cout << "probing main: currently can only test "
         << "rebalancing with Epetra enabled." << std::endl;
  test_passed = false;
#endif

  if (test_passed && verbose) {
    std::cout << "PROBING main: tests passed."<<std::endl;
  }

#ifdef HAVE_MPI
  MPI_Finalize();
#endif

  return(0);
}
Пример #2
0
//-------------------------------------------------------------------
bool test_rebalance_epetra_linproblem2(int numProcs, int localProc, bool verbose)
{
  bool test_passed = false;
#ifndef HAVE_MPI
  return(test_passed);
#endif

  Epetra_CrsMatrix* input_matrix =
    create_epetra_test_matrix_1(numProcs, localProc, verbose);

  Epetra_Vector* x = new Epetra_Vector(input_matrix->RowMap());
  Epetra_Vector* b = new Epetra_Vector(input_matrix->RowMap());
  Epetra_LinearProblem problem(input_matrix, x, b);

  Teuchos::ParameterList paramlist;

  //Wrap a RefCountPtr around the matrix graph, and specify 'false', meaning
  //that the RefCountPtr will not take ownership of the graph (will not
  //delete it).
  Teuchos::RefCountPtr<const Epetra_CrsGraph> graph =
    Teuchos::rcp( &(input_matrix->Graph()), false);

  Teuchos::RefCountPtr<Isorropia::Epetra::Partitioner> partitioner =
    Teuchos::rcp(new Isorropia::Epetra::Partitioner(graph, paramlist));

  Isorropia::Epetra::Redistributor rd(partitioner);

  Teuchos::RefCountPtr<Epetra_CrsMatrix> bal_matrix =
    rd.redistribute(*(problem.GetMatrix()));

  Teuchos::RefCountPtr<Epetra_MultiVector> bal_x =
    rd.redistribute(*(problem.GetLHS()));

  Teuchos::RefCountPtr<Epetra_MultiVector> bal_b =
    rd.redistribute(*(problem.GetRHS()));

  Teuchos::RefCountPtr<Epetra_LinearProblem> balanced_problem =
    Teuchos::rcp(new Epetra_LinearProblem(bal_matrix.get(),
					  bal_x.get(), bal_b.get()));

  //Now check the result matrix and make sure that the number of nonzeros
  //is indeed equal on each processor. (We constructed the input matrix
  //so that a correct rebalancing would result in the same number of
  //nonzeros being on each processor.)
  const Epetra_Map& bal_rowmap = balanced_problem->GetMatrix()->RowMatrixRowMap();
  int bal_local_num_rows = bal_rowmap.NumMyElements();

  //count the local nonzeros.
  if (verbose) {
    std::cout << "test_rebalance_epetra_linproblem: " << std::endl;
    std::cout << " counting local nnz for balanced matrix..." << std::endl;
  }

  int num_nonzeros = 0;
  for(int i=0; i<bal_local_num_rows; ++i) {
    int numrowentries = 0;
    balanced_problem->GetMatrix()->NumMyRowEntries(i,numrowentries);
    num_nonzeros += numrowentries;
  }

  const Epetra_Comm& comm = input_matrix->Comm();

  int global_num_nonzeros;
  comm.SumAll(&num_nonzeros, &global_num_nonzeros, 1);

  int avg_nnz_per_proc = global_num_nonzeros/numProcs;

  if (verbose) {
    std::cout << " making sure local nnz ("<<num_nonzeros
             <<") is the same on every proc...\n" << std::endl;
  }

  if (num_nonzeros == avg_nnz_per_proc) test_passed = true;

  int local_int_result = test_passed ? 1 : 0;
  int global_int_result;
  comm.MinAll(&local_int_result, &global_int_result, 1);

  test_passed = global_int_result==1 ? true : false;

  if (!test_passed && verbose) {
    std::cout << "test FAILED!" << std::endl;
  }

  delete input_matrix;
  delete x;
  delete b;

  return(test_passed);
}
Пример #3
0
//-------------------------------------------------------------------
bool test_rebalance_epetra_linproblem(int numProcs, int localProc, bool verbose)
{
  bool test_passed = false;
#ifndef HAVE_MPI
  return(test_passed);
#endif

  Epetra_CrsMatrix* input_matrix =
    create_epetra_test_matrix_1(numProcs, localProc, verbose);

  Epetra_Vector* x = new Epetra_Vector(input_matrix->RowMap());
  Epetra_Vector* b = new Epetra_Vector(input_matrix->RowMap());
  Epetra_LinearProblem problem(input_matrix, x, b);

  //Call the Isorropia rebalance method allowing default behavior. (I.e.,
  //we won't specify any parameters, weights, etc.) Default behavior should
  //be to balance the matrix so that the number of nonzeros on each processor
  //is roughly equal. i.e., by default, weights for each row are assumed to
  //be the number of nonzeros in that row.

  Epetra_LinearProblem *balanced_problem;

  try {
    if (verbose) {
      std::cout << " calling Isorropia::createBalancedCopy(Epetra_LinearProblem)..."
                << std::endl;
    }

    balanced_problem = Isorropia::Epetra::createBalancedCopy(problem);
  }
  catch(std::exception& exc) {
    std::cout << "caught exception: " << exc.what() << std::endl;
    return(false);
  }

  //Now check the result matrix and make sure that the number of nonzeros
  //is indeed equal on each processor. (We constructed the input matrix
  //so that a correct rebalancing would result in the same number of
  //nonzeros being on each processor.)
  const Epetra_Map& bal_rowmap = balanced_problem->GetMatrix()->RowMatrixRowMap();
  int bal_local_num_rows = bal_rowmap.NumMyElements();

  //count the local nonzeros.
  if (verbose) {
    std::cout << " counting local nnz for balanced matrix..." << std::endl;
  }

  int num_nonzeros = 0;
  for(int i=0; i<bal_local_num_rows; ++i) {
    int numrowentries = 0;
    balanced_problem->GetMatrix()->NumMyRowEntries(i,numrowentries);
    num_nonzeros += numrowentries;
  }

  delete balanced_problem;

  const Epetra_Comm& comm = input_matrix->Comm();

  int global_num_nonzeros;
  comm.SumAll(&num_nonzeros, &global_num_nonzeros, 1);

  int avg_nnz_per_proc = global_num_nonzeros/numProcs;

  if (verbose) {
    std::cout << " making sure local nnz ("<<num_nonzeros
             <<") is the same on every proc...\n" << std::endl;
  }

  if (num_nonzeros == avg_nnz_per_proc) test_passed = true;

  int local_int_result = test_passed ? 1 : 0;
  int global_int_result;
  comm.MinAll(&local_int_result, &global_int_result, 1);

  test_passed = global_int_result==1 ? true : false;

  if (!test_passed && verbose) {
    std::cout << "test FAILED!" << std::endl;
  }

  delete input_matrix;
  delete x;
  delete b;

  return(test_passed);
}