This PR ports NOMAD4 to MS Windows. A large number of files are touched, but there are only a couple of themes of recurring changes, several of which are also relevant on Linux/Mac. I've put them in one PR as they are all needed to work on Windows, but if you prefer to have the general fixes separately, I can split them up.
Needed on all platforms:
OpenMP fixes: in creation of singletons in OutputDirectToFile.cpp, OutputQueue.cpp, and CacheSet.cpp, the OMP lock is set before it is initialized (in the case of the first, it is actually never initialized). Further, the assignment of the unique_ptr is not fenced and in the case of CacheSet.cpp, the thrown exception will leave the lock in a locked state. In Algorithm.cpp, instances init/destroy the class-static lock, so if two instances co-exist, they both init/destroy it twice, and can also set a destroyed lock. I've replaced this with critical sections, under the assumption that performance wasn't the main reason for having a static lock here.
Offload order fix: Evaluator::removeTmpFiles() is called in EvaluatorControl.cpp (destroy) on program shutdown, but that relies on a static variable in Evaluator.cpp (Evaluator::_tmpFiles). The destruction order of statics is not guaranteed across translation units, and as it happens on Windows, removeTmpFiles() is called after Evaluator::_tmpFiles has been destroyed. By putting the destruction in Evaluator.cpp, order is guaranteed (this assumes that destroy is only called on application shutdown).
Missing include files: several standard headers were missing for use of standard functions.
Windows-specific
CMakeLists.txt updates to build on Windows, including the usual suspect of dllimport, dllexport, but also setting the SUFFIX of the library examples to "", to prevent ".exe.exe". The function symbols are automatically exported using a standard cmake macro (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS). Pre-processor macro's in the source code are used so export data members, as appropriate for each of the Nomad libraries (since two of them both import and export, each needed their own macro to disambiguate).
New files nomad_platform.hpp and MicroSleep.hpp. The former to capture platform differences in macro's, the latter has an implementation of usleep using standard C++.
Macro-replacements of __attribute__ (doesn't exist on Windows) and __PRETTY_FUNCTION__ (named differently).
Windows-specific POSIX name fixes (underscores).
Explicit type casts to silence warnings (should have shown up on other platforms as well).
This PR ports NOMAD4 to MS Windows. A large number of files are touched, but there are only a couple of themes of recurring changes, several of which are also relevant on Linux/Mac. I've put them in one PR as they are all needed to work on Windows, but if you prefer to have the general fixes separately, I can split them up.
Needed on all platforms:
OutputDirectToFile.cpp
,OutputQueue.cpp
, andCacheSet.cpp
, the OMP lock is set before it is initialized (in the case of the first, it is actually never initialized). Further, the assignment of theunique_ptr
is not fenced and in the case ofCacheSet.cpp
, the thrown exception will leave the lock in a locked state. InAlgorithm.cpp
, instances init/destroy the class-static lock, so if two instances co-exist, they both init/destroy it twice, and can also set a destroyed lock. I've replaced this withcritical
sections, under the assumption that performance wasn't the main reason for having a static lock here.Evaluator::removeTmpFiles()
is called inEvaluatorControl.cpp
(destroy
) on program shutdown, but that relies on a static variable inEvaluator.cpp
(Evaluator::_tmpFiles
). The destruction order of statics is not guaranteed across translation units, and as it happens on Windows,removeTmpFiles()
is called afterEvaluator::_tmpFiles
has been destroyed. By putting the destruction inEvaluator.cpp
, order is guaranteed (this assumes thatdestroy
is only called on application shutdown).Windows-specific
CMakeLists.txt
updates to build on Windows, including the usual suspect ofdllimport
,dllexport
, but also setting theSUFFIX
of the library examples to""
, to prevent ".exe.exe". The function symbols are automatically exported using a standard cmake macro (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
). Pre-processor macro's in the source code are used so export data members, as appropriate for each of the Nomad libraries (since two of them both import and export, each needed their own macro to disambiguate).nomad_platform.hpp
andMicroSleep.hpp
. The former to capture platform differences in macro's, the latter has an implementation ofusleep
using standard C++.__attribute__
(doesn't exist on Windows) and__PRETTY_FUNCTION__
(named differently).