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 using namespace std;
66 
67 void StridedDataTest(const Teuchos::SerialComm<int> &comm)
68 {
69  // StridedData template arguments
70 
71  typedef zlno_t index_t;
72  typedef zscalar_t value_t;
73 
74  typedef StridedData<index_t, value_t> stridedInput_t;
75  bool aok = true;
76 
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 
119  ArrayRCP<value_t> input2(new value_t [12], 0, 12, true);
120  for (int i=0; i < 12; i+=3)
121  input2[i] = (i+1) * -5.0;
122 
123  RCP<stridedInput_t> s2;
124 
125  try{
126  s2 = rcp<stridedInput_t>(new stridedInput_t(input2, 3));
127  }
128  catch (std::exception &e){
129  aok = false;
130  }
131  TEST_FAIL_AND_EXIT(comm, aok, "Error in constructor 2", 2);
132 
133  std::cout << std::endl;
134  std::cout << "Test 2, input: " << input2 << std::endl;
135  std::cout << "[] test: ";
136  for (int i=0; i < 4; i++)
137  std::cout << (*s2)[i] << " ";
138  std::cout << std::endl;
139 
140  ArrayRCP<const value_t> fromS2;
141  s2->getInputArray(fromS2);
142  std::cout << "getInputArray test: ";
143  for (int i=0; i < 4; i++)
144  std::cout << fromS2[i] << " ";
145  std::cout << std::endl;
146 
147  stridedInput_t s2Copy;
148  s2Copy = *s2;
149 
150  std::cout << "assignment operator test: ";
151  for (int i=0; i < 4; i++)
152  std::cout << s2Copy[i] << " ";
153  std::cout << std::endl;
154 }
155 
156 int main(int argc, char *argv[])
157 {
158  Teuchos::GlobalMPISession session(&argc, &argv);
159  Teuchos::RCP<const Teuchos::Comm<int> > mpicomm =
160  Teuchos::DefaultComm<int>::getComm();
161 
162  // Run the test on only one rank.
163  // There's no parallelism involved in StridedData,
164  // and the output is neater on only one proc.
165  if (mpicomm->getRank() > 0)
166  return 0;
167 
168  Teuchos::SerialComm<int> comm;
169 
170  StridedDataTest(comm);
171 
172  std::cout << "PASS" << std::endl;
173 }
double zscalar_t
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
int zlno_t
common code used by tests
The StridedData class manages lists of weights or coordinates.
int main(int argc, char *argv[])
void StridedDataTest(const Teuchos::SerialComm< int > &comm)
Definition: StridedData.cpp:67
This file defines the StridedData class.