|
|
@@ -30,6 +30,9 @@
|
|
|
#include <boost/program_options.hpp>
|
|
|
#include <boost/simulation.hpp>
|
|
|
#include "cdboost-devstone-atomic.hpp"
|
|
|
+#include "cdboost-devstone-atomic-pair.hpp"
|
|
|
+#include "cdboost-devstone-filter.hpp"
|
|
|
+#include "cdboost-devstone-input-stream-pair.hpp"
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace cdpp;
|
|
|
@@ -38,15 +41,16 @@ using hclock=chrono::high_resolution_clock;
|
|
|
using Time=double;
|
|
|
//const float infinity = std::numeric_limits<double>::infinity();
|
|
|
inline bool is_infinity(double& f ){ return isinf(f); }
|
|
|
-using msg_type=int;
|
|
|
+using msg_type_int=int;
|
|
|
+using msg_type_pair=std::pair<int, int>;
|
|
|
|
|
|
-shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> LI_coupling(int& counted_atomic_models, int& counted_coupled_models,
|
|
|
+shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> LI_coupling(int& counted_atomic_models, int& counted_coupled_models,
|
|
|
int width, int depth, string event_list, int ext_cycles, int int_cycles, int time_advance)
|
|
|
{
|
|
|
- shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> cm;
|
|
|
- auto first_pdevstone = boost::simulation::make_atomic_ptr<PDEVStoneAtomic<Time, msg_type>, int, int, Time>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> cm;
|
|
|
+ auto first_pdevstone = boost::simulation::make_atomic_ptr<PDEVStoneAtomic<Time, msg_type_int>, int, int, Time>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
counted_atomic_models++;
|
|
|
- cm.reset(new boost::simulation::pdevs::coupled<Time, msg_type>{{first_pdevstone}, {first_pdevstone}, {}, {first_pdevstone}});
|
|
|
+ cm.reset(new boost::simulation::pdevs::coupled<Time, msg_type_int>{{first_pdevstone}, {first_pdevstone}, {}, {first_pdevstone}});
|
|
|
counted_coupled_models++;
|
|
|
|
|
|
//connect higher level models
|
|
|
@@ -60,7 +64,7 @@ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> LI_coupling(int& c
|
|
|
eic_cm.clear();
|
|
|
eoc_cm.push_back(cm);
|
|
|
for (int j=0; j < width-1; j++){
|
|
|
- auto current = (std::shared_ptr<boost::simulation::model<Time>>) std::make_shared<cdpp::PDEVStoneAtomic<Time, msg_type>>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
+ auto current = (std::shared_ptr<boost::simulation::model<Time>>) std::make_shared<cdpp::PDEVStoneAtomic<Time, msg_type_int>>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
vpdt.push_back(current);
|
|
|
counted_atomic_models++;
|
|
|
eic_cm.push_back(current);
|
|
|
@@ -68,28 +72,28 @@ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> LI_coupling(int& c
|
|
|
vpdt.push_back(cm);
|
|
|
eic_cm.push_back(cm);
|
|
|
|
|
|
- shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> cm_int ( new boost::simulation::pdevs::coupled<Time, msg_type>{vpdt, eic_cm, {}, eoc_cm});
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> cm_int ( new boost::simulation::pdevs::coupled<Time, msg_type_int>{vpdt, eic_cm, {}, eoc_cm});
|
|
|
counted_coupled_models++;
|
|
|
cm=cm_int;
|
|
|
}
|
|
|
|
|
|
//Plug the input events
|
|
|
shared_ptr<istream> piss{ new ifstream{event_list} };
|
|
|
- auto pf = boost::simulation::make_atomic_ptr<boost::simulation::pdevs::basic_models::input_stream<Time, msg_type, int, int>, shared_ptr<istream>, Time>(piss, Time{0});
|
|
|
+ auto pf = boost::simulation::make_atomic_ptr<boost::simulation::pdevs::basic_models::input_stream<Time, msg_type_int, int, int>, shared_ptr<istream>, Time>(piss, Time{0});
|
|
|
counted_atomic_models++;
|
|
|
|
|
|
- auto root = std::make_shared<boost::simulation::pdevs::coupled<Time, msg_type>>(boost::simulation::pdevs::coupled<Time, msg_type>({pf, cm}, {}, {{pf, cm}}, {cm}));
|
|
|
+ auto root = std::make_shared<boost::simulation::pdevs::coupled<Time, msg_type_int>>(boost::simulation::pdevs::coupled<Time, msg_type_int>({pf, cm}, {}, {{pf, cm}}, {cm}));
|
|
|
counted_coupled_models++;
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
-shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> HI_coupling(int& counted_atomic_models, int& counted_coupled_models,
|
|
|
+shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> HI_coupling(int& counted_atomic_models, int& counted_coupled_models,
|
|
|
int width, int depth, string event_list, int ext_cycles, int int_cycles, int time_advance)
|
|
|
{
|
|
|
- shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> cm;
|
|
|
- auto first_pdevstone = boost::simulation::make_atomic_ptr<PDEVStoneAtomic<Time, msg_type>, int, int, Time>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> cm;
|
|
|
+ auto first_pdevstone = boost::simulation::make_atomic_ptr<PDEVStoneAtomic<Time, msg_type_int>, int, int, Time>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
counted_atomic_models++;
|
|
|
- cm.reset(new boost::simulation::pdevs::coupled<Time, msg_type>{{first_pdevstone}, {first_pdevstone}, {}, {first_pdevstone}});
|
|
|
+ cm.reset(new boost::simulation::pdevs::coupled<Time, msg_type_int>{{first_pdevstone}, {first_pdevstone}, {}, {first_pdevstone}});
|
|
|
counted_coupled_models++;
|
|
|
|
|
|
//connect higher level models
|
|
|
@@ -105,7 +109,7 @@ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> HI_coupling(int& c
|
|
|
ic_cm.clear();
|
|
|
eoc_cm.push_back(cm);
|
|
|
for (int j=0; j < width-1; j++){
|
|
|
- std::shared_ptr<boost::simulation::model<Time>> current = std::shared_ptr<boost::simulation::model<Time>>(make_shared<PDEVStoneAtomic<Time, msg_type>>(int_cycles, ext_cycles, Time(time_advance)));
|
|
|
+ std::shared_ptr<boost::simulation::model<Time>> current = std::shared_ptr<boost::simulation::model<Time>>(make_shared<PDEVStoneAtomic<Time, msg_type_int>>(int_cycles, ext_cycles, Time(time_advance)));
|
|
|
if (j > 0) ic_cm.push_back({vpdt.back(), current});
|
|
|
vpdt.push_back(current);
|
|
|
counted_atomic_models++;
|
|
|
@@ -114,24 +118,81 @@ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> HI_coupling(int& c
|
|
|
vpdt.push_back(cm);
|
|
|
eic_cm.push_back(cm);
|
|
|
|
|
|
- shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> cm_int ( new boost::simulation::pdevs::coupled<Time, msg_type>{vpdt, eic_cm, ic_cm, eoc_cm});
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> cm_int ( new boost::simulation::pdevs::coupled<Time, msg_type_int>{vpdt, eic_cm, ic_cm, eoc_cm});
|
|
|
counted_coupled_models++;
|
|
|
cm=cm_int;
|
|
|
}
|
|
|
|
|
|
//Plug the input events
|
|
|
shared_ptr<istream> piss{ new ifstream{event_list} };
|
|
|
- auto pf = boost::simulation::make_atomic_ptr<boost::simulation::pdevs::basic_models::input_stream<Time, msg_type, int, int>, shared_ptr<istream>, Time>(piss, Time{0});
|
|
|
+ auto pf = boost::simulation::make_atomic_ptr<boost::simulation::pdevs::basic_models::input_stream<Time, msg_type_int, int, int>, shared_ptr<istream>, Time>(piss, Time{0});
|
|
|
|
|
|
counted_atomic_models++;
|
|
|
|
|
|
- auto root = std::make_shared<boost::simulation::pdevs::coupled<Time, msg_type>>(boost::simulation::pdevs::coupled<Time, msg_type>({pf, cm}, {}, {{pf, cm}}, {cm}));
|
|
|
+ auto root = std::make_shared<boost::simulation::pdevs::coupled<Time, msg_type_int>>(boost::simulation::pdevs::coupled<Time, msg_type_int>({pf, cm}, {}, {{pf, cm}}, {cm}));
|
|
|
+ counted_coupled_models++;
|
|
|
+ return root;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_pair>> HO_coupling(int& counted_atomic_models, int& counted_coupled_models,
|
|
|
+ int width, int depth, string event_list, int ext_cycles, int int_cycles, int time_advance)
|
|
|
+{
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_pair>> cm;
|
|
|
+ auto first_pdevstone = boost::simulation::make_atomic_ptr<PDEVStoneAtomicPair<Time, msg_type_pair>, int, int, Time>(int_cycles, ext_cycles, Time(time_advance));
|
|
|
+ counted_atomic_models++;
|
|
|
+ cm.reset(new boost::simulation::pdevs::coupled<Time, msg_type_pair>{{first_pdevstone}, {first_pdevstone}, {}, {first_pdevstone}});
|
|
|
+ counted_coupled_models++;
|
|
|
+
|
|
|
+ //connect higher level models
|
|
|
+
|
|
|
+ for (int i=1; i < depth; i++){
|
|
|
+ auto filter0 = boost::simulation::make_atomic_ptr<PDEVStoneFilter<Time, msg_type_pair>, int, Time>(0, Time(time_advance)); // in
|
|
|
+ auto filter1 = boost::simulation::make_atomic_ptr<PDEVStoneFilter<Time, msg_type_pair>, int, Time>(1, Time(time_advance)); // in2
|
|
|
+ counted_atomic_models+=2;
|
|
|
+ vector<std::shared_ptr<boost::simulation::model<Time>>> vpdt;
|
|
|
+ vector<std::shared_ptr<boost::simulation::model<Time>>> eoc_cm;
|
|
|
+ vector<std::shared_ptr<boost::simulation::model<Time>>> eic_cm;
|
|
|
+ vector<pair<std::shared_ptr<boost::simulation::model<Time>>, std::shared_ptr<boost::simulation::model<Time>>>> ic_cm;
|
|
|
+ vpdt.clear();
|
|
|
+ eoc_cm.clear();
|
|
|
+ eic_cm.clear();
|
|
|
+ ic_cm.clear();
|
|
|
+ eoc_cm.push_back(cm);
|
|
|
+ eic_cm.push_back(filter0);
|
|
|
+ eic_cm.push_back(filter1);
|
|
|
+ for (int j=0; j < width-1; j++){
|
|
|
+ std::shared_ptr<boost::simulation::model<Time>> current = std::shared_ptr<boost::simulation::model<Time>>(make_shared<PDEVStoneAtomicPair<Time, msg_type_pair>>(int_cycles, ext_cycles, Time(time_advance)));
|
|
|
+ if (j > 0) ic_cm.push_back({vpdt.back(), current});
|
|
|
+ vpdt.push_back(current);
|
|
|
+ counted_atomic_models++;
|
|
|
+ //eic_cm.push_back(current);
|
|
|
+ ic_cm.push_back({filter1, current});
|
|
|
+ eoc_cm.push_back(current);
|
|
|
+ }
|
|
|
+ vpdt.push_back(cm);
|
|
|
+ vpdt.push_back(filter0);
|
|
|
+ vpdt.push_back(filter1);
|
|
|
+ //eic_cm.push_back(cm);
|
|
|
+ ic_cm.push_back({filter0, cm});
|
|
|
+
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_pair>> cm_int ( new boost::simulation::pdevs::coupled<Time, msg_type_pair>{vpdt, eic_cm, ic_cm, eoc_cm});
|
|
|
+ counted_coupled_models++;
|
|
|
+ cm=cm_int;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Plug the input events
|
|
|
+ auto gen = boost::simulation::make_atomic_ptr<devstone_input_stream_pair<Time, msg_type_pair>, Time>(Time(time_advance));
|
|
|
+ counted_atomic_models++;
|
|
|
+
|
|
|
+ auto root = std::make_shared<boost::simulation::pdevs::coupled<Time, msg_type_pair>>(boost::simulation::pdevs::coupled<Time, msg_type_pair>({gen, cm}, {}, {{gen, cm}}, {cm}));
|
|
|
counted_coupled_models++;
|
|
|
return root;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
int main(int argc, char* argv[]){
|
|
|
auto start = hclock::now();
|
|
|
|
|
|
@@ -196,23 +257,30 @@ int main(int argc, char* argv[]){
|
|
|
int counted_coupled_models=0;
|
|
|
|
|
|
|
|
|
- shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type>> root;
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_int>> root_int;
|
|
|
+ shared_ptr<boost::simulation::pdevs::coupled<Time, msg_type_pair>> root_pair;
|
|
|
if (kind.compare("LI") == 0){
|
|
|
- root = LI_coupling(counted_atomic_models, counted_coupled_models, width, depth, event_list, ext_cycles, int_cycles, time_advance);
|
|
|
+ root_int = LI_coupling(counted_atomic_models, counted_coupled_models, width, depth, event_list, ext_cycles, int_cycles, time_advance);
|
|
|
} else if (kind.compare("HI") == 0){
|
|
|
- root = HI_coupling(counted_atomic_models, counted_coupled_models, width, depth, event_list, ext_cycles, int_cycles, time_advance);
|
|
|
+ root_int = HI_coupling(counted_atomic_models, counted_coupled_models, width, depth, event_list, ext_cycles, int_cycles, time_advance);
|
|
|
+ } else if (kind.compare("HO") == 0){
|
|
|
+ root_pair = HO_coupling(counted_atomic_models, counted_coupled_models, width, depth, event_list, ext_cycles, int_cycles, time_advance);
|
|
|
} else {
|
|
|
abort();
|
|
|
}
|
|
|
|
|
|
auto model_built = hclock::now();
|
|
|
-
|
|
|
+ std::chrono::_V2::system_clock::time_point model_init;
|
|
|
//run the model
|
|
|
- boost::simulation::pdevs::runner<Time, msg_type> r(root, Time{0});
|
|
|
-
|
|
|
- auto model_init = hclock::now();
|
|
|
-
|
|
|
- r.runUntilPassivate();
|
|
|
+ if (kind.compare("LI") == 0 || kind.compare("HI") == 0) {
|
|
|
+ boost::simulation::pdevs::runner<Time, msg_type_int> r(root_int, Time{0});
|
|
|
+ model_init = hclock::now();
|
|
|
+ r.runUntilPassivate();
|
|
|
+ } else { // HO or HOmod
|
|
|
+ boost::simulation::pdevs::runner<Time, msg_type_pair> r(root_pair, Time{0});
|
|
|
+ model_init = hclock::now();
|
|
|
+ r.runUntilPassivate();
|
|
|
+ }
|
|
|
|
|
|
auto finished_simulation = hclock::now();
|
|
|
|