SISCone  2.0.5
examples/times.cpp
00001 
00002 // File: times.cpp                                                           //
00003 // Description: example program that computes execution times                //
00004 // This file is part of the SISCone project.                                 //
00005 // For more details, see http://projects.hepforge.org/siscone                //
00006 //                                                                           //
00007 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
00008 //                                                                           //
00009 // This program is free software; you can redistribute it and/or modify      //
00010 // it under the terms of the GNU General Public License as published by      //
00011 // the Free Software Foundation; either version 2 of the License, or         //
00012 // (at your option) any later version.                                       //
00013 //                                                                           //
00014 // This program is distributed in the hope that it will be useful,           //
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
00017 // GNU General Public License for more details.                              //
00018 //                                                                           //
00019 // You should have received a copy of the GNU General Public License         //
00020 // along with this program; if not, write to the Free Software               //
00021 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
00022 //                                                                           //
00023 // $Revision:: 320                                                          $//
00024 // $Date:: 2011-11-15 09:54:50 +0100 (Tue, 15 Nov 2011)                     $//
00026 
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <time.h>
00030 #include <sys/time.h>
00031 #include <iostream>
00032 #include <math.h>
00033 
00034 #include "siscone/momentum.h"
00035 #include "siscone/siscone.h"
00036 
00037 #define Nruns 32
00038 #define R    0.7
00039 #define f    0.5
00040 
00041 using namespace std;
00042 using namespace siscone;
00043 
00044 timeval time_start, time_end;
00045 
00046 // compute time spent between time_start and time_end
00047 int time_spent(){
00048   timeval time_diff;
00049   
00050   // compute different with initial time
00051   time_diff.tv_sec = time_end.tv_sec-time_start.tv_sec;
00052   if (time_end.tv_usec > time_start.tv_usec){
00053     time_diff.tv_usec = time_end.tv_usec-time_start.tv_usec;
00054   } else {
00055     time_diff.tv_sec--;
00056     time_diff.tv_usec = (1000000+time_end.tv_usec)-time_start.tv_usec;
00057   }
00058   
00059   return 1000000*time_diff.tv_sec+time_diff.tv_usec;
00060 }
00061 
00062 
00063 
00064 int main(){
00065   vector<Cmomentum> particles;
00066   Csiscone siscone;
00067   double eta,phi;
00068 
00069   // number of events and particles
00070   int i, N;
00071   int n_ev, part_inc;
00072 
00073   // time statistics variables
00074   int time_siscone;
00075 
00076   // save files
00077   FILE *flux;
00078 
00079   // initialise random number generator
00080   cout << "initialise random number generator" << endl;
00081   timeval timestamp;
00082 
00083   gettimeofday(&timestamp, NULL);
00084   srand(timestamp.tv_usec);
00085 
00086   flux = fopen("times.dat", "w+");
00087 
00088   N = 1;
00089   part_inc = 1;
00090   do{
00091     fprintf(stdout, "\r%5d particles\n", N);
00092     time_siscone=0;
00093 
00094     for (n_ev=0;n_ev<Nruns;n_ev++){
00095       // build particle list
00096       particles.clear();
00097       for (i=0;i<N;i++){
00098         eta = -3.0+6.0*rand()/(RAND_MAX+1.0);
00099         phi = 2.0*M_PI*rand()/(RAND_MAX+1.0);
00100         particles.push_back(Cmomentum(cos(phi), sin(phi), tanh(eta), 1.0));
00101       }
00102       
00103       // run siscone
00104       gettimeofday(&time_start, NULL);
00105       siscone.compute_jets(particles, R, f);
00106       gettimeofday(&time_end, NULL);
00107       time_siscone+=time_spent();
00108     }
00109 
00110     fprintf(flux, "%d\t%e\n", N, time_siscone/(1.0*Nruns));
00111 
00112     N+=part_inc;
00113     if (N==(part_inc<<3))
00114       part_inc <<= 1;
00115     //  } while (N<=1024);
00116   } while (N<=1024);
00117   
00118   fclose(flux);
00119   fprintf(stdout, "\n");
00120 
00121   cout << "bye..." << endl;
00122 
00123   return 0;
00124 }
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Mon Jun 4 2012 18:23:38 for SISCone by  Doxygen 1.7.6.1