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_4.hpp
1 /*
2  * test_4.hpp
3  *
4  * Created on: Feb 4, 2014
5  * Author: Pietro Incardona
6  */
7 
8 void test4(layout_gpu< grid<Point<float>>, memory_gpu<memory_gpu_type<Point<float>>::type> > & c3)
9 {
10  std::cout << "3D Array with grid_key_d storing property: " << "\n";
11 
12  typedef Point<float> P;
13 
14  timespec ts_start;
15  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
16  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
17 
18  for (int i = 0 ; i < GS_SIZE ; i++)
19  {
20  for (int j = 0 ; j < GS_SIZE ; j++)
21  {
22  for (int k = 0 ; k < GS_SIZE ; k++)
23  {
24  grid_key_d<3,P::x> kx(i,j,k);
25  grid_key_d<3,P::y> ky(i,j,k);
26  grid_key_d<3,P::z> kz(i,j,k);
27  grid_key_d<3,P::s> ks(i,j,k);
28  grid_key_d<3,P::v> kv(i,j,k);
29  grid_key_d<3,P::t> kt(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)[1] = 2.0f;
38  c3.get(kv)[2] = 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 
61 void test4(layout_cpu< grid<Point<float>>, memory_cpu<memory_cpu_type<Point<float>>::type> > & c3)
62 {
63  std::cout << "3D Array with grid_key_d storing property: " << "\n";
64 
65  typedef Point<float> P;
66 
67  timespec ts_start;
68  // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
69  clock_gettime(CLOCK_REALTIME, &ts_start); // Works on Linux
70 
71  for (int i = 0 ; i < GS_SIZE ; i++)
72  {
73  for (int j = 0 ; j < GS_SIZE ; j++)
74  {
75  for (int k = 0 ; k < GS_SIZE ; k++)
76  {
77  grid_key_d<3,P::x> kx(i,j,k);
78  grid_key_d<3,P::y> ky(i,j,k);
79  grid_key_d<3,P::z> kz(i,j,k);
80  grid_key_d<3,P::s> ks(i,j,k);
81  grid_key_d<3,P::v> kv(i,j,k);
82  grid_key_d<3,P::t> kt(i,j,k);
83 
84  c3.get(kx) = 1.1f;
85  c3.get(ky) = 1.2f;
86  c3.get(kz) = 1.3f;
87  c3.get(ks) = 1.0f;
88 
89  c3.get(kv)[0] = 1.0f;
90  c3.get(kv)[1] = 2.0f;
91  c3.get(kv)[2] = 3.0f;
92 
93  c3.get(kt)[0][0] = 1.0f;
94  c3.get(kt)[0][1] = 2.0f;
95  c3.get(kt)[0][2] = 3.0f;
96  c3.get(kt)[1][0] = 4.0f;
97  c3.get(kt)[1][1] = 5.0f;
98  c3.get(kt)[1][2] = 6.0f;
99  c3.get(kt)[2][0] = 7.0f;
100  c3.get(kt)[2][1] = 8.0f;
101  c3.get(kt)[2][2] = 9.0f;
102  }
103  }
104  }
105 
106  timespec end_time;
107  clock_gettime(CLOCK_REALTIME, &end_time); // Works on Linux
108  float time_dif =(float)( end_time.tv_sec - ts_start.tv_sec + (double)(end_time.tv_nsec - ts_start.tv_nsec)/1000000000.0 );
109 
110  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";
111 }
112 
This class implement the point shape in an N-dimensional space.
Definition: Point.hpp:20
grid_key_d is the key to access any element in the grid
Definition: grid_key.hpp:364
Test structure used for several test.
Definition: Point_test.hpp:72