omp_get_max_threads still occasionally causes crashes even in binaries compiled with icl.. committing a workaround

metadata
Wenzel Jakob 2012-09-30 22:46:12 -04:00
parent f589e35b1d
commit b7d6fc7dba
4 changed files with 23 additions and 5 deletions

View File

@ -174,6 +174,9 @@ private:
boost::scoped_ptr<ThreadPrivate> d;
};
/// Variant of \c omp_get_max_threads that works on all platforms
extern MTS_EXPORT_CORE int mts_omp_get_max_threads();
MTS_NAMESPACE_END
#endif /* __MITSUBA_CORE_THREAD_H_ */

View File

@ -43,7 +43,7 @@ BeamRadianceEstimator::BeamRadianceEstimator(const PhotonMap *pmap, size_t looku
Log(EInfo, "Computing photon radii ..");
#if defined(MTS_OPENMP)
int tcount = omp_get_max_threads();
int tcount = mts_omp_get_max_threads();
#else
int tcount = 1;
#endif

View File

@ -390,9 +390,26 @@ std::string Thread::toString() const {
return oss.str();
}
#if defined(MTS_OPENMP)
static int __omp_threadCount = 0;
#endif
static std::vector<Thread *> __unmanagedThreads;
static boost::mutex __unmanagedMutex;
#if defined(MTS_OPENMP)
int mts_omp_get_max_threads() {
/* This function exists to sidestep an annoying
implementation bug that causes crashes on OSX */
return __omp_threadCount;
}
#endif
void Thread::staticInitialization() {
#if defined(__OSX__)
__mts_autorelease_init();
#endif
#if defined(MTS_OPENMP)
__omp_threadCount = omp_get_max_threads();
#endif
detail::initializeGlobalTLS();
detail::initializeLocalTLS();
@ -405,9 +422,6 @@ void Thread::staticInitialization() {
ThreadPrivate::self->set(mainThread);
}
static std::vector<Thread *> __unmanagedThreads;
static boost::mutex __unmanagedMutex;
Thread *Thread::registerUnmanagedThread(const std::string &name) {
Thread *thread = getThread();
if (!thread) {
@ -443,6 +457,7 @@ void Thread::initializeOpenMP(size_t threadCount) {
ref<Logger> logger = Thread::getThread()->getLogger();
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
__omp_threadCount = threadCount;
omp_set_num_threads((int) threadCount);
omp_set_dynamic(false);

View File

@ -68,7 +68,7 @@ void blueNoisePointSet(const Scene *scene, const std::vector<Shape *> &shapes,
int kmax = 8; /* Perform 8 trial runs */
#if defined(MTS_OPENMP)
int nproc = omp_get_max_threads();
int nproc = mts_omp_get_max_threads();
#else
int nproc = 1;
#endif