本文整理汇总了C++中teuchos::CommandLineProcessor::parse方法的典型用法代码示例。如果您正苦于以下问题:C++ CommandLineProcessor::parse方法的具体用法?C++ CommandLineProcessor::parse怎么用?C++ CommandLineProcessor::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::CommandLineProcessor
的用法示例。
在下文中一共展示了CommandLineProcessor::parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[]) {
Teuchos::CommandLineProcessor clp;
clp.setDocString("This example program measure the performance of IChol algorithms 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 team_interface = false;
clp.setOption("enable-team-interface", "disable-team-interface",
&team_interface, "Flag for team interface");
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)");
int niter = 10;
clp.setOption("niter", &niter, "Number of iterations for testing");
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;
{
const bool overwrite = true;
const int nshepherds = (team_interface ? nthreads/team_size : nthreads);
const int nworker_per_shepherd = nthreads/nshepherds;
setenv("QT_HWPAR", to_string(nthreads).c_str(), overwrite);
setenv("QT_NUM_SHEPHERDS", to_string(nshepherds).c_str(), overwrite);
setenv("QT_NUM_WORKERS_PER_SHEPHERD", to_string(nworker_per_shepherd).c_str(), overwrite);
exec_space::initialize(nthreads);
exec_space::print_configuration(cout, true);
// r_val = exampleICholPerformance
// <value_type,ordinal_type,size_type,exec_space,void>
// (file_input, niter, nthreads, max_task_dependence, team_size, team_interface, (nthreads != 1), verbose);
exec_space::finalize();
unsetenv("QT_HWPAR");
unsetenv("QT_NUM_SHEPHERDS");
unsetenv("QT_NUM_WORKERS_PER_SHEPHERD");
}
return r_val;
}
示例2: main
int main(int argc, char **argv)
{
// Typename of Polynomial Chaos scalar type
typedef Stokhos::StandardStorage<int,double> pce_storage_type;
typedef Sacado::ETPCE::OrthogPoly<double, pce_storage_type> pce_type;
// Typename of ensemble scalar type
const int EnsembleSize = 8;
typedef Stokhos::StaticFixedStorage<int,double,EnsembleSize,Kokkos::DefaultExecutionSpace> ensemble_storage_type;
typedef Sacado::MP::Vector<ensemble_storage_type> ensemble_type;
// Short-hand for several classes used below
using Teuchos::Array;
using Teuchos::RCP;
using Teuchos::rcp;
using Stokhos::OneDOrthogPolyBasis;
using Stokhos::HermiteBasis;
using Stokhos::LegendreBasis;
using Stokhos::CompletePolynomialBasis;
using Stokhos::Quadrature;
using Stokhos::TotalOrderIndexSet;
using Stokhos::SmolyakSparseGridQuadrature;
using Stokhos::TensorProductQuadrature;
using Stokhos::Sparse3Tensor;
using Stokhos::QuadOrthogPolyExpansion;
try {
// Setup command line options
Teuchos::CommandLineProcessor CLP;
CLP.setDocString(
"This example computes the PC expansion of a simple function.\n");
int p = 4;
CLP.setOption("order", &p, "Polynomial order");
bool sparse = false;
CLP.setOption("sparse", "tensor", &sparse,
"Use sparse grid or tensor product quadrature");
// Parse arguments
CLP.parse( argc, argv );
// Basis of dimension 3, order given by command-line option
const int d = 3;
Array< RCP<const OneDOrthogPolyBasis<int,double> > > bases(d);
for (int i=0; i<d; i++) {
bases[i] = rcp(new HermiteBasis<int,double>(p, true));
}
RCP<const CompletePolynomialBasis<int,double> > basis =
rcp(new CompletePolynomialBasis<int,double>(bases));
const int pce_size = basis->size();
std::cout << "basis size = " << pce_size << std::endl;
// Quadrature method
RCP<const Quadrature<int,double> > quad;
if (sparse) {
const TotalOrderIndexSet<int> index_set(d, p);
quad = rcp(new SmolyakSparseGridQuadrature<int,double>(basis, index_set));
}
else {
quad = rcp(new TensorProductQuadrature<int,double>(basis));
}
std::cout << "quadrature size = " << quad->size() << std::endl;
// Triple product tensor
RCP<Sparse3Tensor<int,double> > Cijk =
basis->computeTripleProductTensor();
// Expansion method
RCP<QuadOrthogPolyExpansion<int,double> > expn =
rcp(new QuadOrthogPolyExpansion<int,double>(basis, Cijk, quad));
// Polynomial expansion of u (note: these are coefficients in the
// normalized basis)
pce_type u(expn);
u.term(0,0) = 1.0; // zeroth order term
u.term(0,1) = 0.1; // first order term for dimension 0
u.term(1,1) = 0.05; // first order term for dimension 1
u.term(2,1) = 0.01; // first order term for dimension 2
//
// Compute PCE expansion of function using NISP with ensemble propagation
//
// Extract quadrature data
const int num_quad_points = quad->size();
const Array<double>& quad_weights = quad->getQuadWeights();
const Array< Array<double> >& quad_points = quad->getQuadPoints();
const Array< Array<double> >& quad_values = quad->getBasisAtQuadPoints();
// Loop over quadrature points in blocks of size EnsembleSize
pce_type v(expn);
ensemble_type u_ensemble;
for (int qp_block=0; qp_block<num_quad_points; qp_block+=EnsembleSize) {
const int qp_sz = qp_block+EnsembleSize <= num_quad_points ?
EnsembleSize : num_quad_points-qp_block;
// Evaluate u at each quadrature point
for (int qp=0; qp<qp_sz; ++qp)
u_ensemble.fastAccessCoeff(qp) =
u.evaluate(quad_points[qp_block+qp], quad_values[qp_block+qp]);
//.........这里部分代码省略.........
示例3: main
int main(int argc, char **argv)
{
try {
// Initialize MPI
#ifdef HAVE_MPI
MPI_Init(&argc,&argv);
#endif
// Setup command line options
Teuchos::CommandLineProcessor CLP;
CLP.setDocString(
"This example generates the sparsity pattern for the block stochastic Galerkin matrix.\n");
int d = 3;
CLP.setOption("dimension", &d, "Stochastic dimension");
int p = 5;
CLP.setOption("order", &p, "Polynomial order");
double drop = 1.0e-12;
CLP.setOption("drop", &drop, "Drop tolerance");
std::string file = "A.mm";
CLP.setOption("filename", &file, "Matrix Market filename");
BasisType basis_type = LEGENDRE;
CLP.setOption("basis", &basis_type,
num_basis_types, basis_type_values, basis_type_names,
"Basis type");
Stokhos::GrowthPolicy growth_type = Stokhos::SLOW_GROWTH;
CLP.setOption("growth", &growth_type,
num_growth_types, growth_type_values, growth_type_names,
"Growth type");
ProductBasisType prod_basis_type = COMPLETE;
CLP.setOption("product_basis", &prod_basis_type,
num_prod_basis_types, prod_basis_type_values,
prod_basis_type_names,
"Product basis type");
double alpha = 1.0;
CLP.setOption("alpha", &alpha, "Jacobi alpha index");
double beta = 1.0;
CLP.setOption("beta", &beta, "Jacobi beta index");
bool full = true;
CLP.setOption("full", "linear", &full, "Use full or linear expansion");
bool use_old = false;
CLP.setOption("old", "new", &use_old, "Use old or new Cijk algorithm");
int tile_size = 100;
CLP.setOption("tile_size", &tile_size, "Tile size");
// Parse arguments
CLP.parse( argc, argv );
// Basis
Array< RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d);
for (int i=0; i<d; i++) {
if (basis_type == HERMITE)
bases[i] = Teuchos::rcp(new Stokhos::HermiteBasis<int,double>(
p, true, growth_type));
else if (basis_type == LEGENDRE)
bases[i] = Teuchos::rcp(new Stokhos::LegendreBasis<int,double>(
p, true, growth_type));
else if (basis_type == CC_LEGENDRE)
bases[i] =
Teuchos::rcp(new Stokhos::ClenshawCurtisLegendreBasis<int,double>(
p, true));
else if (basis_type == GP_LEGENDRE)
bases[i] =
Teuchos::rcp(new Stokhos::GaussPattersonLegendreBasis<int,double>(
p, true));
else if (basis_type == RYS)
bases[i] = Teuchos::rcp(new Stokhos::RysBasis<int,double>(
p, 1.0, true, growth_type));
else if (basis_type == JACOBI)
bases[i] = Teuchos::rcp(new Stokhos::JacobiBasis<int,double>(
p, alpha, beta, true, growth_type));
}
RCP<const Stokhos::ProductBasis<int,double> > basis;
if (prod_basis_type == COMPLETE)
basis =
Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(
bases, drop, use_old));
else if (prod_basis_type == TENSOR)
basis =
Teuchos::rcp(new Stokhos::TensorProductBasis<int,double>(
bases, drop));
else if (prod_basis_type == TOTAL)
basis =
Teuchos::rcp(new Stokhos::TotalOrderBasis<int,double>(
bases, drop));
else if (prod_basis_type == SMOLYAK) {
Stokhos::TotalOrderIndexSet<int> index_set(d, p);
basis =
Teuchos::rcp(new Stokhos::SmolyakBasis<int,double>(
bases, index_set, drop));
}
// Triple product tensor
typedef Stokhos::Sparse3Tensor<int,double> Cijk_type;
RCP<Cijk_type> Cijk;
if (full)
Cijk = basis->computeTripleProductTensor();
else
Cijk = basis->computeLinearTripleProductTensor();
//.........这里部分代码省略.........
示例4: main
int main(int narg, char *arg[]) {
Teuchos::GlobalMPISession mpiSession(&narg, &arg,0);
Platform &platform = Tpetra::DefaultPlatform::getDefaultPlatform();
RCP<const Teuchos::Comm<int> > CommT = platform.getComm();
int me = CommT->getRank();
//int numProcs = CommT->getSize();
if (me == 0){
cout
<< "====================================================================\n"
<< "| |\n"
<< "| Example: Partition APF Mesh |\n"
<< "| |\n"
<< "| Questions? Contact Karen Devine ([email protected]), |\n"
<< "| Erik Boman ([email protected]), |\n"
<< "| Siva Rajamanickam ([email protected]). |\n"
<< "| |\n"
<< "| Pamgen's website: http://trilinos.sandia.gov/packages/pamgen |\n"
<< "| Zoltan2's website: http://trilinos.sandia.gov/packages/zoltan2 |\n"
<< "| Trilinos website: http://trilinos.sandia.gov |\n"
<< "| |\n"
<< "====================================================================\n";
}
#ifdef HAVE_MPI
if (me == 0) {
cout << "PARALLEL executable \n";
}
#else
if (me == 0) {
cout << "SERIAL executable \n";
}
#endif
/***************************************************************************/
/******************************* GET INPUTS ********************************/
/***************************************************************************/
// default values for command-line arguments
std::string meshFileName("4/");
std::string modelFileName("torus.dmg");
std::string action("zoltan_hg");
std::string parma_method("VtxElm");
std::string output_loc("");
int nParts = CommT->getSize();
double imbalance=1.1;
// Read run-time options.
Teuchos::CommandLineProcessor cmdp (false, false);
cmdp.setOption("meshfile", &meshFileName,
"Mesh file with APF specifications (.smb file(s))");
cmdp.setOption("modelfile", &modelFileName,
"Model file with APF specifications (.dmg file)");
cmdp.setOption("action", &action,
"Method to use: mj, scotch, zoltan_rcb, parma or color");
cmdp.setOption("parma_method", &parma_method,
"Method to use: Vertex, Edge, Element, VtxElm, VtxEdgeElm, ElmLtVtx, Ghost, or Shape ");
cmdp.setOption("nparts", &nParts,
"Number of parts to create");
cmdp.setOption("imbalance", &imbalance,
"Target Imbalance for first partitioner");
cmdp.setOption("output", &output_loc,
"Location of new partitioned apf mesh. Ex: 4/torus.smb");
cmdp.parse(narg, arg);
/***************************************************************************/
/********************** GET CELL TOPOLOGY **********************************/
/***************************************************************************/
// Get dimensions
//int dim = 3;
/***************************************************************************/
/***************************** GENERATE MESH *******************************/
/***************************************************************************/
#ifdef HAVE_ZOLTAN2_PARMA
if (me == 0) cout << "Generating mesh ... \n\n";
//Setup for SCOREC
PCU_Comm_Init();
// Generate mesh with MDS
gmi_register_mesh();
apf::Mesh2* m = apf::loadMdsMesh(modelFileName.c_str(),meshFileName.c_str());
runTest(CommT,m,action,parma_method,nParts,imbalance,"partition");
runTest(CommT,m,"parma",parma_method,nParts,imbalance,"parma");
if (output_loc!="") {
m->writeNative(output_loc.c_str());
//.........这里部分代码省略.........
示例5: main_
int main_(Teuchos::CommandLineProcessor &clp, int argc, char *argv[]) {
#include <MueLu_UseShortNames.hpp>
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::ArrayRCP;
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();
// =========================================================================
// Convenient definitions
// =========================================================================
typedef Teuchos::ScalarTraits<SC> STS;
SC one = STS::one(), zero = STS::zero();
RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
Teuchos::FancyOStream& out = *fancy;
out.setOutputToRootOnly(0);
// =========================================================================
// Parameters initialization
// =========================================================================
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 xmlFileName = ""; clp.setOption("xml", &xmlFileName, "read parameters from a file");
int numRebuilds = 0; clp.setOption("rebuild", &numRebuilds, "#times to rebuild hierarchy");
bool useFilter = true; clp.setOption("filter", "nofilter", &useFilter, "Print out only Setup times");
bool modify = true; clp.setOption("modify", "nomodify", &modify, "Change values of the matrix used for reuse");
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();
ParameterList paramList;
paramList.set("verbosity", "none");
if (xmlFileName != "")
Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<ParameterList>(¶mList), *comm);
// Retrieve matrix parameters (they may have been changed on the command line)
// [for instance, if we changed matrix type from 2D to 3D we need to update nz]
ParameterList galeriList = galeriParameters.GetParameterList();
// =========================================================================
// Problem construction
// =========================================================================
// For comments, see Driver.cpp
out << "========================================================\n" << xpetraParameters << galeriParameters;
std::string matrixType = galeriParameters.GetMatrixType();
RCP<Matrix> A, B;
RCP<const Map> map;
RCP<MultiVector> coordinates, nullspace;
ConstructData(matrixType, galeriList, lib, comm, A, map, coordinates, nullspace);
if (modify) {
galeriList.set("stretchx", 2.2);
galeriList.set("stretchy", 1.2);
galeriList.set("stretchz", 0.3);
}
ConstructData(matrixType, galeriList, lib, comm, B, map, coordinates, nullspace);
out << "Processor subdomains in x direction: " << galeriList.get<GO>("mx") << std::endl
<< "Processor subdomains in y direction: " << galeriList.get<GO>("my") << std::endl
<< "Processor subdomains in z direction: " << galeriList.get<GO>("mz") << std::endl
<< "========================================================" << std::endl;
// =========================================================================
// Setups and solves
// =========================================================================
RCP<Vector> X = VectorFactory::Build(map);
RCP<Vector> Y = VectorFactory::Build(map);
Y->setSeed(846930886);
Y->randomize();
const int nIts = 9;
std::string thickSeparator = "=============================================================";
std::string thinSeparator = "-------------------------------------------------------------";
// =========================================================================
// Setup #1 (no reuse)
// =========================================================================
out << thickSeparator << " no reuse " << thickSeparator << std::endl;
{
RCP<Hierarchy> H;
// Run multiple builds for matrix A and time them
RCP<Teuchos::Time> tm = TimeMonitor::getNewTimer("Setup #1: no reuse");
for (int i = 0; i <= numRebuilds; i++) {
//.........这里部分代码省略.........
示例6: main
int main(int argc, char* argv[]) {
int ierr = 0;
int p = 1;
int w = p+7;
int w_name = 13;
try {
// Set up command line options
Teuchos::CommandLineProcessor clp;
clp.setDocString("This program tests the speed of various forward mode AD implementations for a finite-element-like Jacobian fill");
int work_count = 200000;
int num_eqns_begin = 5;
int num_eqns_end = 65;
int num_eqns_delta = 10;
int rt = 0;
clp.setOption("wc", &work_count, "Work count = num_nodes*num_eqns");
clp.setOption("p_begin", &num_eqns_begin, "Intitial number of equations");
clp.setOption("p_end", &num_eqns_end, "Final number of equations");
clp.setOption("p_delta", &num_eqns_delta, "Step in number of equations");
clp.setOption("rt", &rt, "Include ADOL-C retaping test");
// Parse options
Teuchos::CommandLineProcessor::EParseCommandLineReturn
parseReturn= clp.parse(argc, argv);
if(parseReturn != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
return 1;
// Print header
std::cout.setf(std::ios::right);
std::cout << std::setw(w_name) << "Name" << " ";
for (int num_eqns = num_eqns_begin; num_eqns <= num_eqns_end;
num_eqns += num_eqns_delta)
std::cout << std::setw(w) << num_eqns << " ";
std::cout << std::endl;
for (int j=0; j<w_name; j++)
std::cout << '=';
std::cout << " ";
for (int num_eqns = num_eqns_begin; num_eqns <= num_eqns_end;
num_eqns += num_eqns_delta) {
for (int j=0; j<w; j++)
std::cout << '=';
std::cout << " ";
}
std::cout << std::endl;
// Analytic
std::vector<double> times_analytic =
do_times(work_count, num_eqns_begin, num_eqns_end, num_eqns_delta,
analytic_jac_fill);
print_times(times_analytic, times_analytic, "Analytic", p, w, w_name);
#ifdef HAVE_ADIC
// Note there seems to be a bug in ADIC where doing more than one num_eqns
// value results in incorrect timings after the first. Doing one value
// at a time seems to give correct values though.
std::vector<double> times_adic =
do_times(work_count, num_eqns_begin, num_eqns_end, num_eqns_delta,
adic_jac_fill);
print_times(times_adic, times_analytic, "ADIC", p, w, w_name);
#endif
// Original Fad
std::vector<double> times_sfad =
do_times_sfad<Sacado::Fad::SFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_sfad, times_analytic, "SFAD", p, w, w_name);
std::vector<double> times_slfad =
do_times_sfad<Sacado::Fad::SLFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_slfad, times_analytic, "SLFAD", p, w, w_name);
std::vector<double> times_dfad =
do_times_fad<Sacado::Fad::DFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_dfad, times_analytic, "DFAD", p, w, w_name);
// ELR Fad
std::vector<double> times_elr_sfad =
do_times_sfad<Sacado::ELRFad::SFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_elr_sfad, times_analytic, "ELRSFAD", p, w, w_name);
std::vector<double> times_elr_slfad =
do_times_sfad<Sacado::ELRFad::SLFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_elr_slfad, times_analytic, "ELRSLFAD", p, w, w_name);
std::vector<double> times_elr_dfad =
do_times_fad<Sacado::ELRFad::DFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
print_times(times_elr_dfad, times_analytic, "ELRDFAD", p, w, w_name);
// Cache Fad
std::vector<double> times_cache_sfad =
do_times_sfad<Sacado::CacheFad::SFad>(
work_count, num_eqns_begin, num_eqns_end, num_eqns_delta);
//.........这里部分代码省略.........