本文整理汇总了C++中teuchos::CommandLineProcessor类的典型用法代码示例。如果您正苦于以下问题:C++ CommandLineProcessor类的具体用法?C++ CommandLineProcessor怎么用?C++ CommandLineProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandLineProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession session(&argc, &argv);
RCP<const Teuchos::Comm<int> > tcomm = Teuchos::DefaultComm<int>::getComm();
int rank = tcomm->getRank();
int nParts = tcomm->getSize();
bool doRemap = false;
string filename = "USAir97";
// Read run-time options.
Teuchos::CommandLineProcessor cmdp (false, false);
cmdp.setOption("file", &filename, "Name of the Matrix Market file to read");
cmdp.setOption("nparts", &nParts, "Number of parts.");
cmdp.setOption("remap", "no-remap", &doRemap, "Remap part numbers.");
cmdp.parse(argc, argv);
meshCoordinatesTest(tcomm);
testFromDataFile(tcomm, nParts, filename, doRemap);
if (rank == 0)
serialTest(nParts, doRemap);
if (rank == 0)
std::cout << "PASS" << std::endl;
}
示例2: mpiSession
int
main (int argc, char* argv[])
{
using KokkosBlas::Impl::testOverScalarsAndLayoutsAndDevices;
using std::cout;
using std::endl;
Teuchos::oblackholestream blackHole;
Teuchos::GlobalMPISession mpiSession (&argc, &argv, &blackHole);
Kokkos::initialize (argc, argv);
#ifdef HAVE_MPI
RCP<const Comm<int> > comm = rcp (new Teuchos::MpiComm<int> (MPI_COMM_WORLD));
#else
RCP<const Comm<int> > comm = rcp (new Teuchos::SerialComm<int> ());
#endif // HAVE_MPI
const int myRank = comm->getRank ();
// Number of columns in the 2-D View(s) to test.
int numCols = 3;
bool oneCol = false;
bool testComplex = true;
Teuchos::CommandLineProcessor cmdp (false, true);
cmdp.setOption ("numCols", &numCols,
"Number of columns in the 2-D View(s) to test");
cmdp.setOption ("oneCol", "noOneCol", &oneCol, "Whether to test the 1-D View "
"(single-column) versions of the kernels");
cmdp.setOption ("testComplex", "noTestComplex", &testComplex,
"Whether to test complex arithmetic");
if (cmdp.parse (argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
if (myRank == 0) {
cout << "TEST FAILED to parse command-line arguments!" << endl;
}
return EXIT_FAILURE;
}
bool curSuccess = true;
bool success = true;
// Always test with numCols=1 first.
curSuccess = testOverScalarsAndLayoutsAndDevices (cout, 1, oneCol, testComplex);
success = curSuccess && success;
if (numCols != 1) {
curSuccess = testOverScalarsAndLayoutsAndDevices (cout, numCols,
oneCol, testComplex);
success = curSuccess && success;
}
if (success) {
if (myRank == 0) {
cout << "End Result: TEST PASSED" << endl;
}
} else {
if (myRank == 0) {
cout << "End Result: TEST FAILED" << endl;
}
}
Kokkos::finalize ();
return EXIT_SUCCESS;
}
示例3: specified
void
parseCommandLineArguments (Teuchos::CommandLineProcessor& cmdp,
bool& printedHelp,
int argc,
char* argv[],
int& nx,
int& ny,
int& nz,
std::string& xmlInputParamsFile,
std::string& solverName,
bool& verbose,
bool& debug)
{
using Teuchos::CommandLineProcessor;
const CommandLineProcessor::EParseCommandLineReturn parseResult =
cmdp.parse (argc, argv);
if (parseResult == CommandLineProcessor::PARSE_HELP_PRINTED) {
printedHelp = true;
}
else {
printedHelp = false;
TEUCHOS_TEST_FOR_EXCEPTION(
parseResult != CommandLineProcessor::PARSE_SUCCESSFUL,
std::invalid_argument, "Failed to parse command-line arguments.");
TEUCHOS_TEST_FOR_EXCEPTION(
xmlInputParamsFile == "" && (nx <= 0 || ny <= 0 || nz <= 0),
std::invalid_argument, "If no XML parameters filename is specified (via "
"--inputParams), then the number of cells along each dimension of the "
"mesh (--nx, --ny, and --nz) must be positive.");
}
}
示例4: main
int main (int argc, char *argv[]) {
Teuchos::CommandLineProcessor clp;
clp.setDocString("This example program demonstrates ICholByBlocks algorithm on Kokkos::Threads execution space.\n");
int nthreads = 1;
clp.setOption("nthreads", &nthreads, "Number of threads");
int max_task_dependence = 10;
clp.setOption("max-task-dependence", &max_task_dependence, "Max number of task dependence");
int team_size = 1;
clp.setOption("team-size", &team_size, "Team size");
bool verbose = false;
clp.setOption("enable-verbose", "disable-verbose", &verbose, "Flag for verbose printing");
string file_input = "test.mtx";
clp.setOption("file-input", &file_input, "Input file (MatrixMarket SPD matrix)");
clp.recogniseAllOptions(true);
clp.throwExceptions(false);
Teuchos::CommandLineProcessor::EParseCommandLineReturn r_parse= clp.parse( argc, argv );
if (r_parse == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) return 0;
if (r_parse != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) return -1;
int r_val = 0;
{
exec_space::initialize(nthreads);
exec_space::print_configuration(cout, true);
r_val = exampleICholByBlocks
<value_type,ordinal_type,size_type,exec_space,void>
(file_input, max_task_dependence, team_size, verbose);
exec_space::finalize();
}
return r_val;
}
示例5: main
int main (int argc, char *argv[]) {
Teuchos::CommandLineProcessor clp;
clp.setDocString("Tacho::DenseMatrixBase examples on Pthreads execution space.\n");
int nthreads = 0;
clp.setOption("nthreads", &nthreads, "Number of threads");
int numa = 0;
clp.setOption("numa", &numa, "Number of numa node");
int core_per_numa = 0;
clp.setOption("core-per-numa", &core_per_numa, "Number of cores per numa node");
bool verbose = false;
clp.setOption("enable-verbose", "disable-verbose", &verbose, "Flag for verbose printing");
clp.recogniseAllOptions(true);
clp.throwExceptions(false);
Teuchos::CommandLineProcessor::EParseCommandLineReturn r_parse= clp.parse( argc, argv );
if (r_parse == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) return 0;
if (r_parse != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) return -1;
int r_val = 0;
{
exec_space::initialize(nthreads, numa, core_per_numa);
r_val = exampleCrsMatrixBase<exec_space>
(verbose);
exec_space::finalize();
}
return r_val;
}
示例6: main
int main(int argc, char *argv[]) {
Teuchos::CommandLineProcessor clp;
clp.setDocString("Intrepid2::DynRankView_PerfTest01.\n");
int nworkset = 8;
clp.setOption("nworkset", &nworkset, "# of worksets");
int C = 4096;
clp.setOption("C", &C, "# of Cells in a workset");
int order = 2;
clp.setOption("order", &order, "cubature order");
bool verbose = true;
clp.setOption("enable-verbose", "disable-verbose", &verbose, "Flag for verbose printing");
clp.recogniseAllOptions(true);
clp.throwExceptions(false);
Teuchos::CommandLineProcessor::EParseCommandLineReturn r_parse= clp.parse( argc, argv );
if (r_parse == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) return 0;
if (r_parse != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) return -1;
Kokkos::initialize();
if (verbose)
std::cout << "Testing datatype double\n";
const int r_val_double = Intrepid2::Test::ComputeBasis_HGRAD
<double,Kokkos::Cuda>(nworkset,
C,
order,
verbose);
return r_val_double;
}
示例7: ParameterList
void
setUpCommandLineArguments (Teuchos::CommandLineProcessor& cmdp,
int& nx,
int& ny,
int& nz,
std::string& xmlInputParamsFile,
std::string& solverName,
double& tol,
int& maxNumIters,
bool& verbose,
bool& debug)
{
cmdp.setOption ("nx", &nx, "Number of cells along the x dimension");
cmdp.setOption ("ny", &ny, "Number of cells along the y dimension");
cmdp.setOption ("nz", &nz, "Number of cells along the z dimension");
cmdp.setOption ("inputParams", &xmlInputParamsFile, "XML file of input "
"parameters, which we read if specified and not \"\". "
"If it has a \"meshInput\" parameter, we use its "
"std::string value as the Pamgen mesh specification. "
"Otherwise, we tell Pamgen to make a cube, using "
"nx, ny, and nz.");
cmdp.setOption ("solverName", &solverName, "Name of iterative linear solver "
"to use for solving the linear system. You may use any name "
"that Belos::SolverFactory understands. Examples include "
"\"GMRES\" and \"CG\".");
cmdp.setOption ("tol", &tol, "Tolerance for the linear solve. If not "
"specified, this is read from the input ParameterList (read "
"from the XML file). If specified, this overrides any value "
"in the input ParameterList.");
cmdp.setOption ("maxNumIters", &maxNumIters, "Maximum number of iterations "
"in the linear solve. If not specified, this is read from "
"the input ParameterList (read from the XML file). If "
"specified, this overrides any value in the input "
"ParameterList.");
cmdp.setOption ("verbose", "quiet", &verbose,
"Whether to print verbose status output.");
cmdp.setOption ("debug", "release", &debug,
"Whether to print copious debugging output to stderr.");
}
示例8: filename
int
main (int argc, char *argv[])
{
using Teuchos::inOutArg;
using Teuchos::ParameterList;
using Teuchos::parameterList;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::rcpFromRef;
using std::endl;
typedef double ST;
typedef Epetra_Operator OP;
typedef Epetra_MultiVector MV;
typedef Belos::OperatorTraits<ST,MV,OP> OPT;
typedef Belos::MultiVecTraits<ST,MV> MVT;
// This calls MPI_Init and MPI_Finalize as necessary.
Belos::Test::MPISession session (inOutArg (argc), inOutArg (argv));
RCP<const Epetra_Comm> comm = session.getComm ();
bool success = false;
bool verbose = false;
try {
int MyPID = comm->MyPID ();
//
// Parameters to read from command-line processor
//
int frequency = -1; // how often residuals are printed by solver
int numRHS = 1; // total number of right-hand sides to solve for
int maxIters = 13000; // maximum number of iterations for solver to use
std::string filename ("bcsstk14.hb");
double tol = 1.0e-5; // relative residual tolerance
//
// Read in command-line arguments
//
Teuchos::CommandLineProcessor cmdp (false, true);
cmdp.setOption ("verbose", "quiet", &verbose, "Print messages and results.");
cmdp.setOption ("frequency", &frequency, "Solvers frequency for printing "
"residuals (#iters).");
cmdp.setOption ("tol", &tol, "Relative residual tolerance used by MINRES "
"solver.");
cmdp.setOption ("filename", &filename, "Filename for Harwell-Boeing test "
"matrix.");
cmdp.setOption ("num-rhs", &numRHS, "Number of right-hand sides to solve.");
cmdp.setOption ("max-iters", &maxIters, "Maximum number of iterations per "
"linear system (-1 means \"adapt to problem/block size\").");
if (cmdp.parse (argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return EXIT_FAILURE;
}
Teuchos::oblackholestream blackHole;
std::ostream& verbOut = (verbose && MyPID == 0) ? std::cout : blackHole;
//
// Generate the linear system(s) to solve.
//
verbOut << "Generating the linear system(s) to solve" << endl << endl;
RCP<Epetra_CrsMatrix> A;
RCP<Epetra_MultiVector> B, X;
RCP<Epetra_Map> rowMap;
try {
// This might change the number of right-hand sides, if we read in
// a right-hand side from the Harwell-Boeing file.
Belos::Util::createEpetraProblem (filename, &rowMap, &A, &B, &X, &MyPID, numRHS);
} catch (std::exception& e) {
TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error,
"Failed to create Epetra problem for matrix "
"filename \"" << filename << "\". "
"createEpetraProblem() reports the following "
"error: " << e.what());
}
//
// Compute the initial residual norm of the problem, so we can see
// by how much it improved after the solve.
//
std::vector<double> initialResidualNorms (numRHS);
std::vector<double> initialResidualInfNorms (numRHS);
Epetra_MultiVector R (*rowMap, numRHS);
OPT::Apply (*A, *X, R);
MVT::MvAddMv (-1.0, R, 1.0, *B, R); // R := -(A*X) + B.
MVT::MvNorm (R, initialResidualNorms);
MVT::MvNorm (R, initialResidualInfNorms, Belos::InfNorm);
if (verbose) {
verbOut << "Initial residual 2-norms: \t";
for (int i = 0; i < numRHS; ++i) {
verbOut << initialResidualNorms[i];
if (i < numRHS-1) {
verbOut << ", ";
}
}
verbOut << endl << "Initial residual Inf-norms: \t";
for (int i = 0; i < numRHS; ++i) {
verbOut << initialResidualInfNorms[i];
if (i < numRHS-1) {
verbOut << ", ";
}
}
verbOut << endl;
}
//.........这里部分代码省略.........
示例9: main_
int main_(Teuchos::CommandLineProcessor &clp, int argc, char *argv[]) {
#include <MueLu_UseShortNames.hpp>
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::TimeMonitor;
// =========================================================================
// MPI initialization using Teuchos
// =========================================================================
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL);
RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
int numProc = comm->getSize();
int myRank = comm->getRank();
// =========================================================================
// Parameters initialization
// =========================================================================
::Xpetra::Parameters xpetraParameters(clp);
bool runHeavyTests = false;
clp.setOption("heavytests", "noheavytests", &runHeavyTests, "whether to exercise tests that take a long time to run");
clp.recogniseAllOptions(true);
switch (clp.parse(argc,argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
// =========================================================================
// Problem construction
// =========================================================================
ParameterList matrixParameters;
matrixParameters.set("nx", Teuchos::as<GO>(9999));
matrixParameters.set("matrixType", "Laplace1D");
RCP<Matrix> A = MueLuTests::TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(matrixParameters.get<GO>("nx"), lib);
RCP<MultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("1D", A->getRowMap(), matrixParameters);
std::string outDir = "Output/";
std::vector<std::string> dirList;
if (runHeavyTests) {
dirList.push_back("EasyParameterListInterpreter-heavy/");
dirList.push_back("FactoryParameterListInterpreter-heavy/");
} else {
dirList.push_back("EasyParameterListInterpreter/");
dirList.push_back("FactoryParameterListInterpreter/");
}
#if defined(HAVE_MPI) && defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_AMESOS2_KLU2)
// The ML interpreter have internal ifdef, which means that the resulting
// output would depend on configuration (reguarl interpreter does not have
// that). Therefore, we need to stabilize the configuration here.
// In addition, we run ML parameter list tests only if KLU is available
dirList.push_back("MLParameterListInterpreter/");
dirList.push_back("MLParameterListInterpreter2/");
#endif
int numLists = dirList.size();
bool failed = false;
Teuchos::Time timer("Interpreter timer");
//double lastTime = timer.wallTime();
for (int k = 0; k < numLists; k++) {
Teuchos::ArrayRCP<std::string> fileList = MueLuTests::TestHelpers::GetFileList(dirList[k],
(numProc == 1 ? std::string(".xml") : std::string("_np" + Teuchos::toString(numProc) + ".xml")));
for (int i = 0; i < fileList.size(); i++) {
// Set seed
std::srand(12345);
// Reset (potentially) cached value of the estimate
A->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
std::string xmlFile = dirList[k] + fileList[i];
std::string outFile = outDir + fileList[i];
std::string baseFile = outFile.substr(0, outFile.find_last_of('.'));
std::size_t found = baseFile.find("_np");
if (numProc == 1 && found != std::string::npos) {
#ifdef HAVE_MPI
baseFile = baseFile.substr(0, found);
#else
std::cout << "Skipping \"" << xmlFile << "\" as MPI is not enabled" << std::endl;
continue;
#endif
}
baseFile = baseFile + (lib == Xpetra::UseEpetra ? "_epetra" : "_tpetra");
std::string goldFile = baseFile + ".gold";
std::ifstream f(goldFile.c_str());
if (!f.good()) {
if (myRank == 0)
std::cout << "Warning: comparison file " << goldFile << " not found. Skipping test" << std::endl;
continue;
}
std::filebuf buffer;
std::streambuf* oldbuffer = NULL;
if (myRank == 0) {
//.........这里部分代码省略.........
示例10: main
// calls MPI_Init and MPI_Finalize
int main (int argc, char* argv[])
{
using Teuchos::RCP;
using Teuchos::rcp_dynamic_cast;
using panzer::StrPureBasisPair;
using panzer::StrPureBasisComp;
PHX::InitializeKokkosDevice();
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
RCP<Epetra_Comm> Comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout));
out.setOutputToRootOnly(0);
out.setShowProcRank(true);
const std::size_t workset_size = 20;
ProblemOptions po;
{
// Set up this problem with two discontinuous (A, C) and one continuous (B)
// fields.
// On fields A are imposed Neumann and weak Dirichlet matching interface conditions.
// On fields C are imposed Robin interface conditions, with one-way
// coupling to field B.
// If the Robin condition is linear, then the default setup is such that
// A, B, C all converge to the same solution for which the Solution
// evaluator provides the exact expression. A response function reports the
// error so a convergence test can be wrapped around multiple runs of this
// program.
// If the Robin condition is nonlinear, then the source is 0 and the
// solution is two planes with a jump of 0.4 at the interface.
Teuchos::CommandLineProcessor clp;
po.nxelem = 10;
clp.setOption("nx", &po.nxelem, "Number of elements in x direction");
po.nonlinear_Robin = false;
clp.setOption("nonlinear", "linear", &po.nonlinear_Robin,
"Use a nonlinear Robin interface condition");
po.rtol = 1e-10;
clp.setOption("rtol", &po.rtol, "Tolerance on residual norm");
po.is3d = false;
clp.setOption("3d", "2d", &po.is3d, "3D test instead of 2D");
po.mesh_filename = "";
clp.setOption("mesh-filename", &po.mesh_filename, "Optionally read from an Exodus mesh");
po.test_Jacobian = false;
clp.setOption("test-jacobian", "dont-test-jacobian", &po.test_Jacobian,
"Test Jacobian using finite differences.");
po.generate_mesh_only = false;
clp.setOption("generate-mesh-only", "dont-generate-mesh-only", &po.generate_mesh_only,
"Generate mesh, save, and quit.");
try {
clp.parse(argc, argv);
} catch (...) {
PHX::FinalizeKokkosDevice();
return -1;
}
po.nyelem = po.nxelem;
po.dof_names.push_back("A");
po.dof_names.push_back("B");
po.dof_names.push_back("C");
po.ss_names.push_back("left");
po.ss_names.push_back("vertical_0");
po.ss_names.push_back("right");
po.outer_iteration = true;
po.check_error = true;
out << po << "\n";
}
bool pass = true;
// Can be overridden by the equation set.
po.integration_order = 2;
// Construct mesh.
Teuchos::RCP<panzer_stk_classic::STK_MeshFactory> mesh_factory;
if ( ! po.mesh_filename.empty()) {
mesh_factory = Teuchos::rcp(new panzer_stk_classic::STK_ExodusReaderFactory(po.mesh_filename));
} else {
if (po.is3d)
mesh_factory = Teuchos::rcp(new panzer_stk_classic::CubeHexMeshFactory);
else
mesh_factory = Teuchos::rcp(new panzer_stk_classic::SquareQuadMeshFactory);
}
if (po.mesh_filename.empty()) {
// set mesh factory parameters
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
pl->set("X Blocks",2);
pl->set("Y Blocks",1);
if (po.is3d) pl->set("Z Blocks",1);
pl->set("X Elements", po.nxelem); // per block
pl->set("Y Elements", po.nyelem);
if (po.is3d) {
pl->set("Z Elements", po.nyelem);
pl->set("Build Interface Sidesets", true);
}
{ // If np is even, put ranks in both x and y directions; if not, go with
// default, which is x direction only. The x direction is the harder case.
//.........这里部分代码省略.........
示例11: main_
int main_(Teuchos::CommandLineProcessor &clp, Xpetra::UnderlyingLib lib, int argc, char *argv[]) {
#include <MueLu_UseShortNames.hpp>
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::TimeMonitor;
bool success = true;
bool verbose = true;
try {
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
Teuchos::FancyOStream& out = *fancy;
typedef Teuchos::ScalarTraits<SC> STS;
// =========================================================================
// Parameters initialization
// =========================================================================
//Teuchos::CommandLineProcessor clp(false);
GO nx = 100, ny = 100, nz = 100;
Galeri::Xpetra::Parameters<GO> galeriParameters(clp, nx, ny, nz, "Laplace2D"); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of Xpetra
std::string matFileName = ""; clp.setOption("matrix",&matFileName,"read matrix from a file");
LO blocksize = 1; clp.setOption("blocksize",&blocksize,"block size");
switch (clp.parse(argc, argv)) {
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break;
case Teuchos::CommandLineProcessor::PARSE_ERROR:
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break;
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break;
}
//Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
ParameterList galeriList = galeriParameters.GetParameterList();
if(lib!=Xpetra::UseTpetra)
throw std::runtime_error("This test only works with Tpetra linear algebra");
// =========================================================================
// Problem construction
// =========================================================================
RCP<const Map> map;
RCP<Matrix> A;
RCP<MultiVector> nullspace;
typedef Tpetra::CrsMatrix<SC,LO,GO,NO> Tpetra_CrsMatrix;
typedef Tpetra::Operator<SC,LO,GO,NO> Tpetra_Operator;
typedef Tpetra::Experimental::BlockCrsMatrix<SC,LO,GO,NO> Tpetra_BlockCrsMatrix;
typedef Xpetra::TpetraBlockCrsMatrix<SC,LO,GO,NO> Xpetra_TpetraBlockCrsMatrix;
typedef Xpetra::CrsMatrix<SC,LO,GO,NO> Xpetra_CrsMatrix;
typedef Xpetra::CrsMatrixWrap<SC,LO,GO,NO> Xpetra_CrsMatrixWrap;
typedef typename Teuchos::ScalarTraits<SC>::magnitudeType SCN;
RCP<Tpetra_CrsMatrix> Acrs;
RCP<Tpetra_BlockCrsMatrix> Ablock;
if(matFileName.length() > 0) {
// Read matrix from disk
out << thickSeparator << std::endl << "Reading matrix from disk" <<std::endl;
typedef Tpetra::MatrixMarket::Reader<Tpetra_CrsMatrix> reader_type;
Acrs = reader_type::readSparseFile(matFileName,comm);
}
else{
// Use Galeri
out << thickSeparator << std::endl << xpetraParameters << galeriParameters;
std::string matrixType = galeriParameters.GetMatrixType();
RCP<Xpetra::Matrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> > Axp;
MueLuExamples::generate_user_matrix_and_nullspace<Scalar,LocalOrdinal,GlobalOrdinal,Node>(matrixType,lib,galeriList,comm,Axp,nullspace);
Acrs = Xpetra::Helpers<SC,LO,GO,NO>::Op2NonConstTpetraCrs(Axp);
}
// Block this bad boy
Ablock = Tpetra::Experimental::convertToBlockCrsMatrix(*Acrs,blocksize);
// Now wrap BlockCrs to Xpetra::Matrix
RCP<Xpetra_CrsMatrix> Axt = rcp(new Xpetra_TpetraBlockCrsMatrix(Ablock));
A = rcp(new Xpetra_CrsMatrixWrap(Axt));
// =========================================================================
// Setups and solves
// =========================================================================
map=Xpetra::toXpetra(Acrs->getRowMap());
RCP<Vector> X1 = VectorFactory::Build(map);
RCP<Vector> X2 = VectorFactory::Build(map);
RCP<Vector> B = VectorFactory::Build(map);
B->setSeed(846930886);
B->randomize();
RCP<TimeMonitor> tm;
// Belos Options
RCP<Teuchos::ParameterList> SList = rcp(new Teuchos::ParameterList );
SList->set("Verbosity",Belos::Errors + Belos::Warnings + Belos::StatusTestDetails);
SList->set("Output Frequency",10);
SList->set("Output Style",Belos::Brief);
SList->set("Maximum Iterations",10);
SList->set("Convergence Tolerance",5e-2);
// =========================================================================
//.........这里部分代码省略.........
示例12: mpiSession
int
main (int argc, char *argv[])
{
using Teuchos::Comm;
using Teuchos::FancyOStream;
using Teuchos::getFancyOStream;
using Teuchos::oblackholestream;
using Teuchos::OSTab;
using Teuchos::ParameterList;
using Teuchos::parameterList;
using Teuchos::RCP;
using Teuchos::rcpFromRef;
using std::cout;
using std::endl;
//
// Typedefs for Tpetra template arguments.
//
typedef double scalar_type;
typedef long int global_ordinal_type;
typedef int local_ordinal_type;
typedef Kokkos::DefaultNode::DefaultNodeType node_type;
//
// Tpetra objects which are the MV and OP template parameters of the
// Belos specialization which we are testing.
//
typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MV;
typedef Tpetra::Operator<scalar_type, local_ordinal_type, global_ordinal_type, node_type> OP;
//
// Other typedefs.
//
typedef Teuchos::ScalarTraits<scalar_type> STS;
typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> sparse_matrix_type;
Teuchos::GlobalMPISession mpiSession (&argc, &argv, &cout);
RCP<const Comm<int> > comm = Tpetra::DefaultPlatform::getDefaultPlatform().getComm();
RCP<node_type> node = Tpetra::DefaultPlatform::getDefaultPlatform().getNode();
RCP<oblackholestream> blackHole (new oblackholestream);
const int myRank = comm->getRank();
// Output stream that prints only on Rank 0.
RCP<FancyOStream> out;
if (myRank == 0) {
out = Teuchos::getFancyOStream (rcpFromRef (cout));
} else {
out = Teuchos::getFancyOStream (blackHole);
}
//
// Get test parameters from command-line processor.
//
// CommandLineProcessor always understands int, but may not
// understand global_ordinal_type. We convert to the latter below.
int numRows = comm->getSize() * 100;
bool tolerant = false;
bool verbose = false;
bool debug = false;
Teuchos::CommandLineProcessor cmdp (false, true);
cmdp.setOption("numRows", &numRows,
"Global number of rows (and columns) in the sparse matrix to generate.");
cmdp.setOption("tolerant", "intolerant", &tolerant,
"Whether to parse files tolerantly.");
cmdp.setOption("verbose", "quiet", &verbose,
"Print messages and results.");
cmdp.setOption("debug", "release", &debug,
"Run debugging checks and print copious debugging output.");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
*out << "\nEnd Result: TEST FAILED" << endl;
return EXIT_FAILURE;
}
// Output stream for verbose output.
RCP<FancyOStream> verbOut = verbose ? out : getFancyOStream (blackHole);
const bool success = true;
// Test whether it's possible to instantiate the solver.
// This is a minimal compilation test.
*verbOut << "Instantiating Block GCRODR solver" << endl;
Belos::BlockGCRODRSolMgr<scalar_type, MV, OP> solver;
//
// Test setting solver parameters. For now, we just use an empty
// (but non-null) parameter list, which the solver should fill in
// with defaults.
//
*verbOut << "Setting solver parameters" << endl;
RCP<ParameterList> solverParams = parameterList ();
solver.setParameters (solverParams);
//
// Create a linear system to solve.
//
*verbOut << "Creating linear system" << endl;
RCP<sparse_matrix_type> A;
RCP<MV> X_guess, X_exact, B;
{
typedef Belos::Tpetra::ProblemMaker<sparse_matrix_type> factory_type;
factory_type factory (comm, node, out, tolerant, debug);
RCP<ParameterList> problemParams = parameterList ();
problemParams->set ("Global number of rows",
static_cast<global_ordinal_type> (numRows));
problemParams->set ("Problem type", std::string ("Nonsymmetric"));
//.........这里部分代码省略.........
示例13: main
int main(int argc,char * argv[])
{
typedef panzer::unit_test::CartesianConnManager<int,panzer::Ordinal64> CCM;
typedef panzer::DOFManager<int,panzer::Ordinal64> DOFManager;
using Teuchos::RCP;
using Teuchos::rcp;
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
Kokkos::initialize(argc,argv);
Teuchos::MpiComm<int> comm(MPI_COMM_WORLD);
int np = comm.getSize(); // number of processors
// timings output
std::string timingsFile = "timings.yaml";
// mesh description
int nx = 10, ny = 7, nz = 4;
int px = np, py = 1, pz = 1;
int bx = 1, by = 2, bz = 1;
// parse command line arguments
Teuchos::CommandLineProcessor clp;
clp.setOption("nx",&nx);
clp.setOption("ny",&ny);
clp.setOption("nz",&nz);
clp.setOption("px",&px);
clp.setOption("py",&py);
clp.setOption("pz",&pz);
clp.setOption("timings-file",&timingsFile);
auto cmdResult = clp.parse(argc,argv);
if(cmdResult!=Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
clp.printHelpMessage(argv[0],std::cout);
return -1;
}
// build velocity, temperature and pressure fields
RCP<const panzer::FieldPattern> pattern_U = buildFieldPattern<Intrepid2::Basis_HGRAD_HEX_C2_FEM<PHX::Device::execution_space,double,double>>();
RCP<const panzer::FieldPattern> pattern_P = buildFieldPattern<Intrepid2::Basis_HGRAD_HEX_C1_FEM<PHX::Device::execution_space,double,double>>();
RCP<const panzer::FieldPattern> pattern_T = buildFieldPattern<Intrepid2::Basis_HGRAD_HEX_C1_FEM<PHX::Device::execution_space,double,double>>();
RCP<const panzer::FieldPattern> pattern_B = buildFieldPattern<Intrepid2::Basis_HDIV_HEX_I1_FEM<PHX::Device::execution_space,double,double>>();
RCP<const panzer::FieldPattern> pattern_E = buildFieldPattern<Intrepid2::Basis_HCURL_HEX_I1_FEM<PHX::Device::execution_space,double,double>>();
// repeatedly construct DOFManager timing the buildGlobalUnknowns
for(int repeats=0;repeats<100;repeats++) {
// build the topology
RCP<CCM> connManager = rcp(new CCM);
connManager->initialize(comm,
Teuchos::as<panzer::Ordinal64>(nx),
Teuchos::as<panzer::Ordinal64>(ny),
Teuchos::as<panzer::Ordinal64>(nz),
px,py,pz,bx,by,bz);
// build the dof manager, and assocaite with the topology
RCP<DOFManager> dofManager = rcp(new DOFManager);
dofManager->setConnManager(connManager,*comm.getRawMpiComm());
// add velocity (U) and PRESSURE fields to the MHD element block
dofManager->addField("eblock-0_0_0","UX",pattern_U);
dofManager->addField("eblock-0_0_0","UY",pattern_U);
dofManager->addField("eblock-0_0_0","UZ",pattern_U);
dofManager->addField("eblock-0_0_0","PRESSURE",pattern_P);
dofManager->addField("eblock-0_0_0","B",pattern_B);
dofManager->addField("eblock-0_0_0","E",pattern_E);
// add velocity (U) fields to the solid element block
dofManager->addField("eblock-0_1_0","UX",pattern_U);
dofManager->addField("eblock-0_1_0","UY",pattern_U);
dofManager->addField("eblock-0_1_0","UZ",pattern_U);
// try to get them all synced up
comm.barrier();
{
PANZER_FUNC_TIME_MONITOR("panzer::ScalingTest::buildGlobalUnknowns");
dofManager->buildGlobalUnknowns();
}
}
Teuchos::TimeMonitor::summarize(std::cout,false,true,false);
if ( timingsFile != "" ){
std::ofstream fout(timingsFile.c_str());
Teuchos::RCP<Teuchos::ParameterList> reportParams = parameterList(* (Teuchos::TimeMonitor::getValidReportParameters()));
reportParams->set("Report format", "YAML");
reportParams->set("YAML style", "spacious");
Teuchos::TimeMonitor::report(fout,reportParams);
}
// this confirms the application passes
std::cout << "Scaling test completed" << std::endl;
return 0;
}
示例14: main
int main(int argc, char * argv[])
{
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::rcpFromRef;
Teuchos::GlobalMPISession mpiSession(&argc,&argv,&std::cout);
std::string output_file_name = "square_mesh.gen";
int xBlocks=1,yBlocks=1, zBlocks=1;
int xElements=1,yElements=1, zElements=1;
double x0=0.0, xf=1.0;
double y0=0.0, yf=1.0;
double z0=0.0, zf=1.0;
bool threeD = false;
// setup input arguments
{
Teuchos::CommandLineProcessor clp;
clp.throwExceptions(false);
clp.setOption("o", &output_file_name, "Mesh output filename");
clp.setOption("3d", "2d", &threeD, "Cube versus square mesh.");
clp.setOption("x-blocks", &xBlocks, "Number of blocks in 'x' direction");
clp.setOption("y-blocks", &yBlocks, "Number of blocks in 'y' direction");
clp.setOption("z-blocks", &zBlocks, "Number of blocks in 'z' direction");
clp.setOption("x-elmts", &xElements, "Number of elements in 'x' direction in each block");
clp.setOption("y-elmts", &yElements, "Number of elements in 'y' direction in each block");
clp.setOption("z-elmts", &zElements, "Number of elements in 'z' direction in each block");
clp.setOption("x0", &x0, "Location of left edge");
clp.setOption("xf", &xf, "Location of right edge");
clp.setOption("y0", &y0, "Location of left edge");
clp.setOption("yf", &yf, "Location of right edge");
clp.setOption("z0", &z0, "Location of front(?) edge");
clp.setOption("zf", &zf, "Location of back(?) edge");
Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv,&std::cerr);
if(parse_return==Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED)
return -1;
TEUCHOS_TEST_FOR_EXCEPTION(parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL,
std::runtime_error, "Failed to parse command line!");
}
RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList);
pl->set("X Blocks",xBlocks);
pl->set("Y Blocks",yBlocks);
pl->set("X Elements",xElements);
pl->set("Y Elements",yElements);
pl->set("X0",x0);
pl->set("Y0",y0);
pl->set("Xf",xf);
pl->set("Yf",yf);
if(threeD) {
pl->set("Z Blocks",zBlocks);
pl->set("Z Elements",zElements);
pl->set("Z0",z0);
pl->set("Zf",zf);
}
int numprocs = stk_classic::parallel_machine_size(MPI_COMM_WORLD);
int rank = stk_classic::parallel_machine_rank(MPI_COMM_WORLD);
RCP<panzer_stk_classic::STK_MeshFactory> factory;
if(!threeD)
factory = Teuchos::rcp(new panzer_stk_classic::SquareQuadMeshFactory);
else
factory = Teuchos::rcp(new panzer_stk_classic::CubeHexMeshFactory);
factory->setParameterList(pl);
RCP<panzer_stk_classic::STK_Interface> mesh = factory->buildMesh(MPI_COMM_WORLD);
mesh->writeToExodus(output_file_name);
return 0;
}
示例15: main
int main(int argc, char *argv[]) {
int r_val = 0;
Teuchos::CommandLineProcessor clp;
int nthreads = 1;
clp.setOption("nthreads", &nthreads, "Number of threads");
clp.recogniseAllOptions(true);
clp.throwExceptions(false);
Teuchos::CommandLineProcessor::EParseCommandLineReturn r_parse= clp.parse( argc, argv );
if (r_parse != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
cout << "Testing Kokkos::Qthread:: Failed in parsing command line input" << endl;
return -1;
}
if (r_parse == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED) {
return 0;
}
unsigned threads_count = 0;
if (Kokkos::hwloc::available()) {
const unsigned numa_count = Kokkos::hwloc::get_available_numa_count();
const unsigned cores_per_numa = Kokkos::hwloc::get_available_cores_per_numa();
const unsigned threads_per_core = Kokkos::hwloc::get_available_threads_per_core();
const unsigned one = 1u;
threads_count = max(one, numa_count)*max(one, cores_per_numa)*max(one, threads_per_core);
cout << " = Kokkos::hwloc = " << endl
<< "NUMA count = " << numa_count << endl
<< "Cores per NUMA = " << cores_per_numa << endl
<< "Threads per core = " << threads_per_core << endl
<< "Threads count = " << threads_count << endl;
} else {
threads_count = thread::hardware_concurrency();
cout << " = std::thread::hardware_concurrency = " << endl
<< "Threads count = " << threads_count << endl;
}
if (static_cast<unsigned int>(nthreads) > threads_count) {
++r_val;
cout << "Testing Kokkos::Threads:: Failed that the given nthreads is greater than the number of threads counted" << endl;
} else {
Kokkos::Threads::initialize( nthreads );
Kokkos::Threads::print_configuration( cout , true /* detailed */ );
//__TestSuiteDoUnitTests__(float,int,unsigned int,Kokkos::Serial,void);
//__TestSuiteDoUnitTests__(float,long,unsigned long,Kokkos::Serial,void);
__TestSuiteDoUnitTests__(double,int,unsigned int,Kokkos::Threads,void);
// __TestSuiteDoUnitTests__(double,long,unsigned long,Kokkos::Serial,void);
// __TestSuiteDoUnitTests__(complex<float>,int,unsigned int,Kokkos::Serial,void);
// __TestSuiteDoUnitTests__(complex<float>,long,unsigned long,Kokkos::Serial,void);
// __TestSuiteDoUnitTests__(complex<double>,int,unsigned int,Kokkos::Serial,void);
// __TestSuiteDoUnitTests__(complex<double>,long,unsigned long,Kokkos::Serial,void);
Kokkos::Threads::finalize();
}
string eval;
__EVAL_STRING__(r_val, eval);
cout << "Testing Kokkos::Threads::" << eval << endl;
return r_val;
}