more MacOS-related OpenMP bugfixes
parent
b7d6fc7dba
commit
b83596accd
|
@ -174,9 +174,19 @@ private:
|
||||||
boost::scoped_ptr<ThreadPrivate> d;
|
boost::scoped_ptr<ThreadPrivate> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Variant of \c omp_get_max_threads that works on all platforms
|
#if defined(MTS_OPENMP)
|
||||||
|
#if defined(__OSX__)
|
||||||
|
/// Variant of \c omp_get_max_threads that works on OSX
|
||||||
extern MTS_EXPORT_CORE int mts_omp_get_max_threads();
|
extern MTS_EXPORT_CORE int mts_omp_get_max_threads();
|
||||||
|
|
||||||
|
/// Variant of \c omp_get_thread_num that works on OSX
|
||||||
|
extern MTS_EXPORT_CORE int mts_omp_get_thread_num();
|
||||||
|
#else
|
||||||
|
#define mts_omp_get_max_threads omp_get_max_threads
|
||||||
|
#define mts_omp_get_thread_num omp_get_thread_num
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
MTS_NAMESPACE_END
|
MTS_NAMESPACE_END
|
||||||
|
|
||||||
#endif /* __MITSUBA_CORE_THREAD_H_ */
|
#endif /* __MITSUBA_CORE_THREAD_H_ */
|
||||||
|
|
|
@ -57,7 +57,7 @@ BeamRadianceEstimator::BeamRadianceEstimator(const PhotonMap *pmap, size_t looku
|
||||||
#endif
|
#endif
|
||||||
for (int i=0; i<(int) m_photonCount; ++i) {
|
for (int i=0; i<(int) m_photonCount; ++i) {
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
int tid = omp_get_thread_num();
|
int tid = mts_omp_get_thread_num();
|
||||||
#else
|
#else
|
||||||
int tid = 0;
|
int tid = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -181,8 +181,6 @@ public:
|
||||||
samplers[i] = clonedSampler.get();
|
samplers[i] = clonedSampler.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::initializeOpenMP(Scheduler::getInstance()->getLocalWorkerCount());
|
|
||||||
|
|
||||||
int samplerResID = sched->registerMultiResource(samplers);
|
int samplerResID = sched->registerMultiResource(samplers);
|
||||||
|
|
||||||
#ifdef MTS_DEBUG_FP
|
#ifdef MTS_DEBUG_FP
|
||||||
|
@ -224,7 +222,7 @@ public:
|
||||||
for (int i=0; i<(int) m_gatherBlocks.size(); ++i) {
|
for (int i=0; i<(int) m_gatherBlocks.size(); ++i) {
|
||||||
std::vector<GatherPoint> &gatherPoints = m_gatherBlocks[i];
|
std::vector<GatherPoint> &gatherPoints = m_gatherBlocks[i];
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
Sampler *sampler = static_cast<Sampler *>(samplers[omp_get_thread_num()]);
|
Sampler *sampler = static_cast<Sampler *>(samplers[mts_omp_get_thread_num()]);
|
||||||
#else
|
#else
|
||||||
Sampler *sampler = static_cast<Sampler *>(samplers[0]);
|
Sampler *sampler = static_cast<Sampler *>(samplers[0]);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -390,18 +390,22 @@ std::string Thread::toString() const {
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MTS_OPENMP)
|
|
||||||
static int __omp_threadCount = 0;
|
|
||||||
#endif
|
|
||||||
static std::vector<Thread *> __unmanagedThreads;
|
static std::vector<Thread *> __unmanagedThreads;
|
||||||
static boost::mutex __unmanagedMutex;
|
static boost::mutex __unmanagedMutex;
|
||||||
|
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP) && defined(__OSX__)
|
||||||
|
static int __omp_threadCount = 0;
|
||||||
|
static pthread_key_t __omp_key;
|
||||||
|
|
||||||
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
|
||||||
implementation bug that causes crashes on OSX */
|
implementation bug that causes crashes on OSX */
|
||||||
return __omp_threadCount;
|
return __omp_threadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mts_omp_get_thread_num() {
|
||||||
|
return reinterpret_cast<int>(pthread_getspecific(__omp_key));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Thread::staticInitialization() {
|
void Thread::staticInitialization() {
|
||||||
|
@ -457,7 +461,11 @@ void Thread::initializeOpenMP(size_t threadCount) {
|
||||||
ref<Logger> logger = Thread::getThread()->getLogger();
|
ref<Logger> logger = Thread::getThread()->getLogger();
|
||||||
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
||||||
|
|
||||||
|
#if defined(__OSX__)
|
||||||
__omp_threadCount = threadCount;
|
__omp_threadCount = threadCount;
|
||||||
|
pthread_key_create(&__omp_key, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
omp_set_num_threads((int) threadCount);
|
omp_set_num_threads((int) threadCount);
|
||||||
omp_set_dynamic(false);
|
omp_set_dynamic(false);
|
||||||
|
|
||||||
|
@ -465,6 +473,7 @@ void Thread::initializeOpenMP(size_t threadCount) {
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
|
pthread_setspecific(__omp_key, reinterpret_cast<void *>(counter));
|
||||||
detail::initializeLocalTLS();
|
detail::initializeLocalTLS();
|
||||||
Thread *thread = Thread::getThread();
|
Thread *thread = Thread::getThread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ void blueNoisePointSet(const Scene *scene, const std::vector<Shape *> &shapes,
|
||||||
#endif
|
#endif
|
||||||
for (int i=0; i<nsamples; ++i) {
|
for (int i=0; i<nsamples; ++i) {
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
int tid = omp_get_thread_num();
|
int tid = mts_omp_get_thread_num();
|
||||||
#else
|
#else
|
||||||
int tid = 0;
|
int tid = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue