コード例 #1
0
ファイル: build_problem.cpp プロジェクト: 00liujj/trilinos
Teuchos::RCP< Epetra_LinearProblem >
build_problem(Teuchos::ParameterList& test_params,
              const Epetra_Comm& comm)
{
  Teuchos::Time timer("build_problem");
  timer.start();

  Epetra_CrsMatrix* A;
  Epetra_Vector* b = NULL;

  std::string mm_file("not specified");
  std::string rhs_mm_file("not specified");
  helper::GetParameter(test_params, "mm_file", mm_file);
  helper::GetParameter(test_params, "rhs_mm_file", rhs_mm_file);
  std::string hb_file("not specified");
  helper::GetParameter(test_params, "hb_file", hb_file);

  if (mm_file != "not specified") {
    if (comm.MyPID() == 0) {
      std::cout << "Matrix-Market file: " << mm_file << std::endl;
    }
    A = read_matrix_mm(mm_file, comm);
    if (rhs_mm_file != "not specified") {
      if (comm.MyPID() == 0) {
        std::cout << "Matrix-Market file: " << rhs_mm_file << std::endl;
      }
      b = read_vector_mm(rhs_mm_file, comm);
    }
  }
  else if (hb_file != "not specified") {
    read_matrix_hb(hb_file, comm, A, b);
  }
  else {
    throw std::runtime_error("No matrix file specified.");
  }

  Teuchos::RCP<Epetra_LinearProblem> problem = build_problem_mm(test_params, A, b);
  timer.stop();
  if (comm.MyPID() == 0) {
    std::cout << "proc 0 time to read matrix & create problem: " << timer.totalElapsedTime()
      << std::endl;
  }

  return problem;
}
コード例 #2
0
Teuchos::RCP<
    Belos::LinearProblem<
        Scalar,
        Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>,
        Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
   > build_problem(Teuchos::ParameterList& test_params,
                   const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
                   Teuchos::RCP<Node> node)
{
  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>    TOP;
  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>   TCRS;
  typedef Belos::LinearProblem<Scalar,TMV,TOP>                        BLinProb;

  Teuchos::RCP<const TCRS> A;
  Teuchos::RCP<TMV> b = Teuchos::null;
  Teuchos::RCP<TMV> nullVec = Teuchos::null;

  std::string mm_file("not specified");
  std::string rhs_mm_file("not specified");
  std::string nullMvec_mm_file("not specified");
  Ifpack2::getParameter(test_params, "mm_file", mm_file);
  Ifpack2::getParameter(test_params, "rhs_mm_file", rhs_mm_file);
  std::string hb_file("not specified");
  Ifpack2::getParameter(test_params, "hb_file", hb_file);

  if (mm_file != "not specified") {
    if (comm->getRank() == 0) {
      std::cout << "Matrix-Market file: " << mm_file << std::endl;
    }
    A = read_matrix_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(mm_file, comm);

    if (rhs_mm_file != "not specified") {
      if (comm->getRank() == 0) {
        std::cout << "Right-hand-side Matrix-Market file: " << rhs_mm_file << std::endl;
      }
      b = read_vector_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(rhs_mm_file, comm);
    }

    if (nullMvec_mm_file != "not specified") {
      if (comm->getRank() == 0) {
        std::cout << "null multivector Matrix-Market file: " << nullMvec_mm_file << std::endl;
      }
      nullVec = read_vector_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(rhs_mm_file, comm);
    }

  }
  else if (hb_file != "not specified") {
    if (comm->getRank() == 0) {
      std::cout << "Harwell-Boeing file: " << hb_file << std::endl;
    }
    A = read_matrix_hb<Scalar,LocalOrdinal,GlobalOrdinal,Node>(hb_file, comm, node);
  }
  else {
    throw std::runtime_error("No matrix file specified.");
  }

  Teuchos::RCP<BLinProb> problem = build_problem_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(test_params, A, b, nullVec);

  return problem;
}
コード例 #3
0
Teuchos::RCP<
Belos::LinearProblem<
Scalar,
Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>,
Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
> build_problem(Teuchos::ParameterList& test_params,
                const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
                Teuchos::RCP<Node> node,
                int myWeight)
{
    typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> TMV;
    typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node>      TV;
    typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node>    TOP;
    typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node>   TCRS;
    typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node>                TMap;
    typedef Belos::LinearProblem<Scalar,TMV,TOP>                        BLinProb;

    Teuchos::RCP<TCRS> A;
    Teuchos::RCP<TMV> b = Teuchos::null;
    Teuchos::RCP<TV> dvec;

    std::string mm_file("not specified");
    std::string rhs_mm_file("not specified");
    std::string gen_mat("not specified");
    // std::string hb_file("not specified");
    Ifpack2::getParameter(test_params, "mm_file", mm_file);
    int mm_file_maxnnz = test_params.get<int>("mm_file_maxnnz", -1);
    // Ifpack2::getParameter(test_params, "hb_file", hb_file);
    Ifpack2::getParameter(test_params, "rhs_mm_file", rhs_mm_file);
    Ifpack2::getParameter(test_params, "gen_mat", gen_mat);

    const bool IAmRoot = (comm->getRank() == 0);

    if (mm_file != "not specified") {
        if (IAmRoot) {
            std::cout << "Matrix-Market file: " << mm_file << std::endl;
        }
        read_matrix_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(mm_file, comm, node, myWeight, mm_file_maxnnz, A, dvec);

        if (rhs_mm_file != "not specified") {
            if (IAmRoot) {
                std::cout << "Right-hand-side Matrix-Market file: " << rhs_mm_file << std::endl;
            }
            b = read_vector_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(rhs_mm_file, comm, node, A->getRowMap());
        }
    }
    // else if (hb_file != "not specified") {
    //   if (IAmRoot) {
    //     std::cout << "Harwell-Boeing file: " << hb_file << std::endl;
    //   }
    //   A = read_matrix_hb<Scalar,LocalOrdinal,GlobalOrdinal,Node>(hb_file, comm, node, myWeight);
    // }
    else if (gen_mat != "not specified") {
        Teuchos::RCP<Teuchos::ParameterList> genparams = sublist(rcpFromRef(test_params),"GenMat");
        if (genparams == Teuchos::null) {
            throw std::runtime_error("Missing parameter list \"GenMat\".");
        }
        Teuchos::RCP<TCRS> ncA;
        Tpetra::Utils::generateMatrix(genparams,comm,node,ncA);
        A = ncA;
        dvec = rcp(new TV(A->getRowMap(), false));
        dvec->putScalar(6);
    }
    else {
        throw std::runtime_error("No matrix specified.");
    }

    // print node details
    {
        RCP<const Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> > importer = A->getGraph()->getImporter();
        for (int i=0; i<comm->getSize(); ++i) {
            if (comm->getRank() == i) {
                if (importer != Teuchos::null) {
                    if (IAmRoot) {
                        std::cout << "\nPartitioning details" << std::endl;
                    }
                    std::cout << "node: " << i
                              << "   same: " << importer->getNumSameIDs()
                              << "   permute: " << importer->getNumPermuteIDs()
                              << "   remote: " << importer->getNumRemoteIDs()
                              << "   export: " << importer->getNumExportIDs() << std::endl;
                }
            }
            comm->barrier();
            comm->barrier();
            comm->barrier();
        }
        if (IAmRoot) {
            std::cout << std::endl;
        }
    }

    Teuchos::RCP<BLinProb> problem = build_problem_mm<Scalar,LocalOrdinal,GlobalOrdinal,Node>(test_params, A, b, dvec);

    return problem;
}