Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterList_UnitTest_Parallel.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_DefaultComm.hpp"
14 #include "Teuchos_CommHelpers.hpp"
15 
17 
18 
19 namespace Teuchos {
20 
21 
22 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcast ) {
24  // Test the broadcast functionality to avoid unscalable I/O collisions
25  std::string inputFile="input.xml";
28  updateParametersFromXmlFile(inputFile, outArg(A));
29  updateParametersFromXmlFileAndBroadcast(inputFile, outArg(B), *comm);
30  out << "B = " << B;
31  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
32 
33  // See if any process returned a failed (i.e. a non-zero local_failed)
34  const int local_failed = !(A == B);
35  int global_failed = -1;
36  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
37  TEST_EQUALITY_CONST(global_failed, 0);
38 }
39 
40 
41 
42 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcastNoOverWrite ) {
44  // Test the broadcast functionality to avoid unscalable I/O collisions
45  std::string inputFile="input.xml";
47  A.set("Transient",true);
48  A.set("Phalanx Graph Visualization Detail",2);
49 
51  B.set("Transient",true);
52  B.set("Phalanx Graph Visualization Detail",2);
53 
54 
55  updateParametersFromXmlFile(inputFile, outArg(A));
56  updateParametersFromXmlFileAndBroadcast(inputFile, outArg(B), *comm);
57  out << "B = " << B;
58  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
59 
60  // See if any process returned a failed (i.e. a non-zero local_failed)
61  const int local_failed = !(A == B);
62  int global_failed = -1;
63  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
64  TEST_EQUALITY_CONST(global_failed, 0);
65 
66  // Check the assigned values.
67  TEST_EQUALITY( B.get("Transient",false), true)
68  TEST_EQUALITY_CONST( B.get("Phalanx Graph Visualization Detail",1), 2)
69 
70 }
71 
72 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, rawUpdateAndBroadcast ) {
74  // Test the broadcast functionality to avoid unscalable I/O collisions
75  std::string inputFile="input.xml";
76  ParameterList A;
77  ParameterList B;
78 
79  // Set root to something != 0, if we can
80  int root = 0;
81  if(comm->getSize() > 1) root = 1;
82 
83  updateParametersFromXmlFile(inputFile, outArg(A));
84  updateParametersAndBroadcast(outArg(A),outArg(B),*comm,root);
85  out << "B = " << B;
86  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
87 
88  // See if any process returned a failed (i.e. a non-zero local_failed)
89  const int local_failed = !(A == B);
90  int global_failed = -1;
91  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
92  TEST_EQUALITY_CONST(global_failed, 0);
93 }
94 
95 
96 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, rawUpdateAndBroadcastNoOverWrite ) {
98  // Test the broadcast functionality to avoid unscalable I/O collisions
99  std::string inputFile="input.xml";
100  ParameterList A;
101  A.set("Transient",true);
102  A.set("Phalanx Graph Visualization Detail",2);
103 
104  ParameterList B;
105  B.set("Transient",true);
106  B.set("Phalanx Graph Visualization Detail",2);
107 
108  // Set root to something != 0, if we can
109  int root = 0;
110  if(comm->getSize() > 1) root = 1;
111 
112  updateParametersFromXmlFile(inputFile, outArg(A));
113  updateParametersAndBroadcast(outArg(A),outArg(B),*comm,root);
114  out << "B = " << B;
115  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
116 
117  // See if any process returned a failed (i.e. a non-zero local_failed)
118  const int local_failed = !(A == B);
119  int global_failed = -1;
120  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
121  TEST_EQUALITY_CONST(global_failed, 0);
122 
123  // Check the assigned values.
124  TEST_EQUALITY( B.get("Transient",false), true)
125  TEST_EQUALITY_CONST( B.get("Phalanx Graph Visualization Detail",1), 2)
126 
127 }
128 
129 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcastSpecialChars ) {
131  // Test that the special characters '&' and '<' are correctly translated from '&amp;' and '&lt;'
132  std::string inputFile="inputSpecialChars.xml";
133  ParameterList A;
134  updateParametersFromXmlFileAndBroadcast(inputFile, outArg(A), *comm);
135  out << "A = " << A;
136  TEST_ASSERT( A.begin() != A.end() ); // Avoid false positive from empty lists
137 
138  TEST_EQUALITY( A.get<std::string>("sigma"), "if (x >= 0.0 && y >= 0.0 && x <= 0.5 && y <= 0.5)" );
139 }
140 
141 } // namespace Teuchos
142 
143 
144 
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
Templated Parameter List class.
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Additional ParameterList XML helper functions including parallel support.
A list of parameters of arbitrary type.
Smart reference counting pointer class for automatic garbage collection.