Skip to content

Commit

Permalink
+ Let the scheduler implement it's own executor.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19343 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
mahge committed Feb 27, 2014
1 parent 39220e0 commit 79453ce
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 216 deletions.
20 changes: 16 additions & 4 deletions SimulationRuntime/ParModelica/auto/Makefile.common
Expand Up @@ -9,25 +9,37 @@ OPENMODELICA_BIN=$(TOP_BUILDDIR)/bin/
COPY=cp -rp
AR_=ar -rcs

SRCS = \
SRCS = $(OS_SRCS) \
om_pm_equation.cpp \
pm_utility.cpp \
om_pm_interface.cpp \
om_pm_model.cpp \
pm_win_timer.cpp
om_pm_model.cpp
# ParModelicaTaskGrapExt_rml.cpp
# ParModelicaTaskGrapExt_omc.cpp \

HDRS = *.hpp *.inl
OBJS = $(SRCS:.cpp=.o)
DPFILE = Makefile.dependencies

.PHONY : libom_pm_autort clean
DPFLAGS = -MM

.PHONY : clean

libom_pm_autort.a: $(OBJS)
@rm -f $@
$(AR_) $@ $(OBJS)

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

test: test_task_graph.cpp transfer
$(CXX) $(CPPFLAGS) -I. test_task_graph.cpp -o gen_graph$(EXEEXT) libom_pm_autort.a

clean :
rm -f *.o *.a
touch $(DPFILE)

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

include $(DPFILE)
25 changes: 25 additions & 0 deletions SimulationRuntime/ParModelica/auto/Makefile.in
@@ -0,0 +1,25 @@
BOOST_HOME = @BOOSTHOME@
INCDIRS = -I"../../c" -I$(BOOST_HOME) -I"../pugixml-1.2/src/"

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

OS_SRCS = pm_posix_timer.cpp

EXEEXT=
DLLEXT=.so

all: transfer

transfer: libom_pm_autort.a
$(COPY) libom_pm_autort.a $(OPENMODELICA_LIB)
mkdir -p $(PARMODELICAAUTO_INC)
$(COPY) om_pm_interface.hpp $(PARMODELICAAUTO_INC)
$(COPY) om_pm_model.hpp $(PARMODELICAAUTO_INC)

Makefile: Makefile.in
(cd ../../../ && ./config.status)

include Makefile.common
26 changes: 9 additions & 17 deletions SimulationRuntime/ParModelica/auto/om_pm_interface.cpp
Expand Up @@ -47,54 +47,46 @@ using namespace openmodelica::parmodelica;

OMModel pm_om_model;

void PM_Model_init(const char* model_name, DATA* data) {
void PM_Model_init(const char* model_name, void* data) {

pm_om_model.model_name = model_name;
pm_om_model.data = data;

pm_om_model.initialize();
}

void PM_functionInitialEquations(int size, DATA* data, functionXXX_system* functionInitialEquations_systems) {
void PM_functionInitialEquations(int size, void* data, om_function_system* functionInitialEquations_systems) {

pm_om_model.ini_system_funcs = functionInitialEquations_systems;

pm_om_model.total_ini_time.start_timer();
pm_om_model.system_execute_ini();
pm_om_model.total_ini_time.stop_timer();

// for(int i = 0; i < size; ++i)
// functionInitialEquations_systems[i](data);
}


void PM_functionDAE(int size, DATA* data, functionXXX_system* functionDAE_systems) {
void PM_functionDAE(int size, void* data, om_function_system* functionDAE_systems) {

pm_om_model.dae_system_funcs = functionDAE_systems;

pm_om_model.total_dae_time.start_timer();
pm_om_model.system_execute_dae();
pm_om_model.total_dae_time.stop_timer();

// for(int i = 0; i < size; ++i)
// functionDAE_systems[i](data);

}


void PM_functionODE(int size, DATA* data, functionXXX_system* functionODE_systems) {
void PM_functionODE(int size, void* data, om_function_system* functionODE_systems) {

pm_om_model.ode_system_funcs = functionODE_systems;

pm_om_model.total_ode_time.start_timer();
pm_om_model.system_execute_ode();
pm_om_model.total_ode_time.stop_timer();

// for(int i = 0; i < size; ++i)
// functionODE_systems[i](data);

}

void PM_functionAlg(int size, DATA* data, functionXXX_system* functionAlg_systems) {
void PM_functionAlg(int size, void* data, om_function_system* functionAlg_systems) {

pm_om_model.total_alg_time.start_timer();

Expand All @@ -106,9 +98,9 @@ void PM_functionAlg(int size, DATA* data, functionXXX_system* functionAlg_system
}

void dump_times() {
std::cout << "Total INI: " << pm_om_model.total_ini_time.get_elapsed_time() << std::endl;
std::cout << "Total DAE: " << pm_om_model.total_dae_time.get_elapsed_time() << std::endl;
std::cout << "Total ODE: " << pm_om_model.total_ode_time.get_elapsed_time() << std::endl;
std::cout << "Total INI: " << pm_om_model.INI_scheduler.execution_timer.get_elapsed_time() << std::endl;
std::cout << "Total DAE: " << pm_om_model.DAE_scheduler.execution_timer.get_elapsed_time() << std::endl;
std::cout << "Total ODE: " << pm_om_model.ODE_scheduler.execution_timer.get_elapsed_time() << std::endl;
std::cout << "Total ALG: " << pm_om_model.total_alg_time.get_elapsed_time() << std::endl;
}

Expand Down
20 changes: 9 additions & 11 deletions SimulationRuntime/ParModelica/auto/om_pm_interface.hpp
@@ -1,6 +1,6 @@
#pragma once
#ifndef id3D63AD28_5E5E_4CDD_96B370DC5B2241A5
#define id3D63AD28_5E5E_4CDD_96B370DC5B2241A5
#pragma once
#ifndef id3D63AD28_5E5E_4CDD_96B370DC5B2241A5
#define id3D63AD28_5E5E_4CDD_96B370DC5B2241A5


/*
Expand Down Expand Up @@ -41,23 +41,21 @@



#include <simulation_data.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*functionXXX_system)(DATA *);
typedef void (*om_function_system)(void *);

void PM_Model_init(const char* model_name, DATA* data);
void PM_Model_init(const char* model_name, void* data);

void PM_functionInitialEquations(int size, DATA* data, functionXXX_system*);
void PM_functionInitialEquations(int size, void* data, om_function_system*);

void PM_functionDAE(int size, DATA* data, functionXXX_system*);
void PM_functionDAE(int size, void* data, om_function_system*);

void PM_functionODE(int size, DATA* data, functionXXX_system*);
void PM_functionODE(int size, void* data, om_function_system*);

void PM_functionAlg(int size, DATA* data, functionXXX_system*);
void PM_functionAlg(int size, void* data, om_function_system*);

void dump_times();

Expand Down
151 changes: 85 additions & 66 deletions SimulationRuntime/ParModelica/auto/om_pm_model.cpp
Expand Up @@ -58,7 +58,6 @@ void OMModel::initialize() {
if(intialized)
return;

std::replace(model_name.begin(), model_name.end(), '_', '.');
std::string xml_file = model_name + "_info.xml";
std::cout << "Loading " << xml_file << std::endl;

Expand Down Expand Up @@ -89,82 +88,102 @@ void OMModel::initialize() {
}


void OMModel::system_execute(LevelScheduler<Equation>& scheduler, functionXXX_system* functionxxx_systems) {

LevelScheduler<Equation>::GraphType& system_graph = scheduler.task_system.graph;
LevelScheduler<Equation>::ProcessorQueuesAllLevelsType::const_iterator pq_level_iter;
pq_level_iter = scheduler.processor_queue_levels.begin() + 1;

/*! Do profiling and reschedule*/
if(!scheduler.profiled) {

std::cout << "system cost before = " << scheduler.task_system.total_cost << std::endl;
std::cout << "Scheduler cost before = " << scheduler.total_parallel_cost << std::endl;
std::cout << "Peak speedup before = " << scheduler.task_system.total_cost/scheduler.total_parallel_cost << std::endl;


scheduler.task_system.total_cost = 0;
PMTimer cost_timer;
double curr_cost;
for(; pq_level_iter != scheduler.processor_queue_levels.end(); ++pq_level_iter) {
const LevelScheduler<Equation>::ProcessorQueuesType& pqueues = *pq_level_iter;

for(unsigned j = 0; j < pqueues.size(); ++j) {
for(unsigned i = 0; i < pqueues[j].nodes.size(); ++i) {
cost_timer.start_timer();
functionxxx_systems[system_graph[pqueues[j].nodes[i]].node_id](data);
cost_timer.stop_timer();
curr_cost = cost_timer.get_elapsed_time() * 10000;
cost_timer.reset_timer();

system_graph[pqueues[j].nodes[i]].cost = curr_cost;
scheduler.task_system.total_cost += curr_cost;
}
}

}



scheduler.re_schedule(4);
scheduler.profiled = true;
std::cout << "system cost after = " << scheduler.task_system.total_cost << std::endl;
std::cout << "Scheduler cost after = " << scheduler.total_parallel_cost << std::endl;
std::cout << "Peak speedup after = " << scheduler.task_system.total_cost/scheduler.total_parallel_cost << std::endl;
// scheduler.print_schedule(std::cout);
std::cout << "-------------------------------------------------------------" << std::endl;
}

if(scheduler.profiled) {
for(; pq_level_iter != scheduler.processor_queue_levels.end(); ++pq_level_iter) {
const LevelScheduler<Equation>::ProcessorQueuesType& pqueues = *pq_level_iter;

for(unsigned j = 0; j < pqueues.size(); ++j) {
for(unsigned i = 0; i < pqueues[j].nodes.size(); ++i) {
functionxxx_systems[system_graph[pqueues[j].nodes[i]].node_id](data);
}
}

}
}

}


void OMModel::system_execute_ini() {
system_execute(INI_scheduler, ini_system_funcs);
//system_execute(INI_scheduler, ini_system_funcs);
if(!INI_scheduler.profiled)
INI_scheduler.profile_execute(ini_system_funcs, data);
else
INI_scheduler.execute_tasks(ini_system_funcs, data);
}


void OMModel::system_execute_dae() {
system_execute(DAE_scheduler, dae_system_funcs);
//system_execute(DAE_scheduler, dae_system_funcs);

if(!DAE_scheduler.profiled)
DAE_scheduler.profile_execute(dae_system_funcs, data);
else
DAE_scheduler.execute_tasks(dae_system_funcs, data);
}

void OMModel::system_execute_ode() {
system_execute(ODE_scheduler, ode_system_funcs);
//system_execute(ODE_scheduler, ode_system_funcs);

if(!ODE_scheduler.profiled)
ODE_scheduler.profile_execute(ode_system_funcs, data);
else
ODE_scheduler.execute_tasks(ode_system_funcs, data);
}


//void OMModel::system_execute(LevelScheduler<Equation>& scheduler, om_function_system* om_function_systems) {
//
// LevelScheduler<Equation>::GraphType& system_graph = scheduler.task_system.graph;
// LevelScheduler<Equation>::ProcessorQueuesAllLevelsType::const_iterator pq_level_iter;
// pq_level_iter = scheduler.processor_queue_levels.begin() + 1;
//
// /*! Do profiling and reschedule*/
// if(!scheduler.profiled)
// {
//
// std::cout << "system cost before = " << scheduler.task_system.total_cost << std::endl;
// std::cout << "Scheduler cost before = " << scheduler.total_parallel_cost << std::endl;
// std::cout << "Peak speedup before = " << scheduler.task_system.total_cost/scheduler.total_parallel_cost << std::endl;
//
//
// scheduler.task_system.total_cost = 0;
// PMTimer cost_timer;
// double curr_cost;
// for(; pq_level_iter != scheduler.processor_queue_levels.end(); ++pq_level_iter)
// {
// const LevelScheduler<Equation>::ProcessorQueuesType& pqueues = *pq_level_iter;
// for(unsigned j = 0; j < pqueues.size(); ++j)
// {
// for(unsigned i = 0; i < pqueues[j].nodes.size(); ++i)
// {
// cost_timer.start_timer();
// om_function_systems[system_graph[pqueues[j].nodes[i]].node_id](data);
// cost_timer.stop_timer();
// curr_cost = cost_timer.get_elapsed_time() * 10000;
// cost_timer.reset_timer();
//
// system_graph[pqueues[j].nodes[i]].cost = curr_cost;
// scheduler.task_system.total_cost += curr_cost;
// }
// }
//
// }
//
//
//
// scheduler.re_schedule(4);
// scheduler.profiled = true;
// std::cout << "system cost after = " << scheduler.task_system.total_cost << std::endl;
// std::cout << "Scheduler cost after = " << scheduler.total_parallel_cost << std::endl;
// std::cout << "Peak speedup after = " << scheduler.task_system.total_cost/scheduler.total_parallel_cost << std::endl;
// // scheduler.print_schedule(std::cout);
// std::cout << "-------------------------------------------------------------" << std::endl;
// }
//
// if(scheduler.profiled)
// {
// for(; pq_level_iter != scheduler.processor_queue_levels.end(); ++pq_level_iter)
// {
// const LevelScheduler<Equation>::ProcessorQueuesType& pqueues = *pq_level_iter;
// for(unsigned j = 0; j < pqueues.size(); ++j)
// {
// for(unsigned i = 0; i < pqueues[j].nodes.size(); ++i)
// {
// om_function_systems[system_graph[pqueues[j].nodes[i]].node_id](data);
// }
// }
//
// }
// }
//
//}





Expand Down

0 comments on commit 79453ce

Please sign in to comment.