main.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * @file tests/mpi/main.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. #include <paradevs/common/RootCoordinator.hpp>
  26. #include <boost/mpi/environment.hpp>
  27. #include <boost/mpi/communicator.hpp>
  28. // #include <tests/boost_graph/graph_defs.hpp>
  29. // #include <tests/boost_graph/graph_builder.hpp>
  30. // #include <tests/boost_graph/graph_generator.hpp>
  31. // #include <tests/boost_graph/graph_partitioning.hpp>
  32. #include <paradevs/common/time/DoubleTime.hpp>
  33. #include <paradevs/kernel/pdevs/mpi/LogicalProcessor.hpp>
  34. #include <tests/mpi/graph_manager.hpp>
  35. #include <chrono>
  36. using namespace paradevs::tests::mpi;
  37. using namespace paradevs::common;
  38. using namespace boost::mpi;
  39. using namespace std::chrono;
  40. void example_simple(int argc, char *argv[])
  41. {
  42. environment env(argc, argv);
  43. communicator world;
  44. if (world.rank() == 0) {
  45. paradevs::tests::mpi::RootGraphManagerParameters parameters;
  46. parameters.S1_rank = 1;
  47. parameters.S2_rank = 2;
  48. paradevs::common::RootCoordinator <
  49. DoubleTime,
  50. paradevs::pdevs::Coordinator <
  51. DoubleTime,
  52. paradevs::tests::mpi::RootGraphManager,
  53. paradevs::common::NoParameters,
  54. paradevs::tests::mpi::RootGraphManagerParameters >
  55. > rc(0, 10, "root", paradevs::common::NoParameters(), parameters);
  56. rc.run();
  57. } else {
  58. if (world.rank() == 1) {
  59. paradevs::pdevs::mpi::Coordinator <
  60. DoubleTime,
  61. paradevs::tests::mpi::S1GraphManager > model(
  62. "S1", paradevs::common::NoParameters(),
  63. paradevs::common::NoParameters());
  64. paradevs::pdevs::mpi::LogicalProcessor <
  65. DoubleTime > LP(&model, world.rank(), 0);
  66. model.set_logical_processor(&LP);
  67. LP.loop();
  68. } else if (world.rank() == 2) {
  69. paradevs::pdevs::mpi::Coordinator <
  70. DoubleTime,
  71. paradevs::tests::mpi::S2GraphManager > model(
  72. "S2", paradevs::common::NoParameters(),
  73. paradevs::common::NoParameters());
  74. paradevs::pdevs::mpi::LogicalProcessor <
  75. DoubleTime > LP(&model, world.rank(), 0);
  76. model.set_logical_processor(&LP);
  77. LP.loop();
  78. }
  79. }
  80. }
  81. // void example_grid(int argc, char *argv[])
  82. // {
  83. // environment env(argc, argv);
  84. // communicator world;
  85. // unsigned int side = 100;
  86. // std::vector<std::pair<int,int>> vertex_selection;
  87. // std::pair<int,int> tmp;
  88. // tmp.first = 0;
  89. // tmp.second = 3;
  90. // vertex_selection.push_back(tmp);
  91. // paradevs::tests::boost_graph::Entiers weight_vertex;
  92. // weight_vertex.push_back(1);
  93. // const char *edge_weight;
  94. // edge_weight = "../../sortie_graphe/tests_grid.txt";
  95. // bool rec = false;
  96. // paradevs::tests::boost_graph::RandomGridGraphGenerator generator(
  97. // side, vertex_selection, weight_vertex, edge_weight, rec);
  98. // paradevs::tests::boost_graph::PartitioningGraphBuilder builder(
  99. // 4, "gggp", 20, false, generator);
  100. // paradevs::tests::mpi::MPIHierarchicalGraphManagerParameters parameters;
  101. // builder.build(parameters.graphs, parameters.input_edges,
  102. // parameters.output_edges, parameters.parent_connections);
  103. // if (world.rank() == 0) {
  104. // paradevs::common::RootCoordinator <
  105. // DoubleTime, paradevs::pdevs::mpi::Coordinator <
  106. // DoubleTime,
  107. // paradevs::tests::mpi::MPIHierarchicalGraphManager,
  108. // paradevs::common::NoParameters,
  109. // paradevs::tests::mpi::MPIHierarchicalGraphManagerParameters >
  110. // > rc(0, 10, "root", paradevs::common::NoParameters(), parameters);
  111. // steady_clock::time_point t1 = steady_clock::now();
  112. // rc.run();
  113. // steady_clock::time_point t2 = steady_clock::now();
  114. // duration < double > time_span = duration_cast <
  115. // duration < double > >(t2 - t1);
  116. // std::cout << "MULTI = " << time_span.count() << std::endl;
  117. // } else {
  118. // }
  119. // }
  120. int main(int argc, char *argv[])
  121. {
  122. example_simple(argc, argv);
  123. // example_grid(argc, argv);
  124. return 0;
  125. }