本文整理汇总了C++中ParameterList::set方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterList::set方法的具体用法?C++ ParameterList::set怎么用?C++ ParameterList::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterList
的用法示例。
在下文中一共展示了ParameterList::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
MPI_Init(&argc,&argv);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
Epetra_MpiComm SerialComm(MPI_COMM_SELF);
if (Comm.MyPID() == 0) {
ParameterList GaleriList;
GaleriList.set("nx", 10);
GaleriList.set("ny", 10);
GaleriList.set("mx", 1);
GaleriList.set("my", 1);
Epetra_Map* Map = CreateMap("Cartesian2D", SerialComm, GaleriList);
Epetra_CrsMatrix* A = CreateCrsMatrix("Laplace2D", Map, GaleriList);
Epetra_Vector LHS(A->OperatorDomainMap());
Epetra_Vector RHS(A->OperatorRangeMap());
LHS.PutScalar(0.0);
RHS.Random();
Epetra_LinearProblem problem(A, &LHS, &RHS);
AztecOO solver(problem);
ParameterList MLList;
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("ML output", 0);
ML_Epetra::MultiLevelPreconditioner* MLPrec =
new ML_Epetra::MultiLevelPreconditioner(*A, MLList);
solver.SetPrecOperator(MLPrec);
solver.SetAztecOption(AZ_solver, AZ_cg_condnum);
solver.SetAztecOption(AZ_output, 32);
solver.Iterate(500, 1e-12);
// destroy the preconditioner
delete MLPrec;
delete A;
delete Map;
}
MPI_Finalize();
return(0);
} // main driver
示例2: getValidParameters
/*! \brief Set up validators specific to this Problem
*/
static void getValidParameters(ParameterList & pl)
{
RCP<Teuchos::StringValidator> order_method_Validator =
Teuchos::rcp( new Teuchos::StringValidator(
Teuchos::tuple<std::string>( "rcm", "minimum_degree", "natural",
"random", "sorted_degree", "scotch", "nd" )));
pl.set("order_method", "rcm", "order algorithm",
order_method_Validator);
RCP<Teuchos::StringValidator> order_package_Validator = Teuchos::rcp(
new Teuchos::StringValidator(
Teuchos::tuple<std::string>( "amd", "package2", "package3" )));
pl.set("order_package", "amd", "package to use in ordering",
order_package_Validator);
}
示例3: getDefaultParameters
ParameterList TPINode::getDefaultParameters()
{
ParameterList params;
params.set("Verbose", 0);
params.set("Num Threads", 0);
return params;
}
示例4: getValidParameters
/*! \brief Set up validators specific to this algorithm
*/
static void getValidParameters(ParameterList & pl)
{
RCP<Teuchos::EnhancedNumberValidator<int>> forTestingOnlyFlag_Validator =
Teuchos::rcp( new Teuchos::EnhancedNumberValidator<int>(0, 1000, 1, 0) );
pl.set("forTestingOnlyFlag", 0, "Used only for testing; look at "
"Zoltan2_AlgForTestingOnly for interpretations",
forTestingOnlyFlag_Validator);
}
示例5: getValidParameters
/*! \brief Set up validators specific to this algorithm
*/
static void getValidParameters(ParameterList & pl)
{
RCP<Teuchos::StringValidator> color_choice_Validator = Teuchos::rcp(
new Teuchos::StringValidator(
Teuchos::tuple<std::string>(
"FirstFit", "Random", "RandomFast", "LeastUsed" )));
pl.set("color_choice", "FirstFit", "selection criterion for coloring",
color_choice_Validator);
}
示例6:
RCP<ParameterList> HybridPlatform::listSupportedNodes()
{
RCP<ParameterList> list = Teuchos::parameterList();
{
ParameterList subpl;
subpl.set("NodeType","KokkosClassic::SerialNode");
subpl.setParameters( KokkosClassic::SerialNode::getDefaultParameters() );
list->set("=-1",subpl);
}
#ifdef HAVE_KOKKOSCLASSIC_TBB
{
ParameterList subpl;
subpl.set("NodeType","KokkosClassic::TBBNode");
subpl.setParameters( KokkosClassic::TBBNode::getDefaultParameters() );
list->set("=-2",subpl);
}
#endif
#ifdef HAVE_KOKKOSCLASSIC_OPENMP
{
ParameterList subpl;
subpl.set("NodeType","KokkosClassic::OpenMPNode");
subpl.setParameters( KokkosClassic::OpenMPNode::getDefaultParameters() );
list->set("=-3",subpl);
}
#endif
#ifdef HAVE_KOKKOSCLASSIC_THREADPOOL
{
ParameterList subpl;
subpl.set("NodeType","KokkosClassic::TPINode");
subpl.setParameters( KokkosClassic::TPINode::getDefaultParameters() );
list->set("=-4",subpl);
}
#endif
#ifdef HAVE_KOKKOSCLASSIC_THRUST
{
ParameterList subpl;
subpl.set("NodeType","KokkosClassic::ThrustGPUNode");
subpl.setParameters( KokkosClassic::ThrustGPUNode::getDefaultParameters() );
list->set("=-5",subpl);
}
#endif
return list;
}
示例7: variableLengthArray
/**
* Test the ArrayLengthDependency.
*/
TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testArrayLengthDep){
RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList);
RCP<DependencySheet> depSheet1 =
RCP<DependencySheet>(new DependencySheet);
ParameterList
numberArrayLengthDepList = My_deplist->sublist(
"Number Array Length Dependency List", false,
"Number Array Length Dependecy testing list.");
numberArrayLengthDepList.set("Array Length", 10, "array length setter");
Array<double> variableLengthArray(11,23.0);
RCP<EnhancedNumberValidator<double> >
varLengthArrayVali = RCP<EnhancedNumberValidator<double> >(
new EnhancedNumberValidator<double>(10,50,4)
);
numberArrayLengthDepList.set(
"Variable Length Array", variableLengthArray, "variable length array",
RCP<ArrayNumberValidator<double> >(
new ArrayNumberValidator<double>(varLengthArrayVali)));
RCP<NumberArrayLengthDependency<int, double> >
arrayLengthDep(
new NumberArrayLengthDependency<int, double>(
numberArrayLengthDepList.getEntryRCP("Array Length"),
numberArrayLengthDepList.getEntryRCP("Variable Length Array"),
rcp(new AdditionFunction<int>(1))
)
);
depSheet1->addDependency(arrayLengthDep);
Array<double> curArray =
numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
TEST_ASSERT(curArray.length() ==11);
numberArrayLengthDepList.set("Array Length", 12);
arrayLengthDep()->evaluate();
curArray =
numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
out << curArray.length() << std::endl;
TEST_ASSERT(curArray.length() ==13);
numberArrayLengthDepList.set("Array Length", -2);
TEST_THROW(arrayLengthDep()->evaluate(),
Exceptions::InvalidParameterValue);
}
示例8: variableColsArray
/**
* Test the TwoDColDependency.
*/
TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDColDependency){
RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList);
RCP<DependencySheet> depSheet1 =
RCP<DependencySheet>(new DependencySheet);
ParameterList
colNumDepList = My_deplist->sublist(
"2D Col Depdency List", false,
"2D Col Dependecy testing list.");
colNumDepList.set("Num cols", 2, "num cols setter");
TwoDArray<double> variableColsArray(11,3,16.5);
RCP<EnhancedNumberValidator<double> >
varColArrayVali = RCP<EnhancedNumberValidator<double> >(
new EnhancedNumberValidator<double>(10,50,4)
);
colNumDepList.set(
"Variable Col Array", variableColsArray, "variable col array",
RCP<TwoDArrayNumberValidator<double> >(
new TwoDArrayNumberValidator<double>(varColArrayVali)));
RCP<TwoDColDependency<int, double> >
arrayColDep = rcp(
new TwoDColDependency<int, double>(
colNumDepList.getEntryRCP("Num cols"),
colNumDepList.getEntryRCP("Variable Col Array") ,
rcp(new AdditionFunction<int>(1))
)
);
depSheet1->addDependency(arrayColDep);
TwoDArray<double> curArray =
colNumDepList.get<TwoDArray<double> >("Variable Col Array");
TEST_EQUALITY_CONST(curArray.getNumCols(),3);
colNumDepList.set("Num cols", 4);
arrayColDep()->evaluate();
curArray =
colNumDepList.get<TwoDArray<double> >("Variable Col Array");
TEST_EQUALITY_CONST(curArray.getNumCols(),5);
colNumDepList.set("Num cols", -2);
TEST_THROW(arrayColDep()->evaluate(),
Exceptions::InvalidParameterValue);
}
示例9: rcp
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, TwoDArrayNumberValidatorConverterTest, T)
{
std::string arrayParameterName = "array";
ParameterList myList;
const T arrayValidatorLen = as<T>(11);
RCP<TwoDArrayNumberValidator< T > > arrayValidator =
rcp(new TwoDArrayNumberValidator< T >(
rcp(new EnhancedNumberValidator<T>(as<T>(0), arrayValidatorLen))));
myList.set(arrayParameterName,
TwoDArray< T >(4,4, 10), "array parameter", arrayValidator);
RCP<ParameterList> readInPL = writeThenReadPL(myList);
RCP<const EnhancedNumberValidator< T > > readInPrototypeValidator =
rcp_dynamic_cast<const TwoDArrayValidator<EnhancedNumberValidator<T>, T > >(
readInPL->getEntry(
arrayParameterName).validator(), true)->getPrototype();
RCP<const EnhancedNumberValidator< T > > actualPrototypeValidator =
arrayValidator->getPrototype();
TEST_EQUALITY(
readInPrototypeValidator->getMin(),
actualPrototypeValidator->getMin()
);
TEST_EQUALITY(
readInPrototypeValidator->getMax(),
actualPrototypeValidator->getMax()
);
TEST_EQUALITY(
readInPrototypeValidator->getStep(),
actualPrototypeValidator->getStep()
);
TEST_EQUALITY(
readInPrototypeValidator->getPrecision(),
actualPrototypeValidator->getPrecision()
);
TEST_EQUALITY(
readInPrototypeValidator->hasMin(),
actualPrototypeValidator->hasMin()
);
TEST_EQUALITY(
readInPrototypeValidator->hasMax(),
actualPrototypeValidator->hasMax()
);
}
示例10: m
void RebalanceAcFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::Build(Level &fineLevel, Level &coarseLevel) const {
FactoryMonitor m(*this, "Computing Ac", coarseLevel);
RCP<Matrix> originalAc = Get< RCP<Matrix> >(coarseLevel, "A");
RCP<const Import> rebalanceImporter = Get< RCP<const Import> >(coarseLevel, "Importer");
if (rebalanceImporter != Teuchos::null) {
RCP<Matrix> rebalancedAc;
{
SubFactoryMonitor subM(*this, "Rebalancing existing Ac", coarseLevel);
RCP<const Map> targetMap = rebalanceImporter->getTargetMap();
const ParameterList & pL = GetParameterList();
ParameterList XpetraList;
if (pL.get<bool>("useSubcomm") == true) {
GetOStream(Runtime0,0) << "Replacing maps with a subcommunicator" << std::endl;
XpetraList.set("Restrict Communicator",true);
}
// NOTE: If the communicator is restricted away, Build returns Teuchos::null.
rebalancedAc = MatrixFactory::Build(originalAc, *rebalanceImporter, targetMap, targetMap, rcp(&XpetraList,false));
if (!rebalancedAc.is_null())
rebalancedAc->SetFixedBlockSize(originalAc->GetFixedBlockSize());
Set(coarseLevel, "A", rebalancedAc);
}
if (!rebalancedAc.is_null()) {
RCP<ParameterList> params = rcp(new ParameterList());
params->set("printLoadBalancingInfo", true);
GetOStream(Statistics0, 0) << Utils::PrintMatrixInfo(*rebalancedAc, "Ac (rebalanced)", params);
}
} else {
// Ac already built by the load balancing process and no load balancing needed
GetOStream(Warnings0, 0) << "No rebalancing" << std::endl;
GetOStream(Warnings0, 0) << "Jamming A into Level " << coarseLevel.GetLevelID() << " w/ generating factory "
<< this << std::endl;
Set(coarseLevel, "A", originalAc);
}
} //Build()
示例11: main
int main(int argc, char** argv)
{
typedef int Ordinal;
typedef double Scalar;
typedef Tpetra::MpiPlatform<KokkosClassic::DefaultNode::DefaultNodeType> MpiPlatform;
typedef Tpetra::SerialPlatform<KokkosClassic::DefaultNode::DefaultNodeType> SerialPlatform;
typedef MpiPlatform::NodeType MpiNodeType;
typedef SerialPlatform::NodeType SerialNodeType;
using namespace Teuchos;
oblackholestream blackhole;
GlobalMPISession mpiSession(&argc,&argv,&blackhole);
ParameterList pl;
Ordinal numThreads=1;
pl.set("Num Threads",numThreads);
RCP<MpiNodeType> mpiNode = rcp(new MpiNodeType(pl));
RCP<SerialNodeType> serialNode = rcp(new SerialNodeType(pl));
MpiPlatform myMpiPlat(mpiNode);
SerialPlatform mySerialPlat(serialNode);
{
RCP<const Comm<int> > teuchosComm = mySerialPlat.getComm();
RCP<const Epetra_Comm> epetraComm = Teuchos2Epetra_Comm(teuchosComm);
assert(epetraComm != Teuchos::null);
}
{
RCP<const Comm<int> > teuchosComm = myMpiPlat.getComm();
RCP<const Epetra_Comm> epetraComm = Teuchos2Epetra_Comm(teuchosComm);
assert(epetraComm != Teuchos::null);
}
return(0);
} //main
示例12: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
// initialize the random number generator
int ml_one = 1;
ML_srandom1(&ml_one);
// ===================== //
// create linear problem //
// ===================== //
ParameterList GaleriList;
GaleriList.set("nx", 10);
GaleriList.set("ny", 10);
GaleriList.set("nz", 10 * Comm.NumProc());
GaleriList.set("mx", 1);
GaleriList.set("my", 1);
GaleriList.set("mz", Comm.NumProc());
Epetra_Map* Map = CreateMap("Cartesian3D", Comm, GaleriList);
Epetra_CrsMatrix* Matrix = CreateCrsMatrix("Laplace3D", Map, GaleriList);
Epetra_MultiVector* Coords = CreateCartesianCoordinates("3D",Map,GaleriList);
Epetra_Vector LHS(*Map);
Epetra_Vector RHS(*Map);
Epetra_LinearProblem Problem(Matrix, &LHS, &RHS);
Teuchos::ParameterList MLList;
double TotalErrorResidual = 0.0, TotalErrorExactSol = 0.0;
// ====================== //
// default options for SA //
// ====================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Gauss-Seidel");
char mystring[80];
strcpy(mystring,"SA");
TestMultiLevelPreconditioner(mystring, MLList, Problem,
TotalErrorResidual, TotalErrorExactSol);
// ============================================== //
// default options for SA, efficient symmetric GS //
// ============================================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Gauss-Seidel");
MLList.set("smoother: Gauss-Seidel efficient symmetric",true);
TestMultiLevelPreconditioner(mystring, MLList, Problem,
TotalErrorResidual, TotalErrorExactSol,true);
// ============================== //
// default options for SA, Jacobi //
// ============================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Jacobi");
TestMultiLevelPreconditioner(mystring, MLList, Problem, TotalErrorResidual,
TotalErrorExactSol,true);
// =========================== //
// default options for SA, Cheby //
// =========================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Chebyshev");
TestMultiLevelPreconditioner(mystring, MLList, Problem,
TotalErrorResidual, TotalErrorExactSol);
// =========================== //
// Specifying Ifpack coarse lists correctly
// =========================== //
#ifdef HAVE_ML_IFPACK
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
if(!Comm.MyPID()) {
MLList.set("ML print initial list",1);
MLList.set("ML print final list",1);
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[]) {
#include "MueLu_UseShortNames.hpp"
using Teuchos::RCP; using Teuchos::rcp;
using Teuchos::TimeMonitor;
//using Galeri::Xpetra::CreateCartesianCoordinates;
Teuchos::oblackholestream blackhole;
Teuchos::GlobalMPISession mpiSession(&argc, &argv, &blackhole);
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
out->setOutputToRootOnly(0);
*out << MueLu::MemUtils::PrintMemoryUsage() << std::endl;
// out->setOutputToRootOnly(-1);
// out->precision(12);
//FIXME we need a HAVE_MUELU_LONG_LONG_INT option
//#ifndef HAVE_TEUCHOS_LONG_LONG_INT
*out << "Warning: scaling test was not compiled with long long int support" << std::endl;
//#endif
//
// SET TEST PARAMETERS
//
// Note: use --help to list available options.
Teuchos::CommandLineProcessor clp(false);
// Default is Laplace1D with nx = 8748.
// It's a nice size for 1D and perfect aggregation. (6561 = 3^8)
//Nice size for 1D and perfect aggregation on small numbers of processors. (8748 = 4*3^7)
Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra
// Custom command line parameters
// - Debug
int optDebug = 0; clp.setOption("debug", &optDebug, "pause to attach debugger");
int optDump = 0; clp.setOption("dump", &optDump, "write matrix to file");
int optTimings = 0; clp.setOption("timings", &optTimings, "print timings to screen");
// - Levels
LO optMaxLevels = 10; clp.setOption("maxLevels", &optMaxLevels, "maximum number of levels allowed");
int optMaxCoarseSize = 50; clp.setOption("maxCoarseSize", &optMaxCoarseSize, "maximum #dofs in coarse operator"); //FIXME clp doesn't like long long int
// - Smoothed-Aggregation
Scalar optSaDamping = 4./3; clp.setOption("saDamping", &optSaDamping, "prolongator damping factor");
// - Aggregation
std::string optAggOrdering = "natural"; clp.setOption("aggOrdering", &optAggOrdering, "aggregation ordering strategy (natural, random, graph)");
int optMinPerAgg = 2; clp.setOption("minPerAgg", &optMinPerAgg, "minimum #DOFs per aggregate");
int optMaxNbrSel = 0; clp.setOption("maxNbrSel", &optMaxNbrSel, "maximum # of nbrs allowed to be in other aggregates");
// - R
int optExplicitR = 1; clp.setOption("explicitR", &optExplicitR, "restriction will be explicitly stored as transpose of prolongator");
// - Smoothers
std::string optSmooType = "sgs"; clp.setOption("smooType", &optSmooType, "smoother type ('l1-sgs', 'sgs 'or 'cheby')");
int optSweeps = 2; clp.setOption("sweeps", &optSweeps, "sweeps to be used in SGS (or Chebyshev degree)");
// - Repartitioning
#if defined(HAVE_MPI) && defined(HAVE_MUELU_ZOLTAN)
int optRepartition = 1; clp.setOption("repartition", &optRepartition, "enable repartitioning (0=no repartitioning, 1=Zoltan RCB, 2=Isorropia+Zoltan PHG");
LO optMinRowsPerProc = 2000; clp.setOption("minRowsPerProc", &optMinRowsPerProc, "min #rows allowable per proc before repartitioning occurs");
double optNnzImbalance = 1.2; clp.setOption("nnzImbalance", &optNnzImbalance, "max allowable nonzero imbalance before repartitioning occurs");
#else
int optRepartition = 0;
#endif // HAVE_MPI && HAVE_MUELU_ZOLTAN
// - Solve
int optFixPoint = 1; clp.setOption("fixPoint", &optFixPoint, "apply multigrid as solver");
int optPrecond = 1; clp.setOption("precond", &optPrecond, "apply multigrid as preconditioner");
LO optIts = 10; clp.setOption("its", &optIts, "number of multigrid cycles");
double optTol = 1e-7; clp.setOption("tol", &optTol, "stopping tolerance for Krylov method");
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;
}
RCP<TimeMonitor> globalTimeMonitor = rcp (new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time")));
if (optDebug) {
Utils::PauseForDebugger();
}
matrixParameters.check();
xpetraParameters.check();
// TODO: check custom parameters
std::transform(optSmooType.begin(), optSmooType.end(), optSmooType.begin(), ::tolower);
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib();
if (comm->getRank() == 0) {
std::cout << xpetraParameters << matrixParameters;
// TODO: print custom parameters // Or use paramList::print()!
}
//
//.........这里部分代码省略.........
示例14: main
int main(int argc, char *argv[]) {
#ifdef HAVE_MPI
MPI_Init(&argc, &argv);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
// initialize the random number generator
int ml_one = 1;
ML_srandom1(&ml_one);
// ===================== //
// create linear problem //
// ===================== //
ParameterList GaleriList;
int base=10;
GaleriList.set("nx", base);
GaleriList.set("ny", base);
GaleriList.set("nz", base * Comm.NumProc());
GaleriList.set("mx", 1);
GaleriList.set("my", 1);
GaleriList.set("mz", Comm.NumProc());
Epetra_Map* Map = CreateMap("Cartesian3D", Comm, GaleriList);
Epetra_CrsMatrix* Matrix = CreateCrsMatrix("Laplace3D", Map, GaleriList);
Epetra_Vector LHS(*Map);
Epetra_Vector RHS(*Map);
Epetra_LinearProblem Problem(Matrix, &LHS, &RHS);
Teuchos::ParameterList MLList;
double TotalErrorResidual = 0.0, TotalErrorExactSol = 0.0;
// ==================n==== //
// default options for SA //
// ====================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Gauss-Seidel");
char mystring[80];
strcpy(mystring,"SA");
TestMultiLevelPreconditioner(mystring, MLList, Problem,
TotalErrorResidual, TotalErrorExactSol);
// ============================== //
// default options for SA, Jacobi //
// ============================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Jacobi");
TestMultiLevelPreconditioner(mystring, MLList, Problem, TotalErrorResidual,
TotalErrorExactSol);
// =========================== //
// default options for SA, Cheby //
// =========================== //
if (Comm.MyPID() == 0) PrintLine();
ML_Epetra::SetDefaults("SA",MLList);
MLList.set("smoother: type", "Chebyshev");
TestMultiLevelPreconditioner(mystring, MLList, Problem,
TotalErrorResidual, TotalErrorExactSol);
// ===================== //
// print out total error //
// ===================== //
if (Comm.MyPID() == 0) {
cout << endl;
cout << "......Total error for residual = " << TotalErrorResidual << endl;
cout << "......Total error for exact solution = " << TotalErrorExactSol << endl;
cout << endl;
}
delete Matrix;
delete Map;
if (TotalErrorResidual > 1e-8) {
cerr << "Error: `MultiLevelPrecoditioner_Sym.exe' failed!" << endl;
exit(EXIT_FAILURE);
}
#ifdef HAVE_MPI
MPI_Finalize();
#endif
if (Comm.MyPID() == 0)
cerr << "`MultiLevelPrecoditioner_Sym.exe' passed!" << endl;
//.........这里部分代码省略.........
示例15: main
int main(int argc, char *argv[]) {
//
Teuchos::GlobalMPISession session(&argc, &argv, NULL);
//
typedef double ST;
typedef Teuchos::ScalarTraits<ST> SCT;
typedef SCT::magnitudeType MT;
typedef Epetra_MultiVector MV;
typedef Epetra_Operator OP;
typedef Belos::MultiVecTraits<ST,MV> MVT;
typedef Belos::OperatorTraits<ST,MV,OP> OPT;
using Teuchos::ParameterList;
using Teuchos::RCP;
using Teuchos::rcp;
bool verbose = false;
bool success = true;
try {
bool proc_verbose = false;
bool pseudo = false; // use pseudo block GMRES to solve this linear system.
int frequency = -1;
int blocksize = 1;
int numrhs = 1;
int maxrestarts = 15; // number of restarts allowed
int maxiters = -1; // maximum number of iterations allowed per linear system
std::string filename("orsirr1.hb");
MT tol = 1.0e-5; // relative residual tolerance
Teuchos::CommandLineProcessor cmdp(false,true);
cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
cmdp.setOption("pseudo","regular",&pseudo,"Use pseudo-block GMRES to solve the linear systems.");
cmdp.setOption("frequency",&frequency,"Solvers frequency for printing residuals (#iters).");
cmdp.setOption("filename",&filename,"Filename for Harwell-Boeing test matrix.");
cmdp.setOption("tol",&tol,"Relative residual tolerance used by GMRES solver.");
cmdp.setOption("max-restarts",&maxrestarts,"Maximum number of restarts allowed for GMRES solver.");
cmdp.setOption("blocksize",&blocksize,"Block size used by GMRES.");
cmdp.setOption("maxiters",&maxiters,"Maximum number of iterations per linear system (-1 = adapted to problem/block size).");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
return -1;
}
if (!verbose)
frequency = -1; // reset frequency if test is not verbose
//
// Get the problem
//
int MyPID;
RCP<Epetra_CrsMatrix> A;
RCP<Epetra_MultiVector> B, X;
int return_val =Belos::createEpetraProblem(filename,NULL,&A,&B,&X,&MyPID);
if(return_val != 0) return return_val;
const Epetra_Map &Map = A->RowMap();
proc_verbose = verbose && (MyPID==0); /* Only print on the zero processor */
//
// ********Other information used by block solver***********
// *****************(can be user specified)******************
//
const int NumGlobalElements = B->GlobalLength();
if (maxiters == -1)
maxiters = NumGlobalElements/blocksize - 1; // maximum number of iterations to run
//
ParameterList belosList;
belosList.set( "Num Blocks", maxiters ); // Maximum number of blocks in Krylov factorization
belosList.set( "Block Size", blocksize ); // Blocksize to be used by iterative solver
belosList.set( "Maximum Iterations", maxiters ); // Maximum number of iterations allowed
belosList.set( "Maximum Restarts", maxrestarts ); // Maximum number of restarts allowed
belosList.set( "Convergence Tolerance", tol ); // Relative convergence tolerance requested
if (verbose) {
belosList.set( "Verbosity", Belos::Errors + Belos::Warnings +
Belos::TimingDetails + + Belos::StatusTestDetails );
if (frequency > 0)
belosList.set( "Output Frequency", frequency );
}
else
belosList.set( "Verbosity", Belos::Errors + Belos::Warnings );
//
//
// Construct an unpreconditioned linear problem instance.
//
Belos::LinearProblem<double,MV,OP> problem( A, X, B );
bool set = problem.setProblem();
if (set == false) {
if (proc_verbose)
std::cout << std::endl << "ERROR: Belos::LinearProblem failed to set up correctly!" << std::endl;
return -1;
}
//
// *******************************************************************
// *************Start the block Gmres iteration*************************
// *******************************************************************
//
Teuchos::RCP< Belos::SolverManager<double,MV,OP> > solver;
if (pseudo)
solver = Teuchos::rcp( new Belos::PseudoBlockGmresSolMgr<double,MV,OP>( rcp(&problem,false), rcp(&belosList,false) ) );
else
solver = Teuchos::rcp( new Belos::BlockGmresSolMgr<double,MV,OP>( rcp(&problem,false), rcp(&belosList,false) ) );
//
// **********Print out information about problem*******************
//
if (proc_verbose) {
//.........这里部分代码省略.........