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 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
45 #include "Teuchos_DefaultComm.hpp"
46 #include "Teuchos_CommHelpers.hpp"
47 
49 
50 
51 namespace Teuchos {
52 
53 
54 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcast ) {
56  // Test the broadcast functionality to avoid unscalable I/O collisions
57  std::string inputFile="input.xml";
60  updateParametersFromXmlFile(inputFile, outArg(A));
61  updateParametersFromXmlFileAndBroadcast(inputFile, outArg(B), *comm);
62  out << "B = " << B;
63  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
64 
65  // See if any process returned a failed (i.e. a non-zero local_failed)
66  const int local_failed = !(A == B);
67  int global_failed = -1;
68  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
69  TEST_EQUALITY_CONST(global_failed, 0);
70 }
71 
72 
73 
74 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, xmlUpdateAndBroadcastNoOverWrite ) {
76  // Test the broadcast functionality to avoid unscalable I/O collisions
77  std::string inputFile="input.xml";
79  A.set("Transient",true);
80  A.set("Phalanx Graph Visualization Detail",2);
81 
83  B.set("Transient",true);
84  B.set("Phalanx Graph Visualization Detail",2);
85 
86 
87  updateParametersFromXmlFile(inputFile, outArg(A));
88  updateParametersFromXmlFileAndBroadcast(inputFile, outArg(B), *comm);
89  out << "B = " << B;
90  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
91 
92  // See if any process returned a failed (i.e. a non-zero local_failed)
93  const int local_failed = !(A == B);
94  int global_failed = -1;
95  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
96  TEST_EQUALITY_CONST(global_failed, 0);
97 
98  // Check the assigned values.
99  TEST_EQUALITY( B.get("Transient",false), true)
100  TEST_EQUALITY_CONST( B.get("Phalanx Graph Visualization Detail",1), 2)
101 
102 }
103 
104 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, rawUpdateAndBroadcast ) {
106  // Test the broadcast functionality to avoid unscalable I/O collisions
107  std::string inputFile="input.xml";
108  ParameterList A;
109  ParameterList B;
110 
111  // Set root to something != 0, if we can
112  int root = 0;
113  if(comm->getSize() > 1) root = 1;
114 
115  updateParametersFromXmlFile(inputFile, outArg(A));
116  updateParametersAndBroadcast(outArg(A),outArg(B),*comm,root);
117  out << "B = " << B;
118  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
119 
120  // See if any process returned a failed (i.e. a non-zero local_failed)
121  const int local_failed = !(A == B);
122  int global_failed = -1;
123  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
124  TEST_EQUALITY_CONST(global_failed, 0);
125 }
126 
127 
128 TEUCHOS_UNIT_TEST( Teuchos_ParameterList, rawUpdateAndBroadcastNoOverWrite ) {
130  // Test the broadcast functionality to avoid unscalable I/O collisions
131  std::string inputFile="input.xml";
132  ParameterList A;
133  A.set("Transient",true);
134  A.set("Phalanx Graph Visualization Detail",2);
135 
136  ParameterList B;
137  B.set("Transient",true);
138  B.set("Phalanx Graph Visualization Detail",2);
139 
140  // Set root to something != 0, if we can
141  int root = 0;
142  if(comm->getSize() > 1) root = 1;
143 
144  updateParametersFromXmlFile(inputFile, outArg(A));
145  updateParametersAndBroadcast(outArg(A),outArg(B),*comm,root);
146  out << "B = " << B;
147  TEST_ASSERT( B.begin() != B.end() ); // Avoid false positive from empty lists
148 
149  // See if any process returned a failed (i.e. a non-zero local_failed)
150  const int local_failed = !(A == B);
151  int global_failed = -1;
152  reduceAll(*comm, Teuchos::REDUCE_SUM, local_failed, outArg(global_failed));
153  TEST_EQUALITY_CONST(global_failed, 0);
154 
155  // Check the assigned values.
156  TEST_EQUALITY( B.get("Transient",false), true)
157  TEST_EQUALITY_CONST( B.get("Phalanx Graph Visualization Detail",1), 2)
158 
159 }
160 
161 } // namespace Teuchos
162 
163 
164 
#define TEST_ASSERT(v1)
Assert the given statement is true.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
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.