graph_manager.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @file tests/mpi/cluster/graph_manager.cpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013-2015 ULCO http://www.univ-litoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef TESTS_PDEVS_MPI_CLUSTER_GRAPH_MANAGER_HPP
  26. #define TESTS_PDEVS_MPI_CLUSTER_GRAPH_MANAGER_HPP 1
  27. #include <tests/pdevs/graph_manager.hpp>
  28. #include <tests/mpi/cluster/models.hpp>
  29. #include <paradevs/kernel/pdevs/mpi/Coordinator.hpp>
  30. #include <paradevs/kernel/pdevs/mpi/ModelProxy.hpp>
  31. #include <paradevs/kernel/pdevs/mpi/GraphManager.hpp>
  32. #include <paradevs/kernel/pdevs/Simulator.hpp>
  33. #include <sstream>
  34. namespace paradevs { namespace tests { namespace mpi { namespace cluster {
  35. class SubGraphManager :
  36. public paradevs::pdevs::mpi::GraphManager < common::DoubleTime >
  37. {
  38. public:
  39. SubGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
  40. const paradevs::common::NoParameters& parameters) :
  41. paradevs::pdevs::mpi::GraphManager < common::DoubleTime >(coordinator,
  42. parameters)
  43. {
  44. coordinator->add_in_port("in");
  45. coordinator->add_out_port("out");
  46. for (unsigned int i = 0; i < 1250; ++i) {
  47. Simulator* m = new Simulator("m", paradevs::common::NoParameters());
  48. models.push_back(m);
  49. add_child(m);
  50. m->add_in_port("in");
  51. m->add_out_port("out");
  52. add_link(coordinator, "in", m, "in");
  53. add_link(m, "out", coordinator, "out");
  54. }
  55. }
  56. void init()
  57. { }
  58. void start(common::DoubleTime::type /* t */)
  59. { }
  60. void transition(const common::Models < common::DoubleTime >& /* receivers */,
  61. common::DoubleTime::type /* t */)
  62. { }
  63. virtual ~SubGraphManager()
  64. {
  65. std::for_each(models.begin(), models.end(),
  66. std::default_delete < Simulator >());
  67. }
  68. private:
  69. typedef paradevs::pdevs::Simulator < common::DoubleTime,
  70. ThreeStateModel > Simulator;
  71. typedef std::vector < Simulator* > Simulators;
  72. Simulators models;
  73. };
  74. struct RootGraphManagerParameters
  75. {
  76. std::vector < int > ranks;
  77. };
  78. class RootGraphManager :
  79. public paradevs::pdevs::GraphManager < common::DoubleTime,
  80. RootGraphManagerParameters >
  81. {
  82. public:
  83. RootGraphManager(
  84. common::Coordinator < common::DoubleTime >* coordinator,
  85. const RootGraphManagerParameters& parameters) :
  86. paradevs::pdevs::GraphManager < common::DoubleTime,
  87. RootGraphManagerParameters >(
  88. coordinator, parameters)
  89. {
  90. for (std::vector < int >::const_iterator it = parameters.ranks.begin();
  91. it != parameters.ranks.end(); ++it) {
  92. std::stringstream ss;
  93. ModelProxy* model = 0;
  94. ss << "S" << *it;
  95. model = new ModelProxy(ss.str(), *it, false);
  96. models.push_back(model);
  97. add_child(model);
  98. // connections (part)
  99. model->add_out_port("out");
  100. model->add_in_port("in");
  101. // if (it != parameters.ranks.begin()) {
  102. // add_link(previous, "out", model, "in");
  103. // }
  104. }
  105. }
  106. virtual ~RootGraphManager()
  107. {
  108. std::for_each(models.begin(), models.end(),
  109. std::default_delete < ModelProxy >());
  110. }
  111. private:
  112. typedef paradevs::pdevs::mpi::ModelProxy < common::DoubleTime > ModelProxy;
  113. typedef std::vector < ModelProxy* > ModelProxies;
  114. ModelProxies models;
  115. };
  116. } } } } // namespace paradevs tests mpi cluster
  117. #endif