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:
*
*/
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:
ConfigurationManager() = delete;
~ConfigurationManager() = delete;
......
......@@ -23,8 +23,13 @@
#include "otbMacro.h"
#include "otbLogger.h"
#include "itkMultiThreader.h"
#include "itksys/SystemTools.hxx"
#ifdef _OPENMP
#include <omp.h>
#endif
#include <cstdlib>
#include <algorithm>
#include <string>
......@@ -99,4 +104,14 @@ itk::LoggerBase::PriorityLevelType ConfigurationManager::GetLoggerLevel()
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 @@
#define otbTestMain_h
#include "otbConfigure.h"
#include "otbConfigurationManager.h"
#include <map>
#include <string>
......@@ -72,6 +73,8 @@ int main(int ac, char* av[])
#ifdef OTB_USE_MPI
otb::MPIConfig::Instance()->Init(ac,av);
#endif
otb::ConfigurationManager::InitOpenMPThreads();
bool lFlagRegression(false);
double lToleranceDiffValue(0);
......
......@@ -44,6 +44,7 @@
//
// OTB includes (sorted by alphabetic order)
#include "otbConfigurationManager.h"
//
// Monteverdi includes (sorted by alphabetic order)
......@@ -70,6 +71,8 @@ main( int argc, char* argv[] )
{
QApplication qtApp( argc, argv );
otb::ConfigurationManager::InitOpenMPThreads();
//
// 0. Splash-screen.
#if !defined( OTB_DEBUG )
......
......@@ -48,6 +48,7 @@
//
// OTB includes (sorted by alphabetic order)
#include "otbConfigurationManager.h"
//
// Monteverdi includes (sorted by alphabetic order)
......@@ -97,6 +98,8 @@ main( int argc, char * argv[] )
{
QApplication qtApp( argc, argv );
otb::ConfigurationManager::InitOpenMPThreads();
//
// 0. Splash-screen.
#if USE_SPLASH_SCREEN
......
......@@ -20,6 +20,7 @@
#include "otbWrapperCommandLineLauncher.h"
#include "otbConfigurationManager.h"
#include "otb_tinyxml.h"
#include <vector>
......@@ -267,6 +268,8 @@ int main(int argc, char* argv[])
otb::MPIConfig::Instance()->Init(argc,argv);
#endif
otb::ConfigurationManager::InitOpenMPThreads();
if (argc < 2)
{
ShowUsage(argv);
......
......@@ -19,6 +19,7 @@
*/
#include <QtWidgets>
#include "otbConfigurationManager.h"
#include "otbWrapperApplicationRegistry.h"
#include "otbWrapperQtWidgetView.h"
#include "otbWrapperQtWidgetSimpleProgressReport.h"
......@@ -43,6 +44,8 @@ int main(int argc, char* argv[])
//////////////////////////////////////////////////////////////////*/
QtApplication qtApp(argc, argv);
otb::ConfigurationManager::InitOpenMPThreads();
if (argc < 2)
{
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