main.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file tests/multithreading/lifegame/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-2016 ULCO http://www.univ-littoral.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 <tests/multithreading/lifegame/graph_manager.hpp>
  27. #include <tests/multithreading/lifegame/models.hpp>
  28. #include <chrono>
  29. using namespace paradevs::common;
  30. using namespace std::chrono;
  31. using namespace paradevs::tests::multithreading::lifegame;
  32. double lifegame_monothreading()
  33. {
  34. paradevs::common::RootCoordinator <
  35. DoubleTime, paradevs::pdevs::Coordinator <
  36. DoubleTime,
  37. HierarchicalGraphManager,
  38. paradevs::common::NoParameters,
  39. GraphManagerParameters >
  40. > rc(0, 10, "root", paradevs::common::NoParameters(),
  41. GraphManagerParameters(4));
  42. steady_clock::time_point t1 = steady_clock::now();
  43. rc.run();
  44. steady_clock::time_point t2 = steady_clock::now();
  45. duration < double > time_span = duration_cast <
  46. duration < double > >(t2 - t1);
  47. return time_span.count();
  48. }
  49. double lifegame_multithreading(int cluster_number)
  50. {
  51. paradevs::common::RootCoordinator <
  52. DoubleTime, paradevs::pdevs::multithreading::Coordinator <
  53. DoubleTime,
  54. ParallelHierarchicalGraphManager,
  55. paradevs::common::NoParameters,
  56. GraphManagerParameters >
  57. > rc(0, 10, "root", paradevs::common::NoParameters(),
  58. GraphManagerParameters(cluster_number));
  59. steady_clock::time_point t1 = steady_clock::now();
  60. rc.run();
  61. steady_clock::time_point t2 = steady_clock::now();
  62. duration < double > time_span = duration_cast <
  63. duration < double > >(t2 - t1);
  64. return time_span.count();
  65. }
  66. void lifegame(int n)
  67. {
  68. if (n == 1) {
  69. std::cout << lifegame_monothreading() << std::endl;
  70. } else {
  71. std::cout << lifegame_multithreading(n) << std::endl;
  72. }
  73. }
  74. int main(int argc, char** argv)
  75. {
  76. if (argc > 1) {
  77. lifegame(atoi(argv[1]));
  78. }
  79. return 0;
  80. }