Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
StridedData.cpp
Go to the documentation of this file.
1
// @HEADER
2
//
3
// ***********************************************************************
4
//
5
// Zoltan2: A package of combinatorial algorithms for scientific computing
6
// Copyright 2012 Sandia Corporation
7
//
8
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9
// the U.S. Government retains certain rights in this software.
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
13
// met:
14
//
15
// 1. Redistributions of source code must retain the above copyright
16
// notice, this list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright
19
// notice, this list of conditions and the following disclaimer in the
20
// documentation and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the Corporation nor the names of the
23
// contributors may be used to endorse or promote products derived from
24
// this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// Questions? Contact Karen Devine (kddevin@sandia.gov)
39
// Erik Boman (egboman@sandia.gov)
40
// Siva Rajamanickam (srajama@sandia.gov)
41
//
42
// ***********************************************************************
43
//
44
// @HEADER
45
//
46
// This is another test where you need to look at the output to
47
// know if it's right. This should be fixed.
48
56
57
#include <
Zoltan2_StridedData.hpp
>
58
#include <
Zoltan2_TestHelpers.hpp
>
59
60
using
Zoltan2::StridedData
;
61
using
Teuchos::RCP;
62
using
Teuchos::rcp;
63
using
Teuchos::ArrayRCP;
64
using
Teuchos::Array;
65
66
void
StridedDataTest
(
const
Teuchos::SerialComm<int> &comm)
67
{
68
// StridedData template arguments
69
70
typedef
int
index_t;
71
typedef
double
value_t;
72
typedef
float
different_value_t;
73
74
typedef
StridedData<index_t, value_t>
stridedInput_t;
75
bool
aok =
true
;
76
79
80
ArrayRCP<value_t> input1(
new
value_t [12], 0, 12,
true
);
81
for
(
int
i=0; i < 12; i++)
82
input1[i] = (i+1) * 5;
83
84
RCP<stridedInput_t> s1;
85
86
try
{
87
s1 = rcp<stridedInput_t>(
new
stridedInput_t(input1, 1));
88
}
89
catch
(std::exception &e){
90
aok =
false
;
91
}
92
TEST_FAIL_AND_EXIT
(comm, aok,
"Error in constructor 1"
, 1);
93
94
std::cout << std::endl;
95
std::cout <<
"Test 1, input: "
<< input1 << std::endl;
96
std::cout <<
"[] test: "
;
97
for
(
int
i=0; i < 12; i++)
98
std::cout << (*s1)[i] <<
" "
;
99
std::cout << std::endl;
100
101
ArrayRCP<const value_t> fromS1;
102
s1->getInputArray(fromS1);
103
std::cout <<
"getInputArray test: "
;
104
for
(
int
i=0; i < 12; i++)
105
std::cout << fromS1[i] <<
" "
;
106
std::cout << std::endl;
107
108
stridedInput_t s1Copy;
109
s1Copy = *s1;
110
111
std::cout <<
"assignment operator test: "
;
112
for
(
int
i=0; i < 12; i++)
113
std::cout << s1Copy[i] <<
" "
;
114
std::cout << std::endl;
115
116
// test a different type
117
ArrayRCP<const different_value_t> fromS1too;
118
s1->getInputArray(fromS1too);
119
std::cout <<
"getInputArray test -- different type: "
;
120
for
(
int
i=0; i < 12; i++)
121
std::cout << fromS1too[i] <<
" "
;
122
std::cout << std::endl;
123
126
127
ArrayRCP<value_t> input2(
new
value_t [12], 0, 12,
true
);
128
for
(
int
i=0; i < 12; i+=3)
129
input2[i] = (i+1) * -5.0;
130
131
RCP<stridedInput_t> s2;
132
133
try
{
134
s2 = rcp<stridedInput_t>(
new
stridedInput_t(input2, 3));
135
}
136
catch
(std::exception &e){
137
aok =
false
;
138
}
139
TEST_FAIL_AND_EXIT
(comm, aok,
"Error in constructor 2"
, 2);
140
141
std::cout << std::endl;
142
std::cout <<
"Test 2, input: "
<< input2 << std::endl;
143
std::cout <<
"[] test: "
;
144
for
(
int
i=0; i < 4; i++)
145
std::cout << (*s2)[i] <<
" "
;
146
std::cout << std::endl;
147
148
ArrayRCP<const value_t> fromS2;
149
s2->getInputArray(fromS2);
150
std::cout <<
"getInputArray test: "
;
151
for
(
int
i=0; i < 4; i++)
152
std::cout << fromS2[i] <<
" "
;
153
std::cout << std::endl;
154
155
stridedInput_t s2Copy;
156
s2Copy = *s2;
157
158
std::cout <<
"assignment operator test: "
;
159
for
(
int
i=0; i < 4; i++)
160
std::cout << s2Copy[i] <<
" "
;
161
std::cout << std::endl;
162
163
// test a different type
164
ArrayRCP<const different_value_t> fromS2too;
165
s1->getInputArray(fromS2too);
166
std::cout <<
"getInputArray test -- different type: "
;
167
for
(
int
i=0; i < 4; i++)
168
std::cout << fromS2too[i] <<
" "
;
169
std::cout << std::endl;
170
}
171
172
int
main
(
int
narg,
char
*arg[])
173
{
174
Tpetra::ScopeGuard tscope(&narg, &arg);
175
Teuchos::RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
176
177
// Run the test on only one rank.
178
// There's no parallelism involved in StridedData,
179
// and the output is neater on only one proc.
180
if
(tcomm->getRank() > 0)
181
return
0;
182
183
Teuchos::SerialComm<int> comm;
184
185
StridedDataTest
(comm);
186
187
std::cout <<
"PASS"
<< std::endl;
188
}
TEST_FAIL_AND_EXIT
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Definition
ErrorHandlingForTests.hpp:70
StridedDataTest
void StridedDataTest(const Teuchos::SerialComm< int > &comm)
Definition
StridedData.cpp:66
Zoltan2_StridedData.hpp
This file defines the StridedData class.
Zoltan2_TestHelpers.hpp
common code used by tests
main
int main()
Definition
absdefinitiontest.cpp:6
Zoltan2::StridedData
The StridedData class manages lists of weights or coordinates.
Definition
Zoltan2_StridedData.hpp:76
test
core
unit
util
StridedData.cpp
Generated by
1.17.0