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(Teuchos::RCP<const Teuchos::Comm<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 
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  TEST_FAIL_AND_EXIT(*comm, 0, "Error in constructor 1", 1);
90  }
91 
92  std::cout << std::endl;
93  std::cout << "Test 1, input: " << input1 << std::endl;
94  std::cout << "[] test: ";
95  for (int i=0; i < 12; i++)
96  std::cout << (*s1)[i] << " ";
97  std::cout << std::endl;
98 
99  ArrayRCP<const value_t> fromS1;
100  s1->getInputArray(fromS1);
101  std::cout << "getInputArray test: ";
102  for (int i=0; i < 12; i++)
103  std::cout << fromS1[i] << " ";
104  std::cout << std::endl;
105 
106  stridedInput_t s1Copy;
107  s1Copy = *s1;
108 
109  std::cout << "assignment operator test: ";
110  for (int i=0; i < 12; i++)
111  std::cout << s1Copy[i] << " ";
112  std::cout << std::endl;
113 
117  ArrayRCP<value_t> input2(new value_t [12], 0, 12, true);
118  for (int i=0; i < 12; i+=3)
119  input2[i] = (i+1) * -5.0;
120 
121  RCP<stridedInput_t> s2;
122 
123  try{
124  s2 = rcp<stridedInput_t>(new stridedInput_t(input2, 3));
125  }
126  catch (std::exception &e){
127  TEST_FAIL_AND_EXIT(*comm, 0, "Error in constructor 2", 2);
128  }
129 
130  std::cout << std::endl;
131  std::cout << "Test 2, input: " << input2 << std::endl;
132  std::cout << "[] test: ";
133  for (int i=0; i < 4; i++)
134  std::cout << (*s2)[i] << " ";
135  std::cout << std::endl;
136 
137  ArrayRCP<const value_t> fromS2;
138  s2->getInputArray(fromS2);
139  std::cout << "getInputArray test: ";
140  for (int i=0; i < 4; i++)
141  std::cout << fromS2[i] << " ";
142  std::cout << std::endl;
143 
144  stridedInput_t s2Copy;
145  s2Copy = *s2;
146 
147  std::cout << "assignment operator test: ";
148  for (int i=0; i < 4; i++)
149  std::cout << s2Copy[i] << " ";
150  std::cout << std::endl;
151 }
152 
153 int main(int argc, char *argv[])
154 {
155  Teuchos::GlobalMPISession session(&argc, &argv);
156  Teuchos::RCP<const Teuchos::Comm<int> > comm =
157  Teuchos::DefaultComm<int>::getComm();
158 
159  if (comm->getRank() > 0)
160  return 0;
161 
162  StridedDataTest(comm);
163 
164  std::cout << "PASS" << std::endl;
165 }
double zscalar_t
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
int zlno_t
common code used by tests
void StridedDataTest(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Definition: StridedData.cpp:67
The StridedData class manages lists of weights or coordinates.
int main(int argc, char *argv[])
This file defines the StridedData class.