Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
comm
test
ParameterList
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
42
#include "
Teuchos_ParameterList.hpp
"
43
#include "
Teuchos_RawParameterListHelpers.hpp
"
44
#include "
Teuchos_XMLParameterListHelpers.hpp
"
45
#include "
Teuchos_DefaultComm.hpp
"
46
#include "
Teuchos_CommHelpers.hpp
"
47
48
#include "
Teuchos_UnitTestHarness.hpp
"
49
50
51
namespace
Teuchos
{
52
53
54
TEUCHOS_UNIT_TEST
( Teuchos_ParameterList, xmlUpdateAndBroadcast ) {
55
const
RCP<const Comm<int>
> comm =
DefaultComm<int>::getComm
();
56
// Test the broadcast functionality to avoid unscalable I/O collisions
57
std::string inputFile=
"input.xml"
;
58
ParameterList
A
;
59
ParameterList
B
;
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 ) {
75
const
RCP<const Comm<int>
> comm =
DefaultComm<int>::getComm
();
76
// Test the broadcast functionality to avoid unscalable I/O collisions
77
std::string inputFile=
"input.xml"
;
78
ParameterList
A
;
79
A
.set(
"Transient"
,
true
);
80
A
.set(
"Phalanx Graph Visualization Detail"
,2);
81
82
ParameterList
B
;
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 ) {
105
const
RCP<const Comm<int>
> comm =
DefaultComm<int>::getComm
();
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 ) {
129
const
RCP<const Comm<int>
> comm =
DefaultComm<int>::getComm
();
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
TEUCHOS_UNIT_TEST
( Teuchos_ParameterList, xmlUpdateAndBroadcastSpecialChars ) {
162
const
RCP<const Comm<int>
> comm =
DefaultComm<int>::getComm
();
163
// Test that the special characters '&' and '<' are correctly translated from '&' and '<'
164
std::string inputFile=
"inputSpecialChars.xml"
;
165
ParameterList
A
;
166
updateParametersFromXmlFileAndBroadcast
(inputFile,
outArg
(
A
), *comm);
167
out <<
"A = "
<<
A
;
168
TEST_ASSERT
(
A
.begin() !=
A
.end() );
// Avoid false positive from empty lists
169
170
TEST_EQUALITY
(
A
.get<std::string>(
"sigma"
),
"if (x >= 0.0 && y >= 0.0 && x <= 0.5 && y <= 0.5)"
);
171
}
172
173
}
// namespace Teuchos
174
175
176
Teuchos_CommHelpers.hpp
Teuchos_DefaultComm.hpp
TEST_ASSERT
#define TEST_ASSERT(v1)
Assert the given statement is true.
Definition
Teuchos_LocalTestingHelpers.hpp:71
TEST_EQUALITY_CONST
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Definition
Teuchos_LocalTestingHelpers.hpp:79
TEST_EQUALITY
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
Definition
Teuchos_LocalTestingHelpers.hpp:87
Teuchos_ParameterList.hpp
Templated Parameter List class.
Teuchos_RawParameterListHelpers.hpp
Teuchos_UnitTestHarness.hpp
Unit testing support.
TEUCHOS_UNIT_TEST
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Definition
Teuchos_UnitTestHelpers.hpp:83
Teuchos_XMLParameterListHelpers.hpp
Additional ParameterList XML helper functions including parallel support.
Teuchos::Comm::reduceAll
void reduceAll(const Comm< Ordinal > &comm, const ValueTypeReductionOp< Ordinal, Packet > &reductOp, const Ordinal count, const Packet sendBuffer[], Packet globalReducts[])
Wrapper for MPI_Allreduce that takes a custom reduction operator.
Definition
Teuchos_CommHelpers.hpp:1433
Teuchos::DefaultComm::getComm
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
Definition
Teuchos_DefaultComm.hpp:212
Teuchos::ParameterList
A list of parameters of arbitrary type.
Definition
Teuchos_ParameterList.hpp:133
Teuchos::ParameterList::updateParametersAndBroadcast
TEUCHOSCOMM_LIB_DLL_EXPORT void updateParametersAndBroadcast(const Ptr< ParameterList > &inParamList, const Ptr< ParameterList > &ParamList, const Comm< int > &comm, int root, bool overwrite=true)
On processor rank = root, broadcast the inParamList to all other processors. Then update the given pa...
Teuchos::ParameterList::updateParametersFromXmlFile
TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT void updateParametersFromXmlFile(const std::string &xmlFileName, const Ptr< ParameterList > ¶mList)
Reads XML parameters from a file and updates those already in the given parameter list.
Teuchos::ParameterList::updateParametersFromXmlFileAndBroadcast
TEUCHOSCOMM_LIB_DLL_EXPORT void updateParametersFromXmlFileAndBroadcast(const std::string &xmlFileName, const Ptr< ParameterList > ¶mList, const Comm< int > &comm, bool overwrite=true)
On processor rank = 0, reads XML parameters from a file and broadcasts them to all other processors....
Teuchos::Ptr::outArg
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
Definition
Teuchos_PtrDecl.hpp:227
Teuchos::RCP
Smart reference counting pointer class for automatic garbage collection.
Definition
Teuchos_RCPDecl.hpp:429
A
Definition
PackageA.cpp:3
B
Definition
PackageB.cpp:3
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::REDUCE_SUM
@ REDUCE_SUM
Sum.
Definition
Teuchos_EReductionType.hpp:72
Generated by
1.17.0