20#include <boost/algorithm/string/split.hpp>
22#include <nexus/NeXusFile.hpp>
24#include <Poco/ActiveResult.h>
32#if __has_include("tbb/tbb_stddef.h")
33#include "tbb/tbb_stddef.h"
34#if TBB_INTERFACE_VERSION_MAJOR < 11
35#include "tbb/task_scheduler_init.h"
38#define TBB_HAS_GLOBAL_CONTROL
39#include "tbb/global_control.h"
42#define TBB_HAS_GLOBAL_CONTROL
43#include "tbb/global_control.h"
56#include <boost/mpi.hpp>
60#ifdef TBB_HAS_GLOBAL_CONTROL
61std::unique_ptr<tbb::global_control> m_globalTbbControl;
63thread_local std::unique_ptr<tbb::task_scheduler_init> m_globalTbbControl;
70using Kernel::LibraryManagerImpl;
75Kernel::Logger
g_log(
"FrameworkManager");
77const char *PLUGINS_DIR_KEY =
"framework.plugins.directory";
79const char *PLUGINS_EXCLUDE_KEY =
"framework.plugins.exclude";
96void backtraceToStream(std::ostream &os) {
97 void *trace_elems[32];
98 int trace_elem_count(backtrace(trace_elems, 32));
99 char **stack_syms(backtrace_symbols(trace_elems, trace_elem_count));
100 for (
int i = 0; i < trace_elem_count; ++i) {
101 os <<
' ' << stack_syms[i] <<
'\n';
111void terminateHandler() {
112 std::cerr <<
"\n********* UNHANDLED EXCEPTION *********\n";
114 std::rethrow_exception(std::current_exception());
115 }
catch (
const std::exception &exc) {
116 std::cerr <<
" what(): " << exc.what() <<
"\n\n";
118 std::cerr <<
" what(): Unknown exception type. No more information "
121 std::cerr <<
"Backtrace:\n";
122 backtraceToStream(std::cerr);
131 : m_mpi_environment(argc, argv)
135 std::set_terminate(terminateHandler);
137 setGlobalNumericLocaleToC();
142 WSAStartup(MAKEWORD(2, 2), &wsaData);
145#if defined(_MSC_VER) && _MSC_VER < 1900
149 _set_output_format(_TWO_DIGIT_EXPONENT);
155 disableNexusOutput();
156 setNumOMPThreadsToConfigValue();
159 g_log.
notice() <<
"This MPI process is rank: " << boost::mpi::communicator().rank() <<
'\n';
162 g_log.
debug() <<
"FrameworkManager created.\n";
164 asynchronousStartupTasks();
178 if (maxCores.get_value_or(0) > 0) {
188 g_log.
debug() <<
"Setting maximum number of threads to " << nthreads <<
"\n";
190 if (m_globalTbbControl) {
191 m_globalTbbControl.reset();
194#ifdef TBB_HAS_GLOBAL_CONTROL
195 m_globalTbbControl = std::make_unique<tbb::global_control>(tbb::global_control::max_allowed_parallelism, nthreads);
197 m_globalTbbControl = std::make_unique<tbb::task_scheduler_init>(nthreads);
222 m_globalTbbControl.reset();
256 if (
count % 2 == 1) {
257 throw std::runtime_error(
"Must have an even number of parameter/value string arguments");
263 if (!alg->isInitialized())
264 throw std::runtime_error(algorithmName +
" was not initialized.");
267 va_start(Params,
count);
268 for (
int i = 0; i <
count; i += 2) {
269 std::string paramName = va_arg(Params,
const char *);
270 std::string paramValue = va_arg(Params,
const char *);
271 alg->setPropertyValue(paramName, paramValue);
306 std::shared_ptr<Workspace> ws_sptr;
314 std::shared_ptr<WorkspaceGroup> ws_grpsptr = std::dynamic_pointer_cast<WorkspaceGroup>(ws_sptr);
328 g_log.
error() <<
"Workspace " << wsName <<
" could not be found.\n";
342 const auto pluginDir = cfgSvc.getString(locationKey);
343 if (pluginDir.length() > 0) {
344 std::vector<std::string> excludes;
345 const auto excludeStr = cfgSvc.getString(excludeKey);
346 boost::split(excludes, excludeStr, boost::is_any_of(
";"));
347 g_log.
debug(
"Loading libraries from '" + pluginDir +
"', excluding '" + excludeStr +
"'");
350 g_log.
debug(
"No library directory found in key \"" + locationKey +
"\"");
366 setlocale(LC_NUMERIC,
"C");
376 if (instrumentUpdates.get_value_or(
false)) {
380 "instrument definitions.\n";
384 if (newVersionCheck.get_value_or(
false)) {
395 auto interval = configSvc.getValue<
int>(
"Usage.BufferCheckInterval");
397 if (interval.get_value_or(0) > 0) {
398 usageSvc.setInterval(interval.get());
400 auto enabled = configSvc.getValue<
bool>(
"usagereports.enabled");
401 usageSvc.setEnabled(enabled.get_value_or(
false));
402 usageSvc.registerStartup();
409 algDownloadInstrument->setAlgStartupLogging(
false);
410 algDownloadInstrument->executeAsync();
412 g_log.
debug() <<
"DowndloadInstrument algorithm is not available - cannot "
413 "update instrument definitions.\n";
421 algCheckVersion->setAlgStartupLogging(
false);
422 algCheckVersion->executeAsync();
424 g_log.
debug() <<
"CheckMantidVersion algorithm is not available - cannot "
425 "check if a newer version is available.\n";
#define PARALLEL_SET_NUM_THREADS(MaxCores)
#define PARALLEL_GET_MAX_THREADS
Workspace * getWorkspace(const std::string &wsName)
Returns a shared pointer to the workspace requested.
std::shared_ptr< IAlgorithm > exec(const std::string &algorithmName, int count,...)
Creates an algorithm and runs it, with variadic arguments.
void updateInstrumentDefinitions()
Update instrument definitions from github.
void clearPropertyManagers()
Clear memory associated with the PropertyManagers.
void loadPlugins()
Load framework plugins.
void setNumOMPThreads(const int nthreads)
Set the number of OpenMP threads to the given value.
void asynchronousStartupTasks()
Starts asynchronous tasks that are done as part of Start-up.
void loadPluginsUsingKey(const std::string &locationKey, const std::string &excludeKey)
Load a set of plugins using a key from the ConfigService.
void clearInstruments()
Clear memory associated with the IDS.
FrameworkManagerImpl()
Private Constructor.
void disableNexusOutput()
Silence NeXus output.
void clearData()
Clear memory associated with the ADS.
void shutdown()
shuts down and performs clean up tasks
void setGlobalNumericLocaleToC()
Set up the global locale.
int getNumOMPThreads() const
Returns the number of OpenMP threads that will be used.
void checkIfNewerVersionIsAvailable()
check if a newer version of Mantid is available
void setNumOMPThreadsToConfigValue()
Set the number of OpenMP threads to use based on the config value.
void clear()
Clears all memory associated with the AlgorithmManager, ADS & IDS.
bool deleteWorkspace(const std::string &wsName)
Deletes a workspace from the framework.
void clearAlgorithms()
Clear memory associated with the AlgorithmManager.
void setupUsageReporting()
Setup Usage Reporting if enabled.
Base Workspace Abstract Class.
Exception for when an item is not found in a collection.
const char * what() const noexcept override
Writes out the range and limits.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Kernel::Logger g_log("ExperimentInfo")
static logger object
void NexusErrorFunction(void *, char *)
This is a function called every time NeXuS raises an error.
MANTID_KERNEL_DLL void initAllocatorOptions()
Initialize platform-dependent options for memory management.
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Mantid::Kernel::SingletonHolder< LibraryManagerImpl > LibraryManager
Mantid::Kernel::SingletonHolder< UsageServiceImpl > UsageService
Helper class which provides the Collimation Length for SANS instruments.
MANTID_KERNEL_DLL std::string welcomeMessage()
Returns the welcome message for Mantid.