Skip to content

Commit

Permalink
Update ParModAuto sources.
Browse files Browse the repository at this point in the history
  - There are so many changes here.
  - Capability for monitoring and rescheduling added.
  - Use JSON instad of XML
  - updated compliation seetings. e.g. use GC_THREADS from the
    compilation command instead of defining it in the files.

  - many other fixes and changes.
  • Loading branch information
mahge committed Oct 29, 2020
1 parent a894bea commit 4c135b3
Show file tree
Hide file tree
Showing 17 changed files with 1,279 additions and 721 deletions.
8 changes: 3 additions & 5 deletions OMCompiler/SimulationRuntime/ParModelica/auto/Makefile.common
Expand Up @@ -8,8 +8,6 @@ om_pm_equation.cpp \
pm_utility.cpp \
om_pm_interface.cpp \
om_pm_model.cpp
# ParModelicaTaskGrapExt_rml.cpp
# ParModelicaTaskGrapExt_omc.cpp \

HDRS = *.hpp *.inl
OBJS = $(SRCS:.cpp=.o)
Expand All @@ -24,7 +22,7 @@ libParModelicaAuto.a: $(OBJS)
$(AR_) $@ $(OBJS)

.cpp.o: $(DPFILE)
$(CC) $(CPPFLAGS) $(INCDIRS) -c $<
$(CXX) $(CPPFLAGS) $(INCDIRS) -c $<

test: test_task_graph.cpp libParModelicaAuto.a
$(CXX) $(CPPFLAGS) -I. $(INCDIRS) test_task_graph.cpp -o gen_graph$(EXEEXT) libParModelicaAuto.a -L$(TBB_LIB) -ltbb
Expand All @@ -34,6 +32,6 @@ clean :
touch $(DPFILE)

$(DPFILE) depend : $(HDRS) $(SRCS)
$(CC) $(DPFLAGS) $(CPPFLAGS) $(SRCS) > $(DPFILE)
$(CXX) $(DPFLAGS) $(CPPFLAGS) $(INCDIRS) $(SRCS) > $(DPFILE)

include $(DPFILE)
include $(DPFILE)
25 changes: 22 additions & 3 deletions OMCompiler/SimulationRuntime/ParModelica/auto/Makefile.in
@@ -1,26 +1,45 @@
TOP_BUILDDIR = @OMBUILDDIR@
HOST_SHORT = @host_short@

OMCOMPILER_ROOT = $(realpath ../../../)

OPENMODELICA_INC=$(TOP_BUILDDIR)/include/omc/c/
PARMODELICAAUTO_INC=$(OPENMODELICA_INC)/ParModelica/auto/
OPENMODELICA_LIB=$(TOP_BUILDDIR)/lib/$(HOST_SHORT)/omc
OPENMODELICA_BIN=$(TOP_BUILDDIR)/bin/

BOOST_HOME = @BOOSTHOME@
INCDIRS = -I"../../c" -I$(BOOST_HOME) -I"../pugixml-1.2/src/"
INCDIRS = -I"../../c" -I$(BOOST_HOME) -I$(OMCOMPILER_ROOT)/3rdParty/tbb/include -I$(OMCOMPILER_ROOT)/3rdParty/gc/include



CC=@CC@
CXX=@CXX@
CFLAGS=@CFLAGS@ $(INCDIRS)
CPPFLAGS= -O3 -Wall -fPIC
CFLAGS=@CFLAGS@
CPPFLAGS= @CFLAGS@ -Wall -DGC_THREADS

OS_SRCS = pm_posix_timer.cpp

EXEEXT=
DLLEXT=.so

ifeq ($(USE_LEVEL_SCHEDULER), 1)
CPPFLAGS += -DUSE_LEVEL_SCHEDULER
$(info ************ COMPILING FOR LEVEL SCHEDULER ************)
else ifeq ($(USE_FLOW_SCHEDULER), 1)
$(info ************ COMPILING FOR FLOW SCHEDULER ************)
CPPFLAGS += -DUSE_FLOW_SCHEDULER
endif

ifeq ($(NUM_THREADS), )
$(info ************ NUM THREADS NOT SET ************)
$(info ************ NUM THREADS NOT SET ************)
$(info ************ NUM THREADS NOT SET ************)
$(info ************ NUM THREADS NOT SET ************)
else
CPPFLAGS += -DNUM_THREADS=$(NUM_THREADS)
endif

all: transfer

transfer: libParModelicaAuto.a
Expand Down
34 changes: 26 additions & 8 deletions OMCompiler/SimulationRuntime/ParModelica/auto/Makefile.omdev.mingw
@@ -1,25 +1,43 @@
TOP_BUILDDIR = ../../../build/
OMBUILDDIR = $(realpath ../../../../)/build
OMCOMPILER_ROOT = $(realpath ../../../)

OPENMODELICA_INC=$(TOP_BUILDDIR)/include/omc/c/
OPENMODELICA_INC=$(OMBUILDDIR)/include/omc/c/
PARMODELICAAUTO_INC=$(OPENMODELICA_INC)/ParModelica/auto/
OPENMODELICA_LIB=$(TOP_BUILDDIR)/lib/omc/
OPENMODELICA_BIN=$(TOP_BUILDDIR)/bin/
OPENMODELICA_LIB=$(OMBUILDDIR)/lib/omc/
OPENMODELICA_BIN=$(OMBUILDDIR)/bin/

TBB_INC = $(OMC_TBB_INC)
TBB_INC = ../tbb/include
TBB_LIB = $(OMC_TBB_LIB)
BOOST_HOME = $(OMDEV)/lib/3rdParty/boost-1_49
INCDIRS = -I"../../c" -I$(TBB_INC) -I$(BOOST_HOME) -I"../pugixml-1.2/src/"
INCDIRS = -I"../../c" -I$(BOOST_HOME) -I$(OMCOMPILER_ROOT)/3rdParty/tbb/include -I$(OMCOMPILER_ROOT)/3rdParty/gc/include

CC=gcc
CXX=g++
CFLAGS= -O3 -Wall
CPPFLAGS= -O3 -Wall
CFLAGS= -O3 -Wall
CPPFLAGS= -std=c++11 -O3 -Wall -DGC_THREADS


OS_SRCS = pm_win_timer.cpp

EXEEXT=.exe
DLLEXT=.dll


ifeq ($(USE_LEVEL_SCHEDULER), 1)
CPPFLAGS += -DUSE_LEVEL_SCHEDULER
$(info ************ COMPILING FOR LEVEL SCHEDULER ************)
else
$(info ************ COMPILING FOR FLOW SCHEDULER ************)
CPPFLAGS += -DUSE_FLOW_SCHEDULER
endif

ifeq ($(NUM_THREADS), )
$(info ************ NUM THREADS NOT SET. SETTIN TO 4 ************)
CPPFLAGS += -DNUM_THREADS=4
else
CPPFLAGS += -DNUM_THREADS=$(NUM_THREADS)
endif

all: transfer

transfer: libParModelicaAuto.a
Expand Down
134 changes: 96 additions & 38 deletions OMCompiler/SimulationRuntime/ParModelica/auto/om_pm_interface.cpp
Expand Up @@ -46,69 +46,127 @@ extern "C" {
using namespace openmodelica::parmodelica;
typedef Equation::FunctionType FunctionType;

OMModel pm_om_model;
PMTimer seq_ode_timer;

void PM_Model_init(const char* model_name, DATA* data, threadData_t* threadData, FunctionType* ode_system) {
pm_om_model.initialize(model_name, data, threadData, ode_system);
}

void PM_functionInitialEquations(int size, DATA* data, threadData_t* threadData, FunctionType* functionInitialEquations_systems) {
void* PM_Model_create(const char* model_name, DATA* data, threadData_t* threadData) {
OMModel* pm_om_model = new OMModel(model_name);
pm_om_model->data = data;
pm_om_model->threadData = threadData;
return pm_om_model;
}

// pm_om_model.ini_system_funcs = functionInitialEquations_systems;
// pm_om_model.INI_scheduler.execute();
pm_om_model.INI_scheduler.execution_timer.start_timer();
for(int i = 0; i < size; ++i)
functionInitialEquations_systems[i](data, threadData);
pm_om_model.INI_scheduler.execution_timer.stop_timer();
void PM_Model_load_ODE_system(void* v_model, FunctionType* ode_system_funcs) {

OMModel& model = *(static_cast<OMModel*>(v_model));
model.ode_system_funcs = ode_system_funcs;
model.load_ODE_system();
}


void PM_functionDAE(int size, DATA* data, threadData_t* threadData, FunctionType* functionDAE_systems) {
// void PM_functionInitialEquations(int size, FunctionType* functionInitialEquations_systems) {

// pm_om_model.dae_system_funcs = functionDAE_systems;
// pm_om_model.DAE_scheduler.execute();
// // pm_om_model.ini_system_funcs = functionInitialEquations_systems;
// // pm_om_model.INI_scheduler.execute();
// pm_om_model.INI_scheduler.execution_timer.start_timer();
// for(int i = 0; i < size; ++i)
// functionInitialEquations_systems[i](data, threadData);
// pm_om_model.INI_scheduler.execution_timer.stop_timer();

pm_om_model.DAE_scheduler.execution_timer.start_timer();
for(int i = 0; i < size; ++i)
functionDAE_systems[i](data, threadData);
pm_om_model.DAE_scheduler.execution_timer.stop_timer();
// }

}

// void PM_functionDAE(int size, FunctionType* functionDAE_systems) {

// // pm_om_model.dae_system_funcs = functionDAE_systems;
// // pm_om_model.DAE_scheduler.execute();

// pm_om_model.DAE_scheduler.execution_timer.start_timer();
// for(int i = 0; i < size; ++i)
// functionDAE_systems[i](data, threadData);
// pm_om_model.DAE_scheduler.execution_timer.stop_timer();

// }

void PM_functionODE(int size, DATA* data, threadData_t* threadData, FunctionType* functionODE_systems) {

pm_om_model.ODE_scheduler.execute();
void PM_evaluate_ODE_system(void* v_model) {

// pm_om_model.ODE_scheduler.execution_timer.start_timer();
OMModel& model = *(static_cast<OMModel*>(v_model));
model.ODE_scheduler.execute();

// pm_om_model.ODE_scheduler.execution_timer.start_timer();
// for(int i = 0; i < size; ++i)
// functionODE_systems[i](data, threadData);
// pm_om_model.ODE_scheduler.execution_timer.stop_timer();

// pm_om_model.ODE_scheduler.execution_timer.stop_timer();

// double step_cost = pm_om_model.ODE_scheduler.execution_timer.get_elapsed_time();
// std::cout << step_cost << std::endl;
// pm_om_model.ODE_scheduler.execution_timer.reset_timer();
}

void PM_functionAlg(int size, DATA* data, threadData_t* threadData, FunctionType* functionAlg_systems) {
// void PM_functionAlg(int size, DATA* data, threadData_t* threadData, FunctionType* functionAlg_systems) {

pm_om_model.total_alg_time.start_timer();
// pm_om_model.ALG_scheduler.execution_timer.start_timer();

for(int i = 0; i < size; ++i)
functionAlg_systems[i](data, threadData);
// for(int i = 0; i < size; ++i)
// functionAlg_systems[i](data, threadData);

// pm_om_model.ALG_scheduler.execution_timer.start_timer();

// }

void seq_ode_timer_start() {
seq_ode_timer.start_timer();
}

pm_om_model.total_alg_time.stop_timer();
void seq_ode_timer_stop() {
seq_ode_timer.stop_timer();
}

void seq_ode_timer_reset() {
seq_ode_timer.reset_timer();
}

void seq_ode_timer_get_elapsed_time2() {
// return seq_ode_timer.get_elapsed_time();
std::cerr << seq_ode_timer.get_elapsed_time();
}

double seq_ode_timer_get_elapsed_time() {
return seq_ode_timer.get_elapsed_time();
}

void dump_times() {
utility::log("") << "Total INI: " << pm_om_model.INI_scheduler.execution_timer.get_elapsed_time() << std::endl;
utility::log("") << "Total DAE: " << pm_om_model.DAE_scheduler.execution_timer.get_elapsed_time() << std::endl;
utility::log("") << "Total ODE: " << pm_om_model.ODE_scheduler.execution_timer.get_elapsed_time() << std::endl;
utility::log("") << "Total ODE: " << pm_om_model.ODE_scheduler.clustering_timer.get_elapsed_time() << std::endl;
utility::log("") << "Total ALG: " << pm_om_model.total_alg_time.get_elapsed_time() << std::endl;
void dump_times(void* v_model) {
OMModel& model = *(static_cast<OMModel*>(v_model));

// utility::log("") << "Total INI: " << model.INI_scheduler.execution_timer.get_elapsed_time() << std::endl;
// utility::log("") << "Total DAE: " << model.DAE_scheduler.execution_timer.get_elapsed_time() << std::endl;
// utility::log("") << "Total ALG: " << model.ALG_scheduler.execution_timer.get_elapsed_time() << std::endl;

// double total = 0;
// for(unsigned int i = 0; i < model.ODE_scheduler.parallel_eval_costs.size(); ++i) {
// double c = model.ODE_scheduler.parallel_eval_costs[i];
// total += c;
// utility::log("") << i+1 << ": " << c << " : " << total/(i+1) << std::endl;
// }

// utility::log("") << "Total ODE added: " << total << std::endl;
// std::cout << model.ODE_scheduler.execution_timer.get_elapsed_time() << std::endl;
// std::cout << model.ODE_scheduler.total_evaluations << " : " << model.ODE_scheduler.total_parallel_cost << std::endl;
#ifdef USE_LEVEL_SCHEDULER
utility::log("") << "Using level scheduler" << std::endl;
#else
#ifdef USE_FLOW_SCHEDULER
utility::log("") << "Using flow scheduler" << std::endl;
#else
#error "please specify scheduler. See makefile"
#endif
#endif
utility::log("") << "Nr.of threads " << NUM_THREADS << std::endl;
utility::log("") << "Nr.of ODE evaluations: " << model.ODE_scheduler.total_evaluations << std::endl;
utility::log("") << "Nr.of profiling ODE Evaluations: " << model.ODE_scheduler.sequential_evaluations << std::endl;
// utility::log("") << "Total ODE evaluation time : " << model.ODE_scheduler.total_parallel_cost << std::endl;
utility::log("") << "Total ODE evaluation time : " << model.ODE_scheduler.execution_timer.get_elapsed_time() << std::endl;
utility::log("") << "Avg. ODE evaluation time : " << model.ODE_scheduler.execution_timer.get_elapsed_time()/model.ODE_scheduler.parallel_evaluations << std::endl;
utility::log("") << "Total ODE loading time: " << model.load_system_timer.get_elapsed_time() << std::endl;
utility::log("") << "Total ODE Clustering time: " << model.ODE_scheduler.clustering_timer.get_elapsed_time() << std::endl;
}


Expand Down
28 changes: 21 additions & 7 deletions OMCompiler/SimulationRuntime/ParModelica/auto/om_pm_interface.hpp
Expand Up @@ -39,7 +39,7 @@
Mahder.Gebremedhin@liu.se 2014-02-19
*/

#include <simulation_data.h>
#include "simulation_data.h"


#ifdef __cplusplus
Expand All @@ -48,17 +48,31 @@ extern "C" {

typedef void (*FunctionType)(DATA *, threadData_t*);

void PM_Model_init(const char* , DATA* , threadData_t*, FunctionType*);
void* PM_Model_create(const char* , DATA* , threadData_t*);

void PM_functionInitialEquations(int size, DATA* data, threadData_t* threadData, FunctionType*);
void PM_Model_load_ODE_system(void*, FunctionType*);

void PM_functionDAE(int size, DATA* data, threadData_t* threadData, FunctionType*);
// void PM_functionInitialEquations(int size, DATA* data, threadData_t* threadData, FunctionType*);

void PM_functionODE(int size, DATA* data, threadData_t* threadData, FunctionType*);
// void PM_functionDAE(int size, DATA* data, threadData_t* threadData, FunctionType*);

void PM_functionAlg(int size, DATA* data, threadData_t* threadData, FunctionType*);
void PM_evaluate_ODE_system(void*);

void dump_times();
// void PM_functionAlg(int size, DATA* data, threadData_t* threadData, FunctionType*);


void seq_ode_timer_start();

void seq_ode_timer_stop();

void seq_ode_timer_reset();

void seq_ode_timer_get_elapsed_time2();

double seq_ode_timer_get_elapsed_time();


void dump_times(void*);



Expand Down

0 comments on commit 4c135b3

Please sign in to comment.