本文整理汇总了C++中teuchos::ParameterList::entry方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterList::entry方法的具体用法?C++ ParameterList::entry怎么用?C++ ParameterList::entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::ParameterList
的用法示例。
在下文中一共展示了ParameterList::entry方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ValidateMLPParameters
bool ML_Epetra::ValidateMLPParameters(const Teuchos::ParameterList &inList, int depth){
using Teuchos::ParameterList;
using Teuchos::Exceptions::InvalidParameterName;
using Teuchos::Exceptions::InvalidParameterType;
using Teuchos::Exceptions::InvalidParameterValue;
using std::cout;
using std::endl;
using std::string;
ParameterList List,*validList;
bool rv=true;
/* Build a copy of the list to be validated. */
for (ParameterList::ConstIterator param = inList.begin(); param != inList.end(); ++param) {
const std::string pname=inList.name(param);
if (pname.find("user-defined function",0) == std::string::npos) {
List.setEntry(pname,inList.entry(param));
}
}
List.setName(inList.name());
/* Get Defaults + Validate */
try {
validList = GetValidMLPParameters();
}
catch(...) {
std::cout << "Error in GetValidMLPParameters. Please report this bug to the ML "
"developers." << std::endl;
#ifdef HAVE_MPI
MPI_Finalize();
#endif
exit(EXIT_FAILURE);
}
try {
List.validateParameters (*validList, depth, Teuchos::VALIDATE_USED_ENABLED,
Teuchos::VALIDATE_DEFAULTS_DISABLED);
}
#ifdef HAVE_IFPACK_DYNAMIC_FACTORY
catch(InvalidParameterName &excpt) {/*rv=false; std::cout<<excpt.what()<<std::endl;*/}
#else
catch(InvalidParameterName &excpt) {rv=false; std::cout<<excpt.what()<<std::endl;}
#endif
catch(InvalidParameterType &excpt) {rv=false; std::cout<<excpt.what()<<std::endl;}
catch(InvalidParameterValue &excpt) {rv=false; std::cout<<excpt.what()<<std::endl;}
catch(...) {rv=false;}
delete validList;
return rv;
}
示例2: UpdateContFile
bool UpdateContFile( const string & fileName,
const int & idStep,
const Teuchos::ParameterList & fileParams )
{
// The file to open
ofstream oFile(fileName.c_str(), ios_base::app);
// Writing the id
oFile << scientific << setw(7) << idStep;
// Looping on the parameters
Teuchos::map<string, Teuchos::ParameterEntry>::const_iterator i;
for (i = fileParams.begin(); i !=fileParams.end(); ++i)
oFile << scientific << setw(15) << fileParams.entry(i);
oFile << std::endl;
// Closing
oFile.close();
return true;
}
示例3: out
std::string ML2MueLuParameterTranslator::SetParameterList(const Teuchos::ParameterList & paramList_in, const std::string& defaultVals) {
Teuchos::ParameterList paramList = paramList_in;
RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); // TODO: use internal out (GetOStream())
#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
// TODO alternative with standard parameterlist from ML user guide?
if (defaultVals != "") {
TEUCHOS_TEST_FOR_EXCEPTION(defaultVals!="SA" && defaultVals!="NSSA", Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: only \"SA\" and \"NSSA\" allowed as options for ML default parameters.");
Teuchos::ParameterList ML_defaultlist;
ML_Epetra::SetDefaults(defaultVals,ML_defaultlist);
// merge user parameters with default parameters
MueLu::MergeParameterList(paramList_in, ML_defaultlist, true);
paramList = ML_defaultlist;
}
#else
if (defaultVals != "") {
// If no validator available: issue a warning and set parameter value to false in the output list
*out << "Warning: MueLu_ENABLE_ML=OFF. No ML default values available." << std::endl;
}
#endif // HAVE_MUELU_ML
//
// Move smoothers/aggregation/coarse parameters to sublists
//
// ML allows to have level-specific smoothers/aggregation/coarse parameters at the top level of the list or/and defined in sublists:
// See also: ML Guide section 6.4.1, MueLu::CreateSublists, ML_CreateSublists
ParameterList paramListWithSubList;
MueLu::CreateSublists(paramList, paramListWithSubList);
paramList = paramListWithSubList; // swap
Teuchos::ParameterList adaptingParamList = paramList; // copy of paramList which is used to removed already interpreted parameters
//
// Validate parameter list
//
{
bool validate = paramList.get("ML validate parameter list", true); /* true = default in ML */
if (validate) {
#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
// Validate parameter list using ML validator
int depth = paramList.get("ML validate depth", 5); /* 5 = default in ML */
TEUCHOS_TEST_FOR_EXCEPTION(! ML_Epetra::ValidateMLPParameters(paramList, depth), Exceptions::RuntimeError,
"ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
#else
// If no validator available: issue a warning and set parameter value to false in the output list
*out << "Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
paramList.set("ML validate parameter list", false);
#endif // HAVE_MUELU_ML
} // if(validate)
} // scope
// stringstream for concatenating xml parameter strings.
std::stringstream mueluss;
// create surrounding MueLu parameter list
mueluss << "<ParameterList name=\"MueLu\">" << std::endl;
// loop over all ML parameters in provided parameter list
for (ParameterList::ConstIterator param = paramListWithSubList.begin(); param != paramListWithSubList.end(); ++param) {
// extract ML parameter name
const std::string & pname=paramListWithSubList.name(param);
// extract corresponding (ML) value
// remove ParameterList specific information from result string
std::stringstream valuess;
valuess << paramList.entry(param);
std::string valuestr = valuess.str();
replaceAll(valuestr, "[unused]", "");
replaceAll(valuestr, "[default]", "");
valuestr = trim(valuestr);
// transform ML parameter to corresponding MueLu parameter and generate XML string
std::string valueInterpreterStr = "\"" + valuestr + "\"";
std::string ret = MasterList::interpretParameterName(MasterList::ML2MueLu(pname),valueInterpreterStr);
// add XML string
if (ret != "") {
mueluss << ret << std::endl;
// remove parameter from ML parameter list
adaptingParamList.remove(pname,false);
}
// special handling for energy minimization
// TAW: this is not optimal for symmetric problems but at least works.
// for symmetric problems the "energy minimization" parameter should not exist anyway...
if (pname == "energy minimization: enable") {
mueluss << "<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
mueluss << "<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
}
// special handling for smoothers
//.........这里部分代码省略.........
示例4: AMGXOperator
//! @name Constructor/Destructor
//@{
AMGXOperator(const Teuchos::RCP<Tpetra::CrsMatrix<SC,LO,GO,NO> > &inA, Teuchos::ParameterList ¶mListIn) {
RCP<const Teuchos::Comm<int> > comm = inA->getRowMap()->getComm();
int numProcs = comm->getSize();
int myRank = comm->getRank();
RCP<Teuchos::Time> amgxTimer = Teuchos::TimeMonitor::getNewTimer("MueLu: AMGX: initialize");
amgxTimer->start();
// Initialize
AMGX_SAFE_CALL(AMGX_initialize());
AMGX_SAFE_CALL(AMGX_initialize_plugins());
/*system*/
//AMGX_SAFE_CALL(AMGX_register_print_callback(&print_callback));
AMGX_SAFE_CALL(AMGX_install_signal_handler());
Teuchos::ParameterList configs = paramListIn.sublist("amgx:params", true);
if (configs.isParameter("json file")) {
AMGX_SAFE_CALL(AMGX_config_create_from_file(&Config_, (const char *) &configs.get<std::string>("json file")[0]));
} else {
std::ostringstream oss;
oss << "";
ParameterList::ConstIterator itr;
for (itr = configs.begin(); itr != configs.end(); ++itr) {
const std::string& name = configs.name(itr);
const ParameterEntry& entry = configs.entry(itr);
oss << name << "=" << filterValueToString(entry) << ", ";
}
oss << "\0";
std::string configString = oss.str();
if (configString == "") {
//print msg that using defaults
//GetOStream(Warnings0) << "Warning: No configuration parameters specified, using default AMGX configuration parameters. \n";
}
AMGX_SAFE_CALL(AMGX_config_create(&Config_, configString.c_str()));
}
// TODO: we probably need to add "exception_handling=1" to the parameter list
// to switch on internal error handling (with no need for AMGX_SAFE_CALL)
#define NEW_COMM
#ifdef NEW_COMM
// NOTE: MPI communicator used in AMGX_resources_create must exist in the scope of AMGX_matrix_comm_from_maps_one_ring
// FIXME: fix for serial comm
RCP<const Teuchos::MpiComm<int> > tmpic = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(comm->duplicate());
TEUCHOS_TEST_FOR_EXCEPTION(tmpic.is_null(), Exceptions::RuntimeError, "Communicator is not MpiComm");
RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > rawMpiComm = tmpic->getRawMpiComm();
MPI_Comm mpiComm = *rawMpiComm;
#endif
// Construct AMGX resources
if (numProcs == 1) {
AMGX_resources_create_simple(&Resources_, Config_);
} else {
int numGPUDevices;
cudaGetDeviceCount(&numGPUDevices);
int device[] = {(comm->getRank() % numGPUDevices)};
AMGX_config_add_parameters(&Config_, "communicator=MPI");
#ifdef NEW_COMM
AMGX_resources_create(&Resources_, Config_, &mpiComm, 1/* number of GPU devices utilized by this rank */, device);
#else
AMGX_resources_create(&Resources_, Config_, MPI_COMM_WORLD, 1/* number of GPU devices utilized by this rank */, device);
#endif
}
AMGX_Mode mode = AMGX_mode_dDDI;
AMGX_solver_create(&Solver_, Resources_, mode, Config_);
AMGX_matrix_create(&A_, Resources_, mode);
AMGX_vector_create(&X_, Resources_, mode);
AMGX_vector_create(&Y_, Resources_, mode);
amgxTimer->stop();
amgxTimer->incrementNumCalls();
std::vector<int> amgx2muelu;
// Construct AMGX communication pattern
if (numProcs > 1) {
RCP<const Tpetra::Import<LO,GO> > importer = inA->getCrsGraph()->getImporter();
TEUCHOS_TEST_FOR_EXCEPTION(importer.is_null(), MueLu::Exceptions::RuntimeError, "The matrix A has no Import object.");
Tpetra::Distributor distributor = importer->getDistributor();
Array<int> sendRanks = distributor.getImagesTo();
Array<int> recvRanks = distributor.getImagesFrom();
std::sort(sendRanks.begin(), sendRanks.end());
std::sort(recvRanks.begin(), recvRanks.end());
bool match = true;
if (sendRanks.size() != recvRanks.size()) {
match = false;
} else {
for (int i = 0; i < sendRanks.size(); i++) {
if (recvRanks[i] != sendRanks[i])
match = false;
//.........这里部分代码省略.........