Zoltan2
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 
57 #include <Zoltan2_StridedData.hpp>
58 #include <Zoltan2_TestHelpers.hpp>
59 
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 zlno_t index_t;
71  typedef zscalar_t value_t;
72 
73  typedef StridedData<index_t, value_t> stridedInput_t;
74  bool aok = true;
75 
79  ArrayRCP<value_t> input1(new value_t [12], 0, 12, true);
80  for (int i=0; i < 12; i++)
81  input1[i] = (i+1) * 5;
82 
83  RCP<stridedInput_t> s1;
84 
85  try{
86  s1 = rcp<stridedInput_t>(new stridedInput_t(input1, 1));
87  }
88  catch (std::exception &e){
89  aok = false;
90  }
91  TEST_FAIL_AND_EXIT(comm, aok, "Error in constructor 1", 1);
92 
93  std::cout << std::endl;
94  std::cout << "Test 1, input: " << input1 << std::endl;
95  std::cout << "[] test: ";
96  for (int i=0; i < 12; i++)
97  std::cout << (*s1)[i] << " ";
98  std::cout << std::endl;
99 
100  ArrayRCP<const value_t> fromS1;
101  s1->getInputArray(fromS1);
102  std::cout << "getInputArray test: ";
103  for (int i=0; i < 12; i++)
104  std::cout << fromS1[i] << " ";
105  std::cout << std::endl;
106 
107  stridedInput_t s1Copy;
108  s1Copy = *s1;
109 
110  std::cout << "assignment operator test: ";
111  for (int i=0; i < 12; i++)
112  std::cout << s1Copy[i] << " ";
113  std::cout << std::endl;
114 
118  ArrayRCP<value_t> input2(new value_t [12], 0, 12, true);
119  for (int i=0; i < 12; i+=3)
120  input2[i] = (i+1) * -5.0;
121 
122  RCP<stridedInput_t> s2;
123 
124  try{
125  s2 = rcp<stridedInput_t>(new stridedInput_t(input2, 3));
126  }
127  catch (std::exception &e){
128  aok = false;
129  }
130  TEST_FAIL_AND_EXIT(comm, aok, "Error in constructor 2", 2);
131 
132  std::cout << std::endl;
133  std::cout << "Test 2, input: " << input2 << std::endl;
134  std::cout << "[] test: ";
135  for (int i=0; i < 4; i++)
136  std::cout << (*s2)[i] << " ";
137  std::cout << std::endl;
138 
139  ArrayRCP<const value_t> fromS2;
140  s2->getInputArray(fromS2);
141  std::cout << "getInputArray test: ";
142  for (int i=0; i < 4; i++)
143  std::cout << fromS2[i] << " ";
144  std::cout << std::endl;
145 
146  stridedInput_t s2Copy;
147  s2Copy = *s2;
148 
149  std::cout << "assignment operator test: ";
150  for (int i=0; i < 4; i++)
151  std::cout << s2Copy[i] << " ";
152  std::cout << std::endl;
153 }
154 
155 int main(int narg, char *arg[])
156 {
157  Tpetra::ScopeGuard tscope(&narg, &arg);
158  Teuchos::RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
159 
160  // Run the test on only one rank.
161  // There's no parallelism involved in StridedData,
162  // and the output is neater on only one proc.
163  if (tcomm->getRank() > 0)
164  return 0;
165 
166  Teuchos::SerialComm<int> comm;
167 
168  StridedDataTest(comm);
169 
170  std::cout << "PASS" << std::endl;
171 }
zscalar_t
double zscalar_t
Definition: Zoltan2_TestHelpers.hpp:141
TEST_FAIL_AND_EXIT
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
Definition: ErrorHandlingForTests.hpp:70
main
int main(int narg, char *arg[])
Definition: StridedData.cpp:155
Zoltan2_StridedData.hpp
This file defines the StridedData class.
zlno_t
int zlno_t
Definition: Zoltan2_TestHelpers.hpp:142
Zoltan2_TestHelpers.hpp
common code used by tests
StridedDataTest
void StridedDataTest(const Teuchos::SerialComm< int > &comm)
Definition: StridedData.cpp:66
Zoltan2::StridedData
The StridedData class manages lists of weights or coordinates.
Definition: Zoltan2_StridedData.hpp:76