Commit b912cf14 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

BUG: #1761: make sure OpenMP runtime is loaded by the main executable

No related merge requests found
Showing with 39 additions and 2 deletions
+39 -2
...@@ -103,8 +103,15 @@ public: ...@@ -103,8 +103,15 @@ public:
* *
*/ */
static itk::LoggerBase::PriorityLevelType GetLoggerLevel(); static itk::LoggerBase::PriorityLevelType GetLoggerLevel();
/**
* If OpenMP is enabled, the number of threads for openMP is set to the
* same number as in ITK (see GetGlobalDefaultNumberOfThreads()). This number
* of threads is returned.
* If OpenMP is disabled, this function does nothing
*/
static int InitOpenMPThreads();
private: private:
ConfigurationManager() = delete; ConfigurationManager() = delete;
~ConfigurationManager() = delete; ~ConfigurationManager() = delete;
......
...@@ -23,8 +23,13 @@ ...@@ -23,8 +23,13 @@
#include "otbMacro.h" #include "otbMacro.h"
#include "otbLogger.h" #include "otbLogger.h"
#include "itkMultiThreader.h"
#include "itksys/SystemTools.hxx" #include "itksys/SystemTools.hxx"
#ifdef _OPENMP
#include <omp.h>
#endif
#include <cstdlib> #include <cstdlib>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
...@@ -99,4 +104,14 @@ itk::LoggerBase::PriorityLevelType ConfigurationManager::GetLoggerLevel() ...@@ -99,4 +104,14 @@ itk::LoggerBase::PriorityLevelType ConfigurationManager::GetLoggerLevel()
return level; return level;
} }
int ConfigurationManager::InitOpenMPThreads()
{
int ret = 1;
#ifdef _OPENMP
ret = itk::MultiThreader::GetGlobalDefaultNumberOfThreads();
omp_set_num_threads(ret);
#endif
return ret;
}
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define otbTestMain_h #define otbTestMain_h
#include "otbConfigure.h" #include "otbConfigure.h"
#include "otbConfigurationManager.h"
#include <map> #include <map>
#include <string> #include <string>
...@@ -72,6 +73,8 @@ int main(int ac, char* av[]) ...@@ -72,6 +73,8 @@ int main(int ac, char* av[])
#ifdef OTB_USE_MPI #ifdef OTB_USE_MPI
otb::MPIConfig::Instance()->Init(ac,av); otb::MPIConfig::Instance()->Init(ac,av);
#endif #endif
otb::ConfigurationManager::InitOpenMPThreads();
bool lFlagRegression(false); bool lFlagRegression(false);
double lToleranceDiffValue(0); double lToleranceDiffValue(0);
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
// //
// OTB includes (sorted by alphabetic order) // OTB includes (sorted by alphabetic order)
#include "otbConfigurationManager.h"
// //
// Monteverdi includes (sorted by alphabetic order) // Monteverdi includes (sorted by alphabetic order)
...@@ -70,6 +71,8 @@ main( int argc, char* argv[] ) ...@@ -70,6 +71,8 @@ main( int argc, char* argv[] )
{ {
QApplication qtApp( argc, argv ); QApplication qtApp( argc, argv );
otb::ConfigurationManager::InitOpenMPThreads();
// //
// 0. Splash-screen. // 0. Splash-screen.
#if !defined( OTB_DEBUG ) #if !defined( OTB_DEBUG )
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
// //
// OTB includes (sorted by alphabetic order) // OTB includes (sorted by alphabetic order)
#include "otbConfigurationManager.h"
// //
// Monteverdi includes (sorted by alphabetic order) // Monteverdi includes (sorted by alphabetic order)
...@@ -97,6 +98,8 @@ main( int argc, char * argv[] ) ...@@ -97,6 +98,8 @@ main( int argc, char * argv[] )
{ {
QApplication qtApp( argc, argv ); QApplication qtApp( argc, argv );
otb::ConfigurationManager::InitOpenMPThreads();
// //
// 0. Splash-screen. // 0. Splash-screen.
#if USE_SPLASH_SCREEN #if USE_SPLASH_SCREEN
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "otbWrapperCommandLineLauncher.h" #include "otbWrapperCommandLineLauncher.h"
#include "otbConfigurationManager.h"
#include "otb_tinyxml.h" #include "otb_tinyxml.h"
#include <vector> #include <vector>
...@@ -267,6 +268,8 @@ int main(int argc, char* argv[]) ...@@ -267,6 +268,8 @@ int main(int argc, char* argv[])
otb::MPIConfig::Instance()->Init(argc,argv); otb::MPIConfig::Instance()->Init(argc,argv);
#endif #endif
otb::ConfigurationManager::InitOpenMPThreads();
if (argc < 2) if (argc < 2)
{ {
ShowUsage(argv); ShowUsage(argv);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
*/ */
#include <QtWidgets> #include <QtWidgets>
#include "otbConfigurationManager.h"
#include "otbWrapperApplicationRegistry.h" #include "otbWrapperApplicationRegistry.h"
#include "otbWrapperQtWidgetView.h" #include "otbWrapperQtWidgetView.h"
#include "otbWrapperQtWidgetSimpleProgressReport.h" #include "otbWrapperQtWidgetSimpleProgressReport.h"
...@@ -43,6 +44,8 @@ int main(int argc, char* argv[]) ...@@ -43,6 +44,8 @@ int main(int argc, char* argv[])
//////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////*/
QtApplication qtApp(argc, argv); QtApplication qtApp(argc, argv);
otb::ConfigurationManager::InitOpenMPThreads();
if (argc < 2) if (argc < 2)
{ {
std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl; std::cerr << "Usage : " << argv[0] << " module_name [module_path]" << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment