--- a/src/raytracer.cc Fri Mar 28 17:13:21 2008 +0100
+++ b/src/raytracer.cc Fri Mar 28 21:47:32 2008 +0100
@@ -404,43 +404,33 @@
Ray ray;
for (;;)
{
- cout<<"#worker "<<pthread_self()<<" locking queue"<<endl;
pthread_mutex_lock(&rt->sample_queue_mutex);
pthread_cond_signal(&rt->worker_ready_cond);
- // if queue is empty, wait for samples
while (rt->sample_queue.empty()) {
if (rt->sample_queue_end)
{
- cout<<"#worker "<<pthread_self()<<" end of queue, unlocking queue and exiting..."<<endl;
pthread_mutex_unlock(&rt->sample_queue_mutex);
pthread_exit(NULL);
}
- cout<<"#worker "<<pthread_self()<<" waiting for cond"<<endl;
pthread_cond_wait(&rt->sample_queue_cond, &rt->sample_queue_mutex);
}
-
sample = rt->sample_queue.front();
rt->sample_queue.pop();
- cout<<"#worker "<<pthread_self()<<" unlocking queue"<<endl;
+
pthread_mutex_unlock(&rt->sample_queue_mutex);
// do the work
- cout<<"#worker "<<pthread_self()<<" locking sampler (camera)"<<endl;
pthread_mutex_lock(&rt->sampler_mutex);
ray = rt->camera->makeRay(sample);
- cout<<"#worker "<<pthread_self()<<" unlocking sampler (camera)"<<endl;
pthread_mutex_unlock(&rt->sampler_mutex);
- cout<<"#worker "<<pthread_self()<<" ray tracing..."<<endl;
col = rt->raytrace(ray, 0, NULL);
-
+
// save the result
- cout<<"#worker "<<pthread_self()<<" locking sampler"<<endl;
pthread_mutex_lock(&rt->sampler_mutex);
rt->sampler->saveSample(sample, col);
- cout<<"#worker "<<pthread_self()<<" unlocking sampler"<<endl;
pthread_mutex_unlock(&rt->sampler_mutex);
delete sample;
@@ -455,7 +445,7 @@
sample_queue_end = false;
// create workers
- dbgmsg(1, "* using %d threads\n", num_threads);
+ dbgmsg(1, "* running %d threads\n", num_threads);
pthread_t threads[num_threads];
for (int t = 0; t < num_threads; t++)
{
@@ -466,70 +456,62 @@
}
}
+ dbgmsg(1, "* raytracing...\n");
+ dbgmsg(2, "- 0%% done");
+
sampler->init();
- int sampnum = 0;
- cout<<"locking sampler"<<endl;
+ int sampnum = 0, sampdone;
+ Sample *sample;
+
pthread_mutex_lock(&sampler_mutex);
while ( (sampnum = sampler->initSampleSet()) > 0 )
{
- Sample *sample;
+ sampdone = 0;
while ( (sample = sampler->nextSample()) != NULL )
{
- cout<<"unlocking sampler and locking queue"<<endl;
pthread_mutex_unlock(&sampler_mutex);
pthread_mutex_lock(&sample_queue_mutex);
sample_queue.push(sample);
+ // wait for workers if there is enough samples ready on queue
if (sample_queue.size() > 1000)
{
- while (sample_queue.size() > 100)
- {
- pthread_cond_signal(&sample_queue_cond);
- pthread_cond_wait(&worker_ready_cond, &sample_queue_mutex);
- }
+ while (sample_queue.size() > 100)
+ {
+ pthread_cond_signal(&sample_queue_cond);
+ pthread_cond_wait(&worker_ready_cond, &sample_queue_mutex);
+ }
}
- cout<<"sending signal and unlocking queue"<<endl;
+ sampdone++;
+ if ((sampdone & 0xfff) == 0)
+ dbgmsg(2, "\b\b\b\b\b\b\b\b%2d%% done", (sampdone - sample_queue.size())*100/sampnum);
+
pthread_cond_signal(&sample_queue_cond);
pthread_mutex_unlock(&sample_queue_mutex);
-
- sampnum--;
- if ((sampnum % 1000) == 0)
- dbgmsg(2, "\b\b\b\b\b\b\b\b%8d", sampnum);
-
-
- cout<<"locking sampler"<<endl;
pthread_mutex_lock(&sampler_mutex);
}
- dbgmsg(2, "\n");
+ dbgmsg(2, "\b\b\b\b\b\b\b\b100%% done\n");
}
- cout<<"unlocking sampler"<<endl;
pthread_mutex_unlock(&sampler_mutex);
// wait for workers
dbgmsg(2, "- waiting for threads to finish\n");
- cout<<"locking queue"<<endl;
pthread_mutex_lock(&sample_queue_mutex);
sample_queue_end = true;
while (!sample_queue.empty())
{
- cout<<"broadcasting signal and unlocking queue"<<endl;
pthread_cond_broadcast(&sample_queue_cond);
pthread_mutex_unlock(&sample_queue_mutex);
- cout<<"locking queue"<<endl;
pthread_mutex_lock(&sample_queue_mutex);
}
- cout<<"broadcasting signal and unlocking queue"<<endl;
pthread_cond_broadcast(&sample_queue_cond);
pthread_mutex_unlock(&sample_queue_mutex);
- cout<<"joining threads"<<endl;
for (int t = 0; t < num_threads; t++)
pthread_join(threads[t], NULL);
- cout<<"done!"<<endl;
-
#if 0
RenderrowData *d;
--- a/src/sampler.cc Fri Mar 28 17:13:21 2008 +0100
+++ b/src/sampler.cc Fri Mar 28 21:47:32 2008 +0100
@@ -40,14 +40,12 @@
const int samples = gridsamples[oversample];
if ( phase == 0 )
{
- cout << "phase 1" << endl;
phase++;
sx = -1;
return w*h*samples;
}
else if ( phase == 1 && oversample )
{
- cout << "phase 2" << endl;
phase = -1;
Float *buf;
for (buf = buffer; buf != buffer + w*h*3; buf++)