1 // Timing test example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
13 // Set up constants for the container geometry
14 const double x_min
=-1,x_max
=1;
15 const double y_min
=-1,y_max
=1;
16 const double z_min
=-1,z_max
=1;
18 // Set up the number of blocks that the container is divided into. If the
19 // preprocessor variable NNN hasn't been passed to the code, then initialize it
20 // to a good value. Otherwise, use the value that has been passed.
24 const int n_x
=NNN
,n_y
=NNN
,n_z
=NNN
;
26 // Set the number of particles that are going to be randomly introduced
27 const int particles
=100000;
29 // This function returns a random double between 0 and 1
30 double rnd() {return double(rand())/RAND_MAX
;}
36 // Create a container with the geometry given above, and make it
37 // periodic in each of the three coordinates. Allocate space for eight
38 // particles within each computational block.
39 container
con(x_min
,x_max
,y_min
,y_max
,z_min
,z_max
,n_x
,n_y
,n_z
,
42 //Randomly add particles into the container
43 for(i
=0;i
<particles
;i
++) {
44 x
=x_min
+rnd()*(x_max
-x_min
);
45 y
=y_min
+rnd()*(y_max
-y_min
);
46 z
=z_min
+rnd()*(z_max
-z_min
);
50 // Store the initial clock time
53 // Carry out a dummy computation of all cells in the entire container
54 con
.compute_all_cells();
56 // Calculate the elapsed time and print it
58 double runtime
=double(end
-start
)/CLOCKS_PER_SEC
;
59 printf("%g\n",runtime
);