fixed some openmp + TLS/related crashes
parent
403706fa62
commit
30efd3c151
|
@ -242,6 +242,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MTS_OPENMP)
|
||||||
|
Thread::initializeOpenMP(nCores);
|
||||||
|
#endif
|
||||||
|
|
||||||
int it = 0;
|
int it = 0;
|
||||||
while (m_running)
|
while (m_running)
|
||||||
photonMapPass(++it, queue, job, film, sceneResID, sensorResID, indepSamplerResID);
|
photonMapPass(++it, queue, job, film, sceneResID, sensorResID, indepSamplerResID);
|
||||||
|
|
|
@ -187,6 +187,10 @@ public:
|
||||||
enableFPExceptions();
|
enableFPExceptions();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MTS_OPENMP)
|
||||||
|
Thread::initializeOpenMP(nCores);
|
||||||
|
#endif
|
||||||
|
|
||||||
int it=0;
|
int it=0;
|
||||||
while (m_running) {
|
while (m_running) {
|
||||||
distributedRTPass(scene, samplers);
|
distributedRTPass(scene, samplers);
|
||||||
|
|
|
@ -396,6 +396,7 @@ static boost::mutex __unmanagedMutex;
|
||||||
#if defined(MTS_OPENMP) && defined(__OSX__)
|
#if defined(MTS_OPENMP) && defined(__OSX__)
|
||||||
static int __omp_threadCount = 0;
|
static int __omp_threadCount = 0;
|
||||||
static pthread_key_t __omp_key;
|
static pthread_key_t __omp_key;
|
||||||
|
static bool __omp_key_created;
|
||||||
|
|
||||||
int mts_omp_get_max_threads() {
|
int mts_omp_get_max_threads() {
|
||||||
/* This function exists to sidestep an annoying
|
/* This function exists to sidestep an annoying
|
||||||
|
@ -451,6 +452,8 @@ void Thread::staticShutdown() {
|
||||||
ThreadPrivate::self = NULL;
|
ThreadPrivate::self = NULL;
|
||||||
detail::destroyGlobalTLS();
|
detail::destroyGlobalTLS();
|
||||||
#if defined(__OSX__)
|
#if defined(__OSX__)
|
||||||
|
if (__omp_key_created)
|
||||||
|
pthread_key_delete(__omp_key);
|
||||||
__mts_autorelease_shutdown();
|
__mts_autorelease_shutdown();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -461,19 +464,25 @@ void Thread::initializeOpenMP(size_t threadCount) {
|
||||||
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
||||||
|
|
||||||
#if defined(__OSX__)
|
#if defined(__OSX__)
|
||||||
|
if (!__omp_key_created) {
|
||||||
|
pthread_key_create(&__omp_key, NULL);
|
||||||
|
__omp_key_created = true;
|
||||||
|
}
|
||||||
__omp_threadCount = threadCount;
|
__omp_threadCount = threadCount;
|
||||||
pthread_key_create(&__omp_key, NULL);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (omp_get_dynamic())
|
||||||
|
omp_set_dynamic(0);
|
||||||
|
|
||||||
omp_set_num_threads((int) threadCount);
|
omp_set_num_threads((int) threadCount);
|
||||||
omp_set_dynamic(false);
|
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
#if defined(__OSX__)
|
#if defined(__OSX__)
|
||||||
pthread_setspecific(__omp_key, reinterpret_cast<void *>(counter));
|
if (!pthread_getspecific(__omp_key))
|
||||||
|
pthread_setspecific(__omp_key, reinterpret_cast<void *>(counter));
|
||||||
#endif
|
#endif
|
||||||
detail::initializeLocalTLS();
|
detail::initializeLocalTLS();
|
||||||
Thread *thread = Thread::getThread();
|
Thread *thread = Thread::getThread();
|
||||||
|
@ -484,14 +493,25 @@ void Thread::initializeOpenMP(size_t threadCount) {
|
||||||
formatString("omp%i", counter));
|
formatString("omp%i", counter));
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
const std::string threadName = "Mitsuba: " + thread->getName();
|
||||||
|
|
||||||
|
#if defined(__LINUX__)
|
||||||
|
prctl(PR_SET_NAME, threadName.c_str());
|
||||||
|
#elif defined(__OSX__)
|
||||||
|
pthread_setname_np(threadName.c_str());
|
||||||
|
#elif defined(__WINDOWS__)
|
||||||
|
SetThreadName(threadName.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
thread->d->running = false;
|
thread->d->running = false;
|
||||||
thread->d->joined = false;
|
thread->d->joined = false;
|
||||||
thread->d->fresolver = fResolver;
|
thread->d->fresolver = fResolver;
|
||||||
thread->d->logger = logger;
|
thread->d->logger = logger;
|
||||||
thread->incRef();
|
thread->incRef();
|
||||||
ThreadPrivate::self->set(thread);
|
ThreadPrivate::self->set(thread);
|
||||||
|
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
__unmanagedThreads.push_back((UnmanagedThread *) thread);
|
__unmanagedThreads.push_back((UnmanagedThread *) thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue