void Teuchos::updateParametersFromXmlFileAndBroadcast( const std::string &xmlFileName, const Ptr<ParameterList> ¶mList, const Comm<int> &comm ) { if (comm.getSize()==1) updateParametersFromXmlFile(xmlFileName, paramList); else { if (comm.getRank()==0) { XMLParameterListReader xmlPLReader; xmlPLReader.setAllowsDuplicateSublists( false ); FileInputSource xmlFile(xmlFileName); XMLObject xmlParams = xmlFile.getObject(); std::string xmlString = toString(xmlParams); int strsize = xmlString.size(); broadcast<int, int>(comm, 0, &strsize); broadcast<int, char>(comm, 0, strsize, &xmlString[0]); updateParametersFromXmlString(xmlString, paramList); } else { int strsize; broadcast<int, int>(comm, 0, &strsize); std::string xmlString; xmlString.resize(strsize); broadcast<int, char>(comm, 0, strsize, &xmlString[0]); updateParametersFromXmlString(xmlString, paramList); } } }
Teuchos::RCP<Teuchos::ParameterList> Teuchos::getParametersFromXmlFile(const std::string &xmlFileName) { RCP<ParameterList> pl = parameterList(); updateParametersFromXmlFile(xmlFileName, pl.ptr()); return pl; }
TEUCHOS_UNIT_TEST( ParameterList, XMLDuplicatedSublists ) { ParameterList pl; TEST_THROW( updateParametersFromXmlFile(filename, inOutArg(pl) ), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlFile(filename), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlFile(filename,null), DuplicateParameterSublist ); // std::ifstream fin(filename.c_str()); std::string xmlstring( (std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>() ); TEST_THROW( updateParametersFromXmlString(xmlstring,inOutArg(pl) ), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlString(xmlstring), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlString(xmlstring,null), DuplicateParameterSublist ); }
TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcast ) { const RCP<const Comm<int> > comm = DefaultComm<int>::getComm(); // Test the broadcast functionality to avoid unscalable I/O collisions std::string inputFile="input.xml"; ParameterList A; ParameterList B; updateParametersFromXmlFile(inputFile, &A); updateParametersFromXmlFileAndBroadcast(inputFile, &B, *comm); out << "B = " << B; TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists // See if any process returned a failed (i.e. a non-zero local_failed) int local_failed = !(A == B); int global_failed = -1; reduceAll( *comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed) ); TEST_EQUALITY_CONST( global_failed, 0 ); }