OpenMP initialization code
parent
dc801e7d6c
commit
d2a0d96f95
|
@ -147,6 +147,9 @@ public:
|
||||||
/// Shut down the threading system
|
/// Shut down the threading system
|
||||||
static void staticShutdown();
|
static void staticShutdown();
|
||||||
|
|
||||||
|
/// Initialize Mitsuba's threading system for simultaneous use of OpenMP
|
||||||
|
static void initializeOpenMP();
|
||||||
|
|
||||||
MTS_DECLARE_CLASS()
|
MTS_DECLARE_CLASS()
|
||||||
protected:
|
protected:
|
||||||
/// Virtual destructor
|
/// Virtual destructor
|
||||||
|
|
|
@ -39,6 +39,21 @@ protected:
|
||||||
virtual ~MainThread() { }
|
virtual ~MainThread() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OpenMPThread : public Thread {
|
||||||
|
public:
|
||||||
|
OpenMPThread() : Thread("main") {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void run() {
|
||||||
|
Log(EError, "The OpenMP thread is already running!");
|
||||||
|
}
|
||||||
|
|
||||||
|
MTS_DECLARE_CLASS()
|
||||||
|
protected:
|
||||||
|
virtual ~OpenMPThread() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
ThreadLocal<Thread> *Thread::m_self = NULL;
|
ThreadLocal<Thread> *Thread::m_self = NULL;
|
||||||
|
|
||||||
#if defined(__LINUX__) || defined(__OSX__)
|
#if defined(__LINUX__) || defined(__OSX__)
|
||||||
|
@ -278,6 +293,26 @@ void Thread::staticShutdown() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Thread::initializeOpenMP() {
|
||||||
|
ref<Logger> logger = Thread::getThread()->getLogger();
|
||||||
|
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
||||||
|
|
||||||
|
#pragma omp parallel
|
||||||
|
{
|
||||||
|
Thread *thread = Thread::getThread();
|
||||||
|
if (!thread) {
|
||||||
|
thread = new OpenMPThread();
|
||||||
|
thread->m_running = true;
|
||||||
|
thread->m_thread = pthread_self();
|
||||||
|
thread->m_joinMutex = new Mutex();
|
||||||
|
thread->m_joined = false;
|
||||||
|
thread->m_fresolver = fResolver;
|
||||||
|
thread->m_logger = logger;
|
||||||
|
m_self->set(thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Thread::~Thread() {
|
Thread::~Thread() {
|
||||||
if (m_running)
|
if (m_running)
|
||||||
Log(EWarn, "Destructor called while Thread '%s' is still running", m_name.c_str());
|
Log(EWarn, "Destructor called while Thread '%s' is still running", m_name.c_str());
|
||||||
|
@ -285,4 +320,5 @@ Thread::~Thread() {
|
||||||
|
|
||||||
MTS_IMPLEMENT_CLASS(Thread, true, Object)
|
MTS_IMPLEMENT_CLASS(Thread, true, Object)
|
||||||
MTS_IMPLEMENT_CLASS(MainThread, false, Thread)
|
MTS_IMPLEMENT_CLASS(MainThread, false, Thread)
|
||||||
|
MTS_IMPLEMENT_CLASS(OpenMPThread, false, Thread)
|
||||||
MTS_NAMESPACE_END
|
MTS_NAMESPACE_END
|
||||||
|
|
|
@ -124,8 +124,8 @@ public:
|
||||||
m_workResult->put(PhotonMap::Photon(its.p, its.geoFrame.n, -its.toWorld(its.wi), weight, depth));
|
m_workResult->put(PhotonMap::Photon(its.p, its.geoFrame.n, -its.toWorld(its.wi), weight, depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMediumInteraction(int depth, bool caustic, const MediumSamplingRecord &mRec, const Vector &wi,
|
void handleMediumInteraction(int depth, bool caustic, const MediumSamplingRecord &mRec, Float time,
|
||||||
const Spectrum &weight) {
|
const Vector &wi, const Spectrum &weight) {
|
||||||
if (m_type == GatherPhotonProcess::EVolumePhotons && depth > 1)
|
if (m_type == GatherPhotonProcess::EVolumePhotons && depth > 1)
|
||||||
m_workResult->put(PhotonMap::Photon(mRec.p, Normal(), -wi, weight, depth));
|
m_workResult->put(PhotonMap::Photon(mRec.p, Normal(), -wi, weight, depth));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue