123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- /**
- * @file tests/mpi/cluster/graph_manager.cpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
- /*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013-2015 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef TESTS_PDEVS_MPI_CLUSTER_GRAPH_MANAGER_HPP
- #define TESTS_PDEVS_MPI_CLUSTER_GRAPH_MANAGER_HPP 1
- #include <tests/pdevs/graph_manager.hpp>
- #include <tests/mpi/cluster/models.hpp>
- #include <paradevs/kernel/pdevs/mpi/Coordinator.hpp>
- #include <paradevs/kernel/pdevs/mpi/ModelProxy.hpp>
- #include <paradevs/kernel/pdevs/mpi/GraphManager.hpp>
- #include <paradevs/kernel/pdevs/Simulator.hpp>
- #include <sstream>
- namespace paradevs { namespace tests { namespace mpi { namespace cluster {
- struct SubGraphManagerParameters
- {
- std::vector < int > indexes;
- std::vector < std::pair < int, int > > internals;
- std::vector < std::pair < int, int > > inputs;
- std::vector < std::pair < int, int > > outputs;
- };
- class SubGraphManager :
- public paradevs::pdevs::mpi::GraphManager < common::DoubleTime,
- SubGraphManagerParameters >
- {
- public:
- SubGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
- const SubGraphManagerParameters& parameters) :
- paradevs::pdevs::mpi::GraphManager <
- common::DoubleTime,
- SubGraphManagerParameters >(coordinator, parameters)
- {
- for (std::vector < int >::const_iterator it = parameters.indexes.begin();
- it != parameters.indexes.end(); ++it) {
- std::stringstream ss;
-
- ss << "m_" << *it;
- Simulator* m = new Simulator(ss.str(), paradevs::common::NoParameters());
-
- models[*it] = m;
- add_child(m);
- m->add_in_port("in");
- m->add_out_port("out");
- }
- for (std::vector < std::pair < int, int > >::const_iterator it =
- parameters.inputs.begin(); it != parameters.inputs.end(); ++it) {
- std::stringstream ss;
-
- ss << "in_" << it->first;
- if (not coordinator->exist_in_port(ss.str())) {
- coordinator->add_in_port(ss.str());
- }
- if (not exist_link(coordinator, ss.str(), models[it->second], "in")) {
- add_link(coordinator, ss.str(), models[it->second], "in");
- }
- }
- for (std::vector < std::pair < int, int > >::const_iterator it =
- parameters.outputs.begin(); it != parameters.outputs.end(); ++it) {
- std::stringstream ss;
-
- ss << "out_" << it->first;
- if (not coordinator->exist_out_port(ss.str())) {
- coordinator->add_out_port(ss.str());
- }
- if (not exist_link(models[it->first], "out", coordinator, ss.str())) {
- add_link(models[it->first], "out", coordinator, ss.str());
- }
- }
- for (std::vector < std::pair < int, int > >::const_iterator it =
- parameters.internals.begin(); it != parameters.internals.end();
- ++it) {
- if (not exist_link(models[it->first], "out", models[it->second], "in")) {
- add_link(models[it->first], "out", models[it->second], "in");
- }
- }
- }
-
- void init()
- { }
-
- void start(common::DoubleTime::type /* t */)
- { }
-
- void transition(const common::Models < common::DoubleTime >& /* receivers */,
- common::DoubleTime::type /* t */)
- { }
- virtual ~SubGraphManager()
- {
- for (Simulators::iterator it = models.begin(); it != models.end(); ++it) {
- delete it->second;
- }
- }
- private:
- typedef paradevs::pdevs::Simulator < common::DoubleTime,
- ThreeStateModel > Simulator;
- typedef std::map < int, Simulator* > Simulators;
-
- Simulators models;
- };
- struct RootGraphManagerParameters
- {
- std::vector <
- std::vector <
- std::pair <
- std::pair < int, int >,
- std::pair < int, int > > > > parents;
- };
- class LevelGraphManager :
- public paradevs::pdevs::GraphManager < common::DoubleTime,
- RootGraphManagerParameters >
- {
- public:
- LevelGraphManager(
- common::Coordinator < common::DoubleTime >* coordinator,
- const RootGraphManagerParameters& parameters) :
- paradevs::pdevs::GraphManager < common::DoubleTime,
- RootGraphManagerParameters >(
- coordinator, parameters)
- {
- int index = 0;
-
- for (std::vector < std::vector <
- std::pair < std::pair < int, int >,
- std::pair < int, int > > > >::const_iterator it =
- parameters.parents.begin(); it != parameters.parents.end();
- ++it) {
- std::stringstream ss;
- ModelProxy* model = 0;
-
- ss << "S_" << index;
- model = new ModelProxy(ss.str(), index + 1, false);
- models.push_back(model);
- add_child(model);
- ++index;
- }
- for (std::vector < std::vector <
- std::pair < std::pair < int, int >,
- std::pair < int, int > > > >::const_iterator it =
- parameters.parents.begin(); it != parameters.parents.end();
- ++it) {
- for (std::vector <
- std::pair < std::pair < int, int >,
- std::pair < int, int > > >::const_iterator it2 =
- it->begin(); it2 != it->end(); ++it2) {
- std::stringstream out_ss;
- std::stringstream in_ss;
- out_ss << "out_" << it2->first.second;
- if (not models[it2->first.first]->exist_out_port(out_ss.str())) {
- models[it2->first.first]->add_out_port(out_ss.str());
- }
- in_ss << "in_" << it2->first.second;
- if (not models[it2->second.first]->exist_in_port(in_ss.str())) {
- models[it2->second.first]->add_in_port(in_ss.str());
- }
- if (not exist_link(models[it2->first.first], out_ss.str(),
- models[it2->second.first], in_ss.str())) {
- add_link(models[it2->first.first], out_ss.str(),
- models[it2->second.first], in_ss.str());
- }
- }
- }
- }
- void init()
- { }
- void start(common::DoubleTime::type /* t */)
- { }
- void transition(
- const common::Models < common::DoubleTime >& /* receivers */,
- common::DoubleTime::type /* t */)
- { }
-
- virtual ~LevelGraphManager()
- {
- std::for_each(models.begin(), models.end(),
- std::default_delete < ModelProxy >());
- }
- private:
- typedef paradevs::pdevs::mpi::ModelProxy < common::DoubleTime > ModelProxy;
- typedef std::vector < ModelProxy* > ModelProxies;
- ModelProxies models;
- };
- class RootGraphManager :
- public paradevs::pdevs::GraphManager < common::DoubleTime,
- RootGraphManagerParameters >
- {
- public:
- RootGraphManager(
- common::Coordinator < common::DoubleTime >* coordinator,
- const RootGraphManagerParameters& parameters) :
- paradevs::pdevs::GraphManager < common::DoubleTime,
- RootGraphManagerParameters >(
- coordinator, parameters),
- S("S", paradevs::common::NoParameters(), parameters)
- {
- add_child(&S);
- }
- void init()
- {
- S.set_sender(
- dynamic_cast < paradevs::pdevs::multithreading::Coordinator <
- common::DoubleTime,
- paradevs::tests::mpi::cluster::RootGraphManager >*
- >(get_coordinator())->get_sender());
- }
- void start(common::DoubleTime::type t)
- {
- S.get_sender().send(
- paradevs::pdevs::multithreading::start_message <
- common::DoubleTime >(t));
- }
- void transition(const common::Models < common::DoubleTime >& receivers,
- common::DoubleTime::type t)
- {
- S.get_sender().send(
- paradevs::pdevs::multithreading::transition_message <
- common::DoubleTime >(t));
- }
- virtual ~RootGraphManager()
- { }
- private:
- paradevs::pdevs::multithreading::Coordinator <
- common::DoubleTime, LevelGraphManager, paradevs::common::NoParameters, RootGraphManagerParameters > S;
- };
- } } } } // namespace paradevs tests mpi cluster
- #endif
|