Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnMultiThreadedBenchedScheduler.cxx

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *  
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #include "PsnMultiThreadedBenchedScheduler.h"
00019 
00020 #include "PsnFrameScheduler.h"
00021 #include "PsnBenchScheduler.h"
00022 #include "PsnBarrier.h"
00023 #include "PsController.h"
00024 #include "PsDuplicatedObject.h"
00025 
00026 #include <unistd.h>
00027 
00028 #include <sys/time.h>
00029 
00030 PsnMultiThreadedBenchedScheduler::PsnMultiThreadedBenchedScheduler (unsigned int numberOfSteps, unsigned int numberOfThreads) :
00031    PsnMultiThreadedScheduler(numberOfSteps, numberOfThreads, false),
00032    _indexOfBenchmarkingSample ( 0 ),
00033    _numberOfSamples ( 350 )
00034 {
00035 
00036    _localWaitingTimes = new long * [ _numberOfThreads ] ;
00037    
00038    for (int i = 0 ; i < _numberOfThreads ; i++ ) 
00039       {
00040          _localWaitingTimes [ i ] = new long [ _numberOfSamples ] ;
00041       }
00042    
00043    _duplicatedObjectScheduler = new PsnBenchScheduler( numberOfSteps, _indexOfBenchmarkingSample , _numberOfSamples , cout ) ;
00044 
00045    for (int i = 0 ; i < _numberOfThreads ; i++ )
00046       {
00047          (*_localSchedulers)[i] = new PsnBenchScheduler( numberOfSteps, _indexOfBenchmarkingSample, _numberOfSamples , cout ) ;
00048       }
00049    
00050    int ret;
00051    for (int i = 0 ; i < _numberOfThreads ; i++ ) 
00052       {
00053       
00054          ret = pthread_create( & (_threadIds [i]), 
00055                                0,
00056                                (void *(*)(void *))_threadContainer,
00057                                (*_threadData)[i]);
00058          if (ret) 
00059          {
00060             PsController::error("Thread creation impossible") ;
00061          }
00062          
00063       }
00064 
00065 }
00066 
00067 
00068 
00069 PsnMultiThreadedBenchedScheduler::~PsnMultiThreadedBenchedScheduler() {
00070    long totalTime = 0 ;
00071    
00072    for (int i = 0 ; i < _numberOfThreads ; i++ ) 
00073       {
00074          totalTime = 0 ;
00075          cout <<"thread "<<i<<endl;
00076          for ( int j =0 ; j < _numberOfSamples ; j ++ ) 
00077             {
00078                totalTime+=_localWaitingTimes [i] [j] ;
00079                cout<<_localWaitingTimes [i] [j] <<" , ";
00080             }
00081          cout<< "average " <<totalTime/_numberOfSamples<<endl;
00082          
00083          delete _localWaitingTimes [ i ] ;
00084          
00085       }  
00086    
00087    delete [] _localWaitingTimes ;
00088 }
00089 
00090 
00091 
00092 void PsnMultiThreadedBenchedScheduler::runStep (unsigned int which) {
00093 
00094    _indexOfBenchmarkingSample = (_indexOfBenchmarkingSample + 1) % _numberOfSamples ;
00095    
00096    PsnMultiThreadedScheduler::runStep ( which ) ; 
00097 
00098 }
00099 
00100 
00101 
00102 
00103 void * PsnMultiThreadedBenchedScheduler::_threadContainer (void * myThreadData) {
00104    
00105    pair<PsnMultiThreadedBenchedScheduler *, unsigned int> * threadData = ( pair<PsnMultiThreadedBenchedScheduler *, unsigned int> * ) myThreadData ;
00106 
00107    ( * threadData ).first->run( ( * threadData ).second ) ;
00108 
00109    return threadData ;
00110 }
00111 
00112 
00113 void PsnMultiThreadedBenchedScheduler::run( unsigned int whichFrameScheduler ) 
00114 {
00115    timeval _dateReelleDebut ;
00116    timeval _dateReelleFin ;
00117    int counter = 0 ;
00118 
00119    while ( true ) {
00120       
00121       _barrier->Sync() ;
00122       
00123 
00124       (*_localSchedulers)[ whichFrameScheduler ]->runStep ( _currentStep ) ;
00125 
00126       gettimeofday(&_dateReelleDebut, NULL);
00127 
00128       _barrier->Sync() ;
00129 
00130       gettimeofday(&_dateReelleFin, NULL);
00131       if (_dateReelleFin.tv_usec > _dateReelleDebut.tv_usec ) 
00132       {
00133          _localWaitingTimes [whichFrameScheduler] [ counter ] = _dateReelleFin.tv_usec - _dateReelleDebut.tv_usec ;
00134       }
00135 
00136       counter = ( counter + 1 ) % _numberOfSamples ;
00137 
00138    }
00139 }
00140 
00141 
00142 
00143 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:00 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001