Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  string xmlFile("initParams.xml");
  Teuchos::XMLParameterListWriter plw;

  // XML converter for Zoltan2::IntegerRangeListValidator must be added
  // once to the validator database.

  typedef Zoltan2::IntegerRangeListValidatorXMLConverter<int> irlConverter_t;
  RCP<irlConverter_t > converter = rcp(new irlConverter_t);
  typedef Zoltan2::IntegerRangeListValidator<int> irl_t;
  RCP<const irl_t> intRangeValidatorP = rcp(new irl_t);

  Teuchos::ValidatorXMLConverterDB::addConverter(
       intRangeValidatorP,    // can be a dummy of this type
       converter);

  Teuchos::ParameterList pl("zoltan2ValidatingParameters");
  createAllParameters(pl);
    
  // Write out to XML
  Teuchos::XMLObject obj = plw.toXML(pl);

  cout << "Parameter list: " << endl;
  cout << obj << endl;
  
  std::ofstream of;
  of.open(xmlFile.c_str());
  of << obj << endl;
  of.close();
}
Ejemplo n.º 2
0
bool TreeModel::writeOutput(QString fileName){
	QFile *file = new QFile(fileName);
	if(!file->open(QIODevice::WriteOnly)){
		return false;
	}
	std::ofstream outputFile;
	Teuchos::XMLParameterListWriter plWriter;
	Teuchos::XMLObject xmlOutput = plWriter.toXML(*validParameters);
	QTextStream outStream(file);
	outStream << QString::fromStdString(xmlOutput.toString());
	file->close();
	delete file;
	saved = true;
	saveFileName = fileName;
	return true;
}
Ejemplo n.º 3
0
int main()
{
  // Create a parameter list with each validator type that we use.

  Teuchos::ParameterList pl("pl");

  {
    string parameterName("speed_versus_quality");
    RCP<const Teuchos::StringValidator> strValidatorP =
      rcp(new Teuchos::StringValidator(
        tuple<string>("speed", "balance", "quality")));
    ostringstream docString;
    strValidatorP->printDoc(
      "When algorithm choices exist, opt for speed or solution quality?\n"
      "(Default is a balance of speed and quality)\n",
       docString);
    pl.set<string>(parameterName, "balance", docString.str(), strValidatorP);
  }

  {
    string parameterName("debug_output_file");
    RCP<const Teuchos::FileNameValidator > fnameValidatorP =
      fnameValidatorP = rcp(new Teuchos::FileNameValidator(false));
    ostringstream docString;
    fnameValidatorP->printDoc(
      "name of file to which debug/status messages should be written\n"
      "(process rank will be included in file name)\n",
       docString);
    pl.set<string>(parameterName, "/dev/null", docString.str(), 
      fnameValidatorP);
  }

  {
    string parameterName("random_seed");
    RCP<const Teuchos::AnyNumberParameterEntryValidator> anyNumValidatorP =
      rcp(new Teuchos::AnyNumberParameterEntryValidator);
    ostringstream docString;
    anyNumValidatorP->printDoc("random seed\n", docString);
    pl.set<string>(parameterName, "0.5", docString.str(), anyNumValidatorP);
  }

  {
    string parameterName("debug_level");
    RCP<const Teuchos::StringToIntegralParameterEntryValidator<int> > 
      str2intValidatorP = 
      rcp(new Teuchos::StringToIntegralParameterEntryValidator<int>(
       tuple<string>("no_status",
                    "basic_status",
                    "detailed_status",
                    "verbose_detailed_status"),

       tuple<string>(
        "library outputs no status information",
        "library outputs basic status information (default)",
        "library outputs detailed information",
        "library outputs very detailed information"),

       tuple<int>(0, 1, 2, 3),

       parameterName));

    string info("the amount of status/warning/debugging info printed\n");
    info.append("(If the compile flag Z2_OMIT_ALL_STATUS_MESSAGES was set,\n");
    info.append("then message output code is not executed at runtime.)\n");

    ostringstream docString;
    str2intValidatorP->printDoc(info, docString);
    pl.set<string>(parameterName, "basic_status", docString.str(), 
      str2intValidatorP);
  }

  {
    string parameterName("bisection_num_test_cuts");
    RCP<const Teuchos::EnhancedNumberValidator<int> > intValidatorP =
      rcp(new Teuchos::EnhancedNumberValidator<int>(1,250,1));
    ostringstream docString;
    intValidatorP->printDoc(
     "Experimental: number of test cuts to do simultaneously (default is 1)\n",
        docString);
    pl.set<int>(parameterName, 1, docString.str(), intValidatorP);
  }

  {
    string parameterName("debug_procs");
    typedef Zoltan2::IntegerRangeListValidator<int> irl_t;
    RCP<const irl_t> intRangeValidatorP = rcp(new irl_t);
    ostringstream docString;
    intRangeValidatorP->printDoc(
      "list of ranks that output debugging/status messages (default \"0\")\n",
       docString);
    pl.set<string>(parameterName, "0", docString.str(), intRangeValidatorP);

    // An XML converter for irl_t only needs to be added once to the converter db.

    typedef Zoltan2::IntegerRangeListValidatorXMLConverter<int> irlConverter_t;
    RCP<irlConverter_t > converter = rcp(new irlConverter_t);
    Teuchos::ValidatorXMLConverterDB::addConverter(
          intRangeValidatorP,    // can be a dummy of this type
          converter);
  }

  // Write out to XML
  Teuchos::XMLParameterListWriter plw;
  Teuchos::XMLObject obj = plw.toXML(pl);

  cout << "Parameter list: " << endl;
  cout << obj << endl;

  std::ofstream of;
  of.open("params.xml");
  of << obj << endl;
  of.close();

  // Read parameter list in from XML file.

  Teuchos::ParameterXMLFileReader rdr("params.xml");
  Teuchos::ParameterList newpl = rdr.getParameters();
  Teuchos::XMLObject objnew = plw.toXML(newpl);

  cout << "After reading in from XML file: " << endl;
  cout << objnew << endl;
}