OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
test_6.hpp
1 
2 
3 void test_6(layout_cpu<3, grid<3,Point<float>>, memory_cpu<memory_cpu_type<Point<float>>::type> > & c3)
4 {
5  // Create a bigger grid
6 
7 
8 
9  std::cout << "3D Array with grid_key (without redundant dimension): " << "\n";
10 
11  typedef Point<float> P;
12 
13  timespec ts_start;
14  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
15  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
16 
17  grid_key_dx<3> kk;
18 
19  for (int i = 0 ; i < GS_SIZE ; i++)
20  {
21  for (int j = 0 ; j < GS_SIZE ; j++)
22  {
23  for (int k = 0 ; k < GS_SIZE ; k++)
24  {
25  kk.set(i,j,k);
26 
27  c3.get<P::x>(kk) = 1.1f;
28  c3.get<P::y>(kk) = 1.2f;
29  c3.get<P::z>(kk) = 1.3f;
30  c3.get<P::s>(kk) = 1.0f;
31 
32  c3.get<P::v>(kk)[0] = 1.0f;
33  c3.get<P::v>(kk)[1] = 2.0f;
34  c3.get<P::v>(kk)[2] = 3.0f;
35 
36  c3.get<P::t>(kk)[0][0] = 1.0f;
37  c3.get<P::t>(kk)[0][1] = 2.0f;
38  c3.get<P::t>(kk)[0][2] = 3.0f;
39  c3.get<P::t>(kk)[1][0] = 4.0f;
40  c3.get<P::t>(kk)[1][1] = 5.0f;
41  c3.get<P::t>(kk)[1][2] = 6.0f;
42  c3.get<P::t>(kk)[2][0] = 7.0f;
43  c3.get<P::t>(kk)[2][1] = 8.0f;
44  c3.get<P::t>(kk)[2][2] = 9.0f;
45  }
46  }
47  }
48 
49  timespec end_time;
50  clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
51  float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
52 
53  std::cout << "End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 << " MB " << " Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/time_dif << " MB/s ";
54 
56 
57  bool passed = true;
58 
59  for (int i = 0 ; i < GS_SIZE ; i++)
60  {
61  for (int j = 0 ; j < GS_SIZE ; j++)
62  {
63  for (int k = 0 ; k < GS_SIZE ; k++)
64  {
65  kk.set(i,j,k);
66 
67  c3.get<P::x>(kk) = i;
68  c3.get<P::y>(kk) = j;
69  c3.get<P::z>(kk) = k;
70  c3.get<P::s>(kk) = i+j+k;
71 
72  c3.get<P::v>(kk)[0] = i;
73  c3.get<P::v>(kk)[1] = j;
74  c3.get<P::v>(kk)[2] = k;
75 
76  c3.get<P::t>(kk)[0][0] = i+i;
77  c3.get<P::t>(kk)[0][1] = i+j;
78  c3.get<P::t>(kk)[0][2] = i+k;
79  c3.get<P::t>(kk)[1][0] = j+i;
80  c3.get<P::t>(kk)[1][1] = j+j;
81  c3.get<P::t>(kk)[1][2] = j+k;
82  c3.get<P::t>(kk)[2][0] = k+i;
83  c3.get<P::t>(kk)[2][1] = k+j;
84  c3.get<P::t>(kk)[2][2] = k+k;
85  }
86  }
87  }
88 
89  for (int i = 0 ; i < GS_SIZE ; i++)
90  {
91  for (int j = 0 ; j < GS_SIZE ; j++)
92  {
93  for (int k = 0 ; k < GS_SIZE ; k++)
94  {
95  kk.set(i,j,k);
96 
97  if (c3.get<P::x>(kk) != i) passed = false;
98  if (c3.get<P::y>(kk) != j) passed = false;
99  if (c3.get<P::z>(kk) != k) passed = false;
100  if (c3.get<P::s>(kk) != i+j+k) passed = false;
101 
102  if (c3.get<P::v>(kk)[0] != i) passed = false;
103  if (c3.get<P::v>(kk)[1] != j) passed = false;
104  if (c3.get<P::v>(kk)[2] != k) passed = false;
105 
106  if (c3.get<P::t>(kk)[0][0] != i+i) passed = false;
107  if (c3.get<P::t>(kk)[0][1] != i+j) passed = false;
108  if (c3.get<P::t>(kk)[0][2] != i+k) passed = false;
109  if (c3.get<P::t>(kk)[1][0] != j+i) passed = false;
110  if (c3.get<P::t>(kk)[1][1] != j+j) passed = false;
111  if (c3.get<P::t>(kk)[1][2] != j+k) passed = false;
112  if (c3.get<P::t>(kk)[2][0] != k+i) passed = false;
113  if (c3.get<P::t>(kk)[2][1] != k+j) passed = false;
114  if (c3.get<P::t>(kk)[2][2] != k+k) passed = false;
115  }
116  }
117  }
118 
119  if (passed == true)
120  std::cout << "PASSED" << "\n";
121  else
122  std::cout << "FAILED" << "\n";
123 }
124 
125 
126 void test2(layout_gpu<3, grid<3,Point<float>>, memory_gpu<memory_gpu_type<Point<float>>::type> > & c3)
127 {
128  std::cout << "3D Array with grid_key (without redundant dimension): " << "\n";
129 
130  typedef Point<float> P;
131 
132  timespec ts_start;
133  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
134  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
135 
136  grid_key_dx<3> kk;
137 
138  for (int i = 0 ; i < GS_SIZE ; i++)
139  {
140  for (int j = 0 ; j < GS_SIZE ; j++)
141  {
142  for (int k = 0 ; k < GS_SIZE ; k++)
143  {
144 
145  kk.set(i,j,k);
146 
147  c3.get<P::x>(kk) = 1.1f;
148  c3.get<P::y>(kk) = 1.2f;
149  c3.get<P::z>(kk) = 1.3f;
150  c3.get<P::s>(kk) = 1.0f;
151 
152  c3.get<P::v>(kk)[0] = 1.0f;
153  c3.get<P::v>(kk)[1] = 2.0f;
154  c3.get<P::v>(kk)[2] = 3.0f;
155 
156  c3.get<P::t>(kk)[0][0] = 1.0f;
157  c3.get<P::t>(kk)[0][1] = 2.0f;
158  c3.get<P::t>(kk)[0][2] = 3.0f;
159  c3.get<P::t>(kk)[1][0] = 4.0f;
160  c3.get<P::t>(kk)[1][1] = 5.0f;
161  c3.get<P::t>(kk)[1][2] = 6.0f;
162  c3.get<P::t>(kk)[2][0] = 7.0f;
163  c3.get<P::t>(kk)[2][1] = 8.0f;
164  c3.get<P::t>(kk)[2][2] = 9.0f;
165 
166  }
167  }
168  }
169 
170  timespec end_time;
171  clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
172  float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
173 
174  std::cout << "End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 << " MB " << " Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/time_dif << " MB/s ";
175 
177 
178  bool passed = true;
179 
180  for (int i = 0 ; i < GS_SIZE ; i++)
181  {
182  for (int j = 0 ; j < GS_SIZE ; j++)
183  {
184  for (int k = 0 ; k < GS_SIZE ; k++)
185  {
186  kk.set(i,j,k);
187 
188  c3.get<P::x>(kk) = i;
189  c3.get<P::y>(kk) = j;
190  c3.get<P::z>(kk) = k;
191  c3.get<P::s>(kk) = i+j+k;
192 
193  c3.get<P::v>(kk)[0] = i;
194  c3.get<P::v>(kk)[1] = j;
195  c3.get<P::v>(kk)[2] = k;
196 
197  c3.get<P::t>(kk)[0][0] = i+i;
198  c3.get<P::t>(kk)[0][1] = i+j;
199  c3.get<P::t>(kk)[0][2] = i+k;
200  c3.get<P::t>(kk)[1][0] = j+i;
201  c3.get<P::t>(kk)[1][1] = j+j;
202  c3.get<P::t>(kk)[1][2] = j+k;
203  c3.get<P::t>(kk)[2][0] = k+i;
204  c3.get<P::t>(kk)[2][1] = k+j;
205  c3.get<P::t>(kk)[2][2] = k+k;
206  }
207  }
208  }
209 
210  for (int i = 0 ; i < GS_SIZE ; i++)
211  {
212  for (int j = 0 ; j < GS_SIZE ; j++)
213  {
214  for (int k = 0 ; k < GS_SIZE ; k++)
215  {
216  kk.set(i,j,k);
217 
218  if (c3.get<P::x>(kk) != i) passed = false;
219  if (c3.get<P::y>(kk) != j) passed = false;
220  if (c3.get<P::z>(kk) != k) passed = false;
221  if (c3.get<P::s>(kk) != i+j+k) passed = false;
222 
223  if (c3.get<P::v>(kk)[0] != i) passed = false;
224  if (c3.get<P::v>(kk)[1] != j) passed = false;
225  if (c3.get<P::v>(kk)[2] != k) passed = false;
226 
227  if (c3.get<P::t>(kk)[0][0] != i+i) passed = false;
228  if (c3.get<P::t>(kk)[0][1] != i+j) passed = false;
229  if (c3.get<P::t>(kk)[0][2] != i+k) passed = false;
230  if (c3.get<P::t>(kk)[1][0] != j+i) passed = false;
231  if (c3.get<P::t>(kk)[1][1] != j+j) passed = false;
232  if (c3.get<P::t>(kk)[1][2] != j+k) passed = false;
233  if (c3.get<P::t>(kk)[2][0] != k+i) passed = false;
234  if (c3.get<P::t>(kk)[2][1] != k+j) passed = false;
235  if (c3.get<P::t>(kk)[2][2] != k+k) passed = false;
236  }
237  }
238  }
239 
240  if (passed == true)
241  std::cout << "PASSED" << "\n";
242  else
243  std::cout << "FAILED" << "\n";
244 }
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:20
void set(a v, T...t)
set the grid key from a list of numbers
Definition: grid_key.hpp:227
Test structure used for several test.
Definition: Point_test.hpp:72