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_5.hpp
1 /*
2  * test_5.hpp
3  *
4  * Created on: Feb 4, 2014
5  * Author: i-bird
6  */
7 
8 void test5(layout_gpu< grid<Point<float>>, memory_gpu<memory_gpu_type<Point<float>>::type> > & c3)
9 {
10  std::cout << "3D Array with grid_key runtime dimensions " << "\n";
11 
12  grid_key<Point<float>::x> kx(3);
13  grid_key<Point<float>::y> ky(kx);
14  grid_key<Point<float>::z> kz(kx);
15  grid_key<Point<float>::s> ks(kx);
16  grid_key<Point<float>::v> kv(kx);
17  grid_key<Point<float>::t> kt(kx);
18 
19  timespec ts_start;
20  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
21  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
22 
23  for (int i = 0 ; i < GS_SIZE ; i++)
24  {
25  for (int j = 0 ; j < GS_SIZE ; j++)
26  {
27  for (int k = 0 ; k < GS_SIZE ; k++)
28  {
29  kx.set(i,j,k);
30 
31  c3.get(kx) = 1.1f;
32  c3.get(ky) = 1.2f;
33  c3.get(kz) = 1.3f;
34  c3.get(ks) = 1.0f;
35 
36  c3.get(kv)[0] = 1.0f;
37  c3.get(kv)[0] = 2.0f;
38  c3.get(kv)[0] = 3.0f;
39 
40  c3.get(kt)[0][0] = 1.0f;
41  c3.get(kt)[0][1] = 2.0f;
42  c3.get(kt)[0][2] = 3.0f;
43  c3.get(kt)[1][0] = 4.0f;
44  c3.get(kt)[1][1] = 5.0f;
45  c3.get(kt)[1][2] = 6.0f;
46  c3.get(kt)[2][0] = 7.0f;
47  c3.get(kt)[2][1] = 8.0f;
48  c3.get(kt)[2][2] = 9.0f;
49  }
50  }
51  }
52 
53  timespec end_time;
54  clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
55  float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
56 
57  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 \n";
58 }
59 
60 void test5(layout_cpu< grid<Point<float>>, memory_cpu<memory_cpu_type<Point<float>>::type> > & c3)
61 {
62  std::cout << "3D Array with grid_key runtime dimensions " << "\n";
63 
64  grid_key<Point<float>::x> kx(3);
65  grid_key<Point<float>::y> ky(kx);
66  grid_key<Point<float>::z> kz(kx);
67  grid_key<Point<float>::s> ks(kx);
68  grid_key<Point<float>::v> kv(kx);
69  grid_key<Point<float>::t> kt(kx);
70 
71  timespec ts_start;
72  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
73  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
74 
75  for (int i = 0 ; i < GS_SIZE ; i++)
76  {
77  for (int j = 0 ; j < GS_SIZE ; j++)
78  {
79  for (int k = 0 ; k < GS_SIZE ; k++)
80  {
81  kx.set(i,j,k);
82 
83  c3.get(kx) = 1.1f;
84  c3.get(ky) = 1.2f;
85  c3.get(kz) = 1.3f;
86  c3.get(ks) = 1.0f;
87 
88  c3.get(kv)[0] = 1.0f;
89  c3.get(kv)[0] = 2.0f;
90  c3.get(kv)[0] = 3.0f;
91 
92  c3.get(kt)[0][0] = 1.0f;
93  c3.get(kt)[0][1] = 2.0f;
94  c3.get(kt)[0][2] = 3.0f;
95  c3.get(kt)[1][0] = 4.0f;
96  c3.get(kt)[1][1] = 5.0f;
97  c3.get(kt)[1][2] = 6.0f;
98  c3.get(kt)[2][0] = 7.0f;
99  c3.get(kt)[2][1] = 8.0f;
100  c3.get(kt)[2][2] = 9.0f;
101  }
102  }
103  }
104 
105  timespec end_time;
106  clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
107  float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
108 
109  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 \n";
110 }
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:20