Skip to content

Commit

Permalink
[OMSICpp] improved error handling for zeromq simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
niklwors authored and adrpo committed Nov 2, 2020
1 parent be39574 commit 544d2c3
Show file tree
Hide file tree
Showing 12 changed files with 611 additions and 212 deletions.
Expand Up @@ -26,7 +26,21 @@ ELSE()
ENDIF(IS_MINGW32)
MESSAGE(STATUS "Boost root for omc - zeromq:")
MESSAGE(STATUS ${BOOST_ROOT})
FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options)
FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options )
IF(NOT(COMPILER_SUPPORTS_CXX11))
FIND_PACKAGE(Threads)
IF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ADD_DEFINITIONS(-DUSE_THREAD)
MESSAGE(STATUS "Using boost thread for omc zeromq")
ELSE(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
MESSAGE(STATUS "Boost thread for omc zeromq disabled")
ENDIF(Boost_THREAD_FOUND AND Boost_ATOMIC_FOUND)
ELSE(NOT(COMPILER_SUPPORTS_CXX11))
MESSAGE(STATUS "Boost thread disabled for omc zeromq because of available C++11 support")
ENDIF(NOT(COMPILER_SUPPORTS_CXX11))



MESSAGE(STATUS "using boost include for omc - zeromq: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "Boost Libraries for omc - zeromq:")
MESSAGE(STATUS ${Boost_LIBRARIES})
Expand Down
@@ -0,0 +1,15 @@
#include "zhelpers.hpp"
#include <string>
#include <vector>
#include <thread>
#include <memory>
#include <functional>
#include <iostream>
#include <string>
#include "OMC.h"
#define GC_THREADS
#include "gc.h"

using std::string;
static std::exception_ptr globalSimulationExceptionPtr = nullptr;
static std::exception_ptr globalZeroMQTaskExceptionPtr = nullptr;
@@ -0,0 +1,179 @@
#pragma once
/** @addtogroup core
*
* @{
*/

#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <numeric>
#include <functional>
#include <iostream>
#include <iterator>

/*Namespaces*/
using std::abs;
using std::ios;
using std::endl;
using std::cout;
using std::cerr;
using std::ostream_iterator;
using std::map;
using std::pair;
using std::make_pair;
using std::max;
using std::min;
using std::string;
using std::ostream;
using std::ostringstream;
using std::stringstream;
using std::vector;
using std::deque;
using std::copy;
using std::exception;
using std::runtime_error;



#if !defined(USE_CPP_03) && !defined(__vxworks)
#include <array>
#include <tuple>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
using namespace std::chrono;
#define USE_CHRONO
#if defined(USE_THREAD)
#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>
using std::thread;
using std::atomic;
using std::mutex;
using std::memory_order_release;
using std::memory_order_relaxed;
using std::condition_variable;
using std::unique_lock;
#endif //USE_THREAD

// builtin range based for loop
#define FOREACH(element, range) for(element : range)

// builtin list initializers
#define LIST_OF {
#define LIST_SEP ,
#define LIST_END }
#define MAP_LIST_OF {{
#define MAP_LIST_SEP },{
#define MAP_LIST_END }}
#define TUPLE_LIST_OF {std::make_tuple(
#define TUPLE_LIST_SEP ),std::make_tuple(
#define TUPLE_LIST_END )}

/** namespace for generated code to avoid name clashes */
namespace omcpp
{
using std::ref;
using std::trunc;
using std::to_string;
}

using std::bind;
using std::function;
using std::make_tuple;
using std::array;
using std::isfinite;
using std::minmax_element;
using std::get;
using std::tuple;
using std::unordered_map;
using std::unordered_set;
using std::shared_ptr;
using std::weak_ptr;
using std::dynamic_pointer_cast;
using std::to_string;
#else
#if defined(_MSC_VER)
#include <tuple>
using std::get;
using std::tuple;
using std::make_tuple;
using std::minmax_element;
#else
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/minmax_element.hpp>
using boost::get;
using boost::tuple;
using boost::make_tuple;
using boost::minmax_element;
#endif
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/array.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/math/special_functions/trunc.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <boost/ref.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

#if defined(USE_THREAD)
#include <boost/thread.hpp>
#include <boost/atomic.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
using boost::bind;
using boost::function;
using boost::thread;
using boost::atomic;
using boost::mutex;
using boost::memory_order_release;
using boost::memory_order_relaxed;
using boost::condition_variable;
using boost::unique_lock;
#endif //USE_THREAD

// boost range based for loop
#define FOREACH BOOST_FOREACH

// boost list initializers
#define LIST_OF boost::assign::list_of(
#define LIST_SEP )(
#define LIST_END )
#define MAP_LIST_OF boost::assign::map_list_of(
#define MAP_LIST_SEP )(
#define MAP_LIST_END )
#define TUPLE_LIST_OF boost::assign::tuple_list_of(
#define TUPLE_LIST_SEP )(
#define TUPLE_LIST_END )

/** namespace for generated code to avoid name clashes */
namespace omcpp {
using boost::ref;
using boost::math::trunc;
template <typename T>
std::string to_string(T val) {
return boost::lexical_cast<std::string>(val);
}
}
using boost::array;
using boost::math::isfinite;
using boost::unordered_map;
using boost::unordered_set;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
using omcpp::to_string;
using namespace boost::lambda;
#endif //!USE_CPP_03


/** @} */ // end of group1
@@ -0,0 +1,97 @@
/** @addtogroup core
*
* @{
*/

typedef double modelica_real;
typedef int modelica_integer;
typedef bool modelica_boolean;
typedef bool edge_rettype;
typedef bool sample_rettype;
typedef double cos_rettype;
typedef double cosh_rettype;
typedef double sin_rettype;
typedef double sinh_rettype;
typedef double log_rettype;
typedef double tan_rettype;
typedef double atan_rettype;
typedef double tanh_rettype;
typedef double exp_rettype;
typedef double sqrt_rettype;
typedef double abs_rettype;
typedef double max_rettype;
typedef double min_rettype;
typedef double arctan_rettype;
typedef double floorRetType;
typedef double asinRetType;
typedef double tan_rettype;
typedef double tanhRetType;
typedef double acosRetType;
typedef double logRetType;
typedef double coshRetType;

#ifndef FORCE_INLINE
#if defined(_MSC_VER)
#define FORCE_INLINE __forceinline
#else
#define FORCE_INLINE __attribute__((always_inline)) inline
#endif
#endif

#ifndef PREFETCH
#if defined(_MSC_VER)
#define PREFETCH(add, rw, locality)
#else
#define PREFETCH(add, rw, locality) __builtin_prefetch(add, rw, locality)
#endif
#endif

#ifndef VAR_ALIGN_PRE
#ifdef __GNUC__
#define VAR_ALIGN_PRE
#define VAR_ALIGN_POST __attribute__((aligned(0x40)))
#elif defined _MSC_VER
#define VAR_ALIGN_PRE __declspec(align(64))
#define VAR_ALIGN_POST
#else
#define VAR_ALIGN_PRE
#define VAR_ALIGN_POST
#endif
#endif


#ifndef BOOST_THREAD_USE_DLL
#define BOOST_THREAD_USE_DLL
#endif
#ifndef BOOST_STATIC_LINKING
#ifndef BOOST_ALL_DYN_LINK
#define BOOST_ALL_DYN_LINK
#endif
#endif


// Visual C++ 2015 by default does not link the CRT if the entry point is overriden. Force linking. Macros according to
// "MSDN — Predefined Macros"; library names according to "Visual C++ Team Blog — Introducing the Universal CRT".
#if _MSC_VER >= 1900
# if _DEBUG
# if _DLL
# pragma comment(lib, "vcruntimed")
# pragma comment(lib, "ucrtd")
# else
# pragma comment(lib, "libvcruntimed")
# pragma comment(lib, "libucrtd")
# endif
# else
# if _DLL
# pragma comment(lib, "vcruntime")
# pragma comment(lib, "ucrt")
# else
# pragma comment(lib, "libvcruntime")
# pragma comment(lib, "libucrt")
# endif
# endif
#endif



/** @} */ // end of core
@@ -1,5 +1,6 @@
#include <zmq.hpp>
#include <string>

#define BOOST_SPIRIT_THREADSAFE
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>

Expand All @@ -16,10 +17,13 @@ class omcZeromqTask {

protected:
void startSimulation(pt::ptree& node);
int simulateModel(OMCData* omc, string model_name, pt::ptree& node, string tmp_dir, string& results_msg, string& error_msg);
int loadMSL(OMCData* omc);
bool simulateModel(OMCData* omc, string model_name, pt::ptree& node, string tmp_dir, string& results_msg, string& error_msg);
int setZeroMQID(OMCData* omc, std::string jobId, string& error_msg);
int setModelParameter(OMCData* omc, string model_name, pt::ptree& node, string& error_msg);
bool setModelParameter(OMCData* omc, string model_name, pt::ptree& node, string& error_msg);
bool checkStatus(OMCData* omc,int status,string& error_msg,string& command_result_msg);

int loadMSL(OMCData* omc);

private:
zmq::context_t ctx_;
zmq::socket_t publisher_;
Expand Down

0 comments on commit 544d2c3

Please sign in to comment.