Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_RawParameterListHelpers.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
13 #include "Teuchos_CommHelpers.hpp"
14 
16 void Teuchos::updateParametersAndBroadcast(
17  const Ptr<ParameterList> &inParamList,
18  const Ptr<ParameterList> &paramList,
19  const Comm<int> &comm,
20  int root,
21  bool overwrite)
22 {
23 
24  if (comm.getSize()==1) {
25  if(overwrite) paramList->setParameters(*inParamList);
26  else paramList->setParametersNotAlreadySet(*inParamList);
27  }
28  else {
29  if (comm.getRank()==root) {
30  XMLParameterListWriter w;
31  std::string xmlString = toString(w.toXML(*inParamList));
32  int strsize = static_cast<int>(xmlString.size());
33  broadcast<int, int>(comm, root, &strsize);
34  broadcast<int, char>(comm, root, strsize, &xmlString[0]);
35  updateParametersFromXmlString(xmlString, paramList,overwrite);
36  }
37  else {
38  int strsize;
39  broadcast<int, int>(comm, root, &strsize);
40  std::string xmlString;
41  xmlString.resize(strsize);
42  broadcast<int, char>(comm, root, strsize, &xmlString[0]);
43  updateParametersFromXmlString(xmlString, paramList,overwrite);
44  }
45  }
46 }
std::string toString(const any &rhs)
Converts the value in any to a std::string.
Writes a ParameterList to an XML object.
Additional ParameterList XML helper functions including parallel support.
#define TEUCHOSCOMM_LIB_DLL_EXPORT
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlString(const std::string &xmlStr, const Ptr< ParameterList > &paramList, bool overwrite=true)
Reads XML parameters from a std::string and updates those already in the given parameter list...