Commit 9ba717fc authored by Emeric Verschuur's avatar Emeric Verschuur

--no commit message

--no commit message
parent 3b46bf8d
......@@ -23,6 +23,7 @@
#include <fstream>
#include <iostream>
#include <cassert>
#include <sys/time.h>
#ifdef WIN32
#define msleep(s) Sleep(s)
#else
......@@ -155,21 +156,49 @@ static void *__lr_generateimage(void *ptr){
return NULL;
}
static void __getTimevalDiff(timeval &b, timeval &e, int &h, int &m, int &s, int &us){
struct timeval d;
d.tv_sec = e.tv_sec - b.tv_sec;
d.tv_usec = e.tv_usec - b.tv_usec;
if (d.tv_usec < 0) {
d.tv_sec--;
d.tv_usec += 1000000;
}
h = d.tv_sec / 3600;
d.tv_sec %= 3600;
m = d.tv_sec / 60;
d.tv_sec %= 60;
s = d.tv_sec;
us = d.tv_usec;
}
void LrScene::generateImage(int nbThreads)
{
timeval tvInitBeg,tvInitEnd;
timeval tvCalculBeg,tvCalculEnd;
int h,m,s,us;
gettimeofday(&tvInitBeg, NULL);
initialize();
gettimeofday(&tvInitEnd, NULL);
cout << "[.........10........20........30........40........50........60........70........80........90.........]\r[ " << flush;
__getTimevalDiff(tvInitBeg,tvInitEnd,h,m,s,us);
cout << "Temps d'initialisation : " << h << " heures, " << m << " minules, "
<< s << " secondes, " << us << " microsecondes" << endl;
int nbL = m_image->getHeight();
assert(nbThreads > 0);
assert(nbThreads < nbL);
assert(nbL % nbThreads == 0);
__lr_generateimage_t ptr={this,-1,PTHREAD_MUTEX_INITIALIZER};
pthread_t thLst[nbThreads];
cout << "Nombre de threads : "<< nbThreads << endl;
cout << "[.........10........20........30........40........50........60........70........80........90.........]\r[ " << flush;
gettimeofday(&tvCalculBeg, NULL);
for( int i=0 ; i < nbThreads ; i++ ){
pthread_create(&thLst[i],NULL,__lr_generateimage,(void*)&ptr);
}
......@@ -190,6 +219,15 @@ void LrScene::generateImage(int nbThreads)
for( int i=0 ; i < nbThreads ; i++ ){
pthread_join(thLst[i],NULL);
}
gettimeofday(&tvCalculEnd, NULL);
cout << (char)8 << ']' << endl;
__getTimevalDiff(tvCalculBeg,tvCalculEnd,h,m,s,us);
cout << "Temps de calcul : " << h << " heures, " << m << " minules, "
<< s << " secondes, " << us << " microsecondes" << endl;
__getTimevalDiff(tvInitBeg,tvCalculEnd,h,m,s,us);
cout << "Temps total : " << h << " heures, " << m << " minules, "
<< s << " secondes, " << us << " microsecondes" << endl;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment