1 ///////////////////////////////////////////////////////////////////////////////
2 // File: times.cpp                                                           //
3 // Description: example program that computes execution times                //
4 // This file is part of the SISCone project.                                 //
5 // For more details, see http://projects.hepforge.org/siscone                //
6 //                                                                           //
7 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
8 //                                                                           //
9 // This program is free software; you can redistribute it and/or modify      //
10 // it under the terms of the GNU General Public License as published by      //
11 // the Free Software Foundation; either version 2 of the License, or         //
12 // (at your option) any later version.                                       //
13 //                                                                           //
14 // This program is distributed in the hope that it will be useful,           //
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
17 // GNU General Public License for more details.                              //
18 //                                                                           //
19 // You should have received a copy of the GNU General Public License         //
20 // along with this program; if not, write to the Free Software               //
21 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
22 //                                                                           //
23 // $Revision:: 320                                                          $//
24 // $Date:: 2011-11-15 09:54:50 +0100 (Tue, 15 Nov 2011)                     $//
25 ///////////////////////////////////////////////////////////////////////////////
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <time.h>
30 #include <sys/time.h>
31 #include <iostream>
32 #include <math.h>
33 
34 #include "siscone/momentum.h"
35 #include "siscone/siscone.h"
36 
37 #define Nruns 32
38 #define R    0.7
39 #define f    0.5
40 
41 using namespace std;
42 using namespace siscone;
43 
44 timeval time_start, time_end;
45 
46 // compute time spent between time_start and time_end
time_spent()47 int time_spent(){
48   timeval time_diff;
49 
50   // compute different with initial time
51   time_diff.tv_sec = time_end.tv_sec-time_start.tv_sec;
52   if (time_end.tv_usec > time_start.tv_usec){
53     time_diff.tv_usec = time_end.tv_usec-time_start.tv_usec;
54   } else {
55     time_diff.tv_sec--;
56     time_diff.tv_usec = (1000000+time_end.tv_usec)-time_start.tv_usec;
57   }
58 
59   return 1000000*time_diff.tv_sec+time_diff.tv_usec;
60 }
61 
62 
63 
main()64 int main(){
65   vector<Cmomentum> particles;
66   Csiscone siscone;
67   double eta,phi;
68 
69   // number of events and particles
70   int i, N;
71   int n_ev, part_inc;
72 
73   // time statistics variables
74   int time_siscone;
75 
76   // save files
77   FILE *flux;
78 
79   // initialise random number generator
80   cout << "initialise random number generator" << endl;
81   timeval timestamp;
82 
83   gettimeofday(&timestamp, NULL);
84   srand(timestamp.tv_usec);
85 
86   flux = fopen("times.dat", "w+");
87 
88   N = 1;
89   part_inc = 1;
90   do{
91     fprintf(stdout, "\r%5d particles\n", N);
92     time_siscone=0;
93 
94     for (n_ev=0;n_ev<Nruns;n_ev++){
95       // build particle list
96       particles.clear();
97       for (i=0;i<N;i++){
98 	eta = -3.0+6.0*rand()/(RAND_MAX+1.0);
99 	phi = 2.0*M_PI*rand()/(RAND_MAX+1.0);
100 	particles.push_back(Cmomentum(cos(phi), sin(phi), tanh(eta), 1.0));
101       }
102 
103       // run siscone
104       gettimeofday(&time_start, NULL);
105       siscone.compute_jets(particles, R, f);
106       gettimeofday(&time_end, NULL);
107       time_siscone+=time_spent();
108     }
109 
110     fprintf(flux, "%d\t%e\n", N, time_siscone/(1.0*Nruns));
111 
112     N+=part_inc;
113     if (N==(part_inc<<3))
114       part_inc <<= 1;
115     //  } while (N<=1024);
116   } while (N<=1024);
117 
118   fclose(flux);
119   fprintf(stdout, "\n");
120 
121   cout << "bye..." << endl;
122 
123   return 0;
124 }
125