Strip extra spaces from code.
[voro++.git] / branches / dynamic / examples / timing / timing_test.cc
blob276eae8ad1a5b7ed268aaec13038db60132d869f
1 // Voronoi calculation example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : July 1st 2008
7 #include "voro++.cc"
8 #include <ctime>
9 using namespace std;
11 // Set up constants for the container geometry
12 const double x_min=-1,x_max=1;
13 const double y_min=-1,y_max=1;
14 const double z_min=-1,z_max=1;
16 // Set up the number of blocks that the container is divided into. If the
17 // preprocessor variable NNN hasn't been passed to the code, then initialize it
18 // to a good value. Otherwise, use the value that has been passed.
19 #ifndef NNN
20 #define NNN 26
21 #endif
22 const int n_x=NNN,n_y=NNN,n_z=NNN;
24 // Set the number of particles that are going to be randomly introduced
25 const int particles=100000;
27 // This function returns a random double between 0 and 1
28 double rnd() {return double(rand())/RAND_MAX;}
30 int main() {
31 clock_t start,end;
32 int i;double x,y,z;
34 // Create a container with the geometry given above, and make it
35 // periodic in each of the three coordinates. Allocate space for eight
36 // particles within each computational block.
37 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
38 true,true,true,8);
40 //Randomly add particles into the container
41 for(i=0;i<particles;i++) {
42 x=x_min+rnd()*(x_max-x_min);
43 y=y_min+rnd()*(y_max-y_min);
44 z=z_min+rnd()*(z_max-z_min);
45 con.put(i,x,y,z);
48 // Store the initial clock time
49 start=clock();
51 // Carry out a dummy computation of all cells in the entire container
52 con.compute_all_cells();
54 // Calculate the elapsed time and print it
55 end=clock();
56 double runtime=double(end-start)/CLOCKS_PER_SEC;
57 cout << runtime << endl;