123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /**
- * @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 {
- class SubGraphManager :
- public paradevs::pdevs::mpi::GraphManager < common::DoubleTime >
- {
- public:
- SubGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
- const paradevs::common::NoParameters& parameters) :
- paradevs::pdevs::mpi::GraphManager < common::DoubleTime >(coordinator,
- parameters)
- {
- coordinator->add_in_port("in");
- coordinator->add_out_port("out");
-
- for (unsigned int i = 0; i < 1250; ++i) {
- Simulator* m = new Simulator("m", paradevs::common::NoParameters());
-
- models.push_back(m);
- add_child(m);
- m->add_in_port("in");
- m->add_out_port("out");
- add_link(coordinator, "in", m, "in");
- add_link(m, "out", coordinator, "out");
- }
- }
- void init()
- { }
-
- void start(common::DoubleTime::type /* t */)
- { }
-
- void transition(const common::Models < common::DoubleTime >& /* receivers */,
- common::DoubleTime::type /* t */)
- { }
- virtual ~SubGraphManager()
- {
- std::for_each(models.begin(), models.end(),
- std::default_delete < Simulator >());
- }
- private:
- typedef paradevs::pdevs::Simulator < common::DoubleTime,
- ThreeStateModel > Simulator;
- typedef std::vector < Simulator* > Simulators;
-
- Simulators models;
- };
- struct RootGraphManagerParameters
- {
- std::vector < int > ranks;
- };
- 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)
- {
- for (std::vector < int >::const_iterator it = parameters.ranks.begin();
- it != parameters.ranks.end(); ++it) {
- std::stringstream ss;
- ModelProxy* model = 0;
- ss << "S" << *it;
- model = new ModelProxy(ss.str(), *it, false);
- models.push_back(model);
- add_child(model);
-
- // connections (part)
- model->add_out_port("out");
- model->add_in_port("in");
- // if (it != parameters.ranks.begin()) {
- // add_link(previous, "out", model, "in");
- // }
- }
- }
- virtual ~RootGraphManager()
- {
- 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;
- };
- } } } } // namespace paradevs tests mpi cluster
- #endif
|