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