better OpenMP integration
parent
79ff47e7b1
commit
d08a351a6c
|
@ -148,7 +148,7 @@ public:
|
|||
static void staticShutdown();
|
||||
|
||||
/// Initialize Mitsuba's threading system for simultaneous use of OpenMP
|
||||
static void initializeOpenMP();
|
||||
static void initializeOpenMP(size_t threadCount);
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
protected:
|
||||
|
|
|
@ -40,11 +40,14 @@ public:
|
|||
|
||||
MTS_DECLARE_CLASS()
|
||||
protected:
|
||||
typedef std::map<std::string, std::string> ParameterMap;
|
||||
|
||||
/// Virtual destructor
|
||||
virtual ~Utility() { }
|
||||
|
||||
/// Load a scene
|
||||
ref<Scene> loadScene(const std::string &fname);
|
||||
ref<Scene> loadScene(const std::string &fname,
|
||||
const ParameterMap ¶ms= ParameterMap());
|
||||
};
|
||||
|
||||
#define MTS_DECLARE_UTILITY() \
|
||||
|
|
|
@ -124,9 +124,6 @@ public:
|
|||
Vector2i cropSize = film->getCropSize();
|
||||
Point2i cropOffset = film->getCropOffset();
|
||||
|
||||
#if !defined(__OSX__) && defined(_OPENMP)
|
||||
omp_set_num_threads(nCores);
|
||||
#endif
|
||||
m_gatherPoints.clear();
|
||||
m_running = true;
|
||||
for (size_t i=0; i<m_blocks.size(); ++i)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <mitsuba/core/lock.h>
|
||||
#include <mitsuba/core/fresolver.h>
|
||||
#include <errno.h>
|
||||
#include <omp.h>
|
||||
|
||||
MTS_NAMESPACE_BEGIN
|
||||
|
||||
|
@ -41,8 +42,8 @@ protected:
|
|||
|
||||
class OpenMPThread : public Thread {
|
||||
public:
|
||||
OpenMPThread() : Thread("main") {
|
||||
}
|
||||
OpenMPThread(int threadIdx)
|
||||
: Thread(formatString("omp%i", threadIdx)) { }
|
||||
|
||||
virtual void run() {
|
||||
Log(EError, "The OpenMP thread is already running!");
|
||||
|
@ -293,15 +294,17 @@ void Thread::staticShutdown() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void Thread::initializeOpenMP() {
|
||||
void Thread::initializeOpenMP(size_t threadCount) {
|
||||
ref<Logger> logger = Thread::getThread()->getLogger();
|
||||
ref<FileResolver> fResolver = Thread::getThread()->getFileResolver();
|
||||
|
||||
omp_set_num_threads(threadCount);
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
Thread *thread = Thread::getThread();
|
||||
if (!thread) {
|
||||
thread = new OpenMPThread();
|
||||
thread = new OpenMPThread(omp_get_thread_num());
|
||||
thread->m_running = true;
|
||||
thread->m_thread = pthread_self();
|
||||
thread->m_joinMutex = new Mutex();
|
||||
|
|
|
@ -155,7 +155,7 @@ public:
|
|||
const MediumSamplingRecord &mRec, const Medium *medium,
|
||||
Float time, const Vector &wi, const Spectrum &weight) {
|
||||
if (m_type == GatherPhotonProcess::EVolumePhotons)
|
||||
m_workResult->put(Photon(mRec.p, Normal(), -wi, weight, depth));
|
||||
m_workResult->put(Photon(mRec.p, Normal(0.0f, 0.0f, 0.0f), -wi, weight, depth));
|
||||
}
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
MTS_NAMESPACE_BEGIN
|
||||
|
||||
ref<Scene> Utility::loadScene(const std::string &filename) {
|
||||
ref<Scene> Utility::loadScene(const std::string &filename,
|
||||
const ParameterMap ¶ms) {
|
||||
/* Prepare for parsing scene descriptions */
|
||||
FileResolver *resolver = Thread::getThread()->getFileResolver();
|
||||
SAXParser* parser = new SAXParser();
|
||||
|
@ -37,7 +38,7 @@ ref<Scene> Utility::loadScene(const std::string &filename) {
|
|||
parser->setExternalNoNamespaceSchemaLocation(schemaPath.file_string().c_str());
|
||||
|
||||
std::map<std::string, std::string> parameters;
|
||||
SceneHandler *handler = new SceneHandler(parameters);
|
||||
SceneHandler *handler = new SceneHandler(params);
|
||||
parser->setDoNamespaces(true);
|
||||
parser->setDocumentHandler(handler);
|
||||
parser->setErrorHandler(handler);
|
||||
|
|
|
@ -70,7 +70,7 @@ void help() {
|
|||
cout << " workloads (default: 32). Only applies to some integrators." << endl << endl;
|
||||
cout << " -v Be more verbose" << endl << endl;
|
||||
cout << " -w Treat warnings as errors" << endl << endl;
|
||||
cout << " -b Disable progress bars" << endl << endl;
|
||||
cout << " -z Disable progress bars" << endl << endl;
|
||||
cout << " The README file included with the distribution contains further information." << endl;
|
||||
}
|
||||
|
||||
|
@ -217,6 +217,9 @@ int ubi_main(int argc, char **argv) {
|
|||
|
||||
ProgressReporter::setEnabled(progressBars);
|
||||
|
||||
/* Initialize OpenMP */
|
||||
Thread::initializeOpenMP(nprocs);
|
||||
|
||||
/* Configure the logging subsystem */
|
||||
ref<Logger> log = Thread::getThread()->getLogger();
|
||||
log->setLogLevel(logLevel);
|
||||
|
|
|
@ -188,6 +188,9 @@ int ubi_main(int argc, char **argv) {
|
|||
/* Configure the logging subsystem */
|
||||
ref<Logger> log = Thread::getThread()->getLogger();
|
||||
log->setLogLevel(logLevel);
|
||||
|
||||
/* Initialize OpenMP */
|
||||
Thread::initializeOpenMP(nprocs);
|
||||
|
||||
/* Disable the default appenders */
|
||||
for (size_t i=0; i<log->getAppenderCount(); ++i) {
|
||||
|
|
|
@ -191,6 +191,9 @@ int mtsutil(int argc, char **argv) {
|
|||
/* Configure the logging subsystem */
|
||||
ref<Logger> log = Thread::getThread()->getLogger();
|
||||
log->setLogLevel(logLevel);
|
||||
|
||||
/* Initialize OpenMP */
|
||||
Thread::initializeOpenMP(nprocs);
|
||||
|
||||
/* Disable the default appenders */
|
||||
for (size_t i=0; i<log->getAppenderCount(); ++i) {
|
||||
|
|
|
@ -102,6 +102,7 @@ int main(int argc, char *argv[]) {
|
|||
PluginManager::staticInitialization();
|
||||
Statistics::staticInitialization();
|
||||
Thread::staticInitialization();
|
||||
Thread::initializeOpenMP(getProcessorCount());
|
||||
Logger::staticInitialization();
|
||||
Spectrum::staticInitialization();
|
||||
Scheduler::staticInitialization();
|
||||
|
|
Loading…
Reference in New Issue