Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
StridedData.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 //
11 // This is another test where you need to look at the output to
12 // know if it's right. This should be fixed.
13 
22 #include <Zoltan2_StridedData.hpp>
23 #include <Zoltan2_TestHelpers.hpp>
24 
26 using Teuchos::RCP;
27 using Teuchos::rcp;
28 using Teuchos::ArrayRCP;
29 using Teuchos::Array;
30 
31 void StridedDataTest(const Teuchos::SerialComm<int> &comm)
32 {
33  // StridedData template arguments
34 
35  typedef int index_t;
36  typedef double value_t;
37  typedef float different_value_t;
38 
39  typedef StridedData<index_t, value_t> stridedInput_t;
40  bool aok = true;
41 
45  ArrayRCP<value_t> input1(new value_t [12], 0, 12, true);
46  for (int i=0; i < 12; i++)
47  input1[i] = (i+1) * 5;
48 
49  RCP<stridedInput_t> s1;
50 
51  try{
52  s1 = rcp<stridedInput_t>(new stridedInput_t(input1, 1));
53  }
54  catch (std::exception &e){
55  aok = false;
56  }
57  TEST_FAIL_AND_EXIT(comm, aok, "Error in constructor 1", 1);
58 
59  std::cout << std::endl;
60  std::cout << "Test 1, input: " << input1 << std::endl;
61  std::cout << "[] test: ";
62  for (int i=0; i < 12; i++)
63  std::cout << (*s1)[i] << " ";
64  std::cout << std::endl;
65 
66  ArrayRCP<const value_t> fromS1;
67  s1->getInputArray(fromS1);
68  std::cout << "getInputArray test: ";
69  for (int i=0; i < 12; i++)
70  std::cout << fromS1[i] << " ";
71  std::cout << std::endl;
72 
73  stridedInput_t s1Copy;
74  s1Copy = *s1;
75 
76  std::cout << "assignment operator test: ";
77  for (int i=0; i < 12; i++)
78  std::cout << s1Copy[i] << " ";
79  std::cout << std::endl;
80 
81  // test a different type
82  ArrayRCP<const different_value_t> fromS1too;
83  s1->getInputArray(fromS1too);
84  std::cout << "getInputArray test -- different type: ";
85  for (int i=0; i < 12; i++)
86  std::cout << fromS1too[i] << " ";
87  std::cout << std::endl;
88 
92  ArrayRCP<value_t> input2(new value_t [12], 0, 12, true);
93  for (int i=0; i < 12; i+=3)
94  input2[i] = (i+1) * -5.0;
95 
96  RCP<stridedInput_t> s2;
97 
98  try{
99  s2 = rcp<stridedInput_t>(new stridedInput_t(input2, 3));
100  }
101  catch (std::exception &e){
102  aok = false;
103  }
104  TEST_FAIL_AND_EXIT(comm, aok, "Error in constructor 2", 2);
105 
106  std::cout << std::endl;
107  std::cout << "Test 2, input: " << input2 << std::endl;
108  std::cout << "[] test: ";
109  for (int i=0; i < 4; i++)
110  std::cout << (*s2)[i] << " ";
111  std::cout << std::endl;
112 
113  ArrayRCP<const value_t> fromS2;
114  s2->getInputArray(fromS2);
115  std::cout << "getInputArray test: ";
116  for (int i=0; i < 4; i++)
117  std::cout << fromS2[i] << " ";
118  std::cout << std::endl;
119 
120  stridedInput_t s2Copy;
121  s2Copy = *s2;
122 
123  std::cout << "assignment operator test: ";
124  for (int i=0; i < 4; i++)
125  std::cout << s2Copy[i] << " ";
126  std::cout << std::endl;
127 
128  // test a different type
129  ArrayRCP<const different_value_t> fromS2too;
130  s1->getInputArray(fromS2too);
131  std::cout << "getInputArray test -- different type: ";
132  for (int i=0; i < 4; i++)
133  std::cout << fromS2too[i] << " ";
134  std::cout << std::endl;
135 }
136 
137 int main(int narg, char *arg[])
138 {
139  Tpetra::ScopeGuard tscope(&narg, &arg);
140  Teuchos::RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
141 
142  // Run the test on only one rank.
143  // There's no parallelism involved in StridedData,
144  // and the output is neater on only one proc.
145  if (tcomm->getRank() > 0)
146  return 0;
147 
148  Teuchos::SerialComm<int> comm;
149 
150  StridedDataTest(comm);
151 
152  std::cout << "PASS" << std::endl;
153 }
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
int main(int narg, char **arg)
Definition: coloring1.cpp:164
common code used by tests
The StridedData class manages lists of weights or coordinates.
void StridedDataTest(const Teuchos::SerialComm< int > &comm)
Definition: StridedData.cpp:31
This file defines the StridedData class.