tests.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /**
  2. * @file tests/boost_graph/tests.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 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 <boost/timer.hpp>
  26. #include <paradevs/common/RootCoordinator.hpp>
  27. #include <tests/boost_graph/models.hpp>
  28. #include <tests/boost_graph/graph_builder.hpp>
  29. #include <tests/boost_graph/graph_manager.hpp>
  30. #include <tests/boost_graph/graph_partitioning.hpp>
  31. using namespace paradevs::common;
  32. using namespace paradevs::common::scheduler;
  33. using namespace paradevs::pdevs;
  34. using namespace paradevs::tests::boost_graph;
  35. template < class GraphBuilder >
  36. void flat_heap_test(double duration)
  37. {
  38. RootCoordinator <
  39. DoubleTime,
  40. paradevs::pdevs::Coordinator <
  41. DoubleTime,
  42. SchedulerType,
  43. SchedulerHandle,
  44. InBuildFlatGraphManager <
  45. SchedulerHandle,
  46. GraphBuilder >,
  47. paradevs::common::NoParameters,
  48. paradevs::common::NoParameters >
  49. > rc(0, duration, "root", NoParameters(), NoParameters());
  50. rc.run();
  51. }
  52. template < class GraphBuilder >
  53. void flat_vector_test(double duration)
  54. {
  55. RootCoordinator <
  56. DoubleTime,
  57. paradevs::pdevs::Coordinator <
  58. DoubleTime,
  59. paradevs::common::scheduler::VectorScheduler <
  60. paradevs::common::DoubleTime >,
  61. paradevs::common::scheduler::NoSchedulerHandle,
  62. InBuildFlatGraphManager <
  63. paradevs::common::scheduler::NoSchedulerHandle,
  64. GraphBuilder >,
  65. paradevs::common::NoParameters,
  66. paradevs::common::NoParameters >
  67. > rc(0, duration, "root", NoParameters(), NoParameters());
  68. rc.run();
  69. }
  70. void hierarchical_test()
  71. {
  72. // RootCoordinator <
  73. // DoubleTime,
  74. // paradevs::pdevs::Coordinator <
  75. // DoubleTime,
  76. // SchedulerType,
  77. // SchedulerHandle,
  78. // HierarchicalGraphManager <
  79. // SchedulerHandle,
  80. // HierarchicalGraphBuilder >,
  81. // paradevs::common::NoParameters,
  82. // paradevs::common::NoParameters >
  83. // > rc(0, 100, "root", NoParameters(), NoParameters());
  84. // rc.run();
  85. }
  86. void parallel_partitionning_heap_test(double duration,
  87. int cluster_number,
  88. std::string partitioning_method_name,
  89. int contraction_coef,
  90. bool contraction_coef_flag)
  91. {
  92. RootCoordinator <
  93. DoubleTime,
  94. paradevs::pdevs::multithreading::Coordinator <
  95. DoubleTime,
  96. SchedulerType,
  97. SchedulerHandle,
  98. ParallelHeapHierarchicalGraphManager <
  99. SchedulerHandle,
  100. PartitioningGraphBuilder >,
  101. paradevs::common::NoParameters,
  102. PartitioningParameters >
  103. > rc(0, duration, "root", NoParameters(),
  104. PartitioningParameters(cluster_number, partitioning_method_name,
  105. contraction_coef, contraction_coef_flag));
  106. rc.run();
  107. }
  108. void partitionning_heap_test(double duration,
  109. int cluster_number,
  110. std::string partitioning_method_name,
  111. int contraction_coef,
  112. bool contraction_coef_flag)
  113. {
  114. RootCoordinator <
  115. DoubleTime,
  116. paradevs::pdevs::Coordinator <
  117. DoubleTime,
  118. SchedulerType,
  119. SchedulerHandle,
  120. HeapHierarchicalGraphManager <
  121. SchedulerHandle,
  122. PartitioningGraphBuilder >,
  123. paradevs::common::NoParameters,
  124. PartitioningParameters >
  125. > rc(0, duration, "root", NoParameters(),
  126. PartitioningParameters(cluster_number, partitioning_method_name,
  127. contraction_coef, contraction_coef_flag));
  128. rc.run();
  129. }
  130. void partitionning_vector_test(double duration,
  131. int cluster_number,
  132. std::string partitioning_method_name,
  133. int contraction_coef,
  134. bool contraction_coef_flag)
  135. {
  136. RootCoordinator <
  137. DoubleTime,
  138. paradevs::pdevs::Coordinator <
  139. DoubleTime,
  140. paradevs::common::scheduler::VectorScheduler <
  141. paradevs::common::DoubleTime >,
  142. paradevs::common::scheduler::NoSchedulerHandle,
  143. VectorHierarchicalGraphManager <
  144. paradevs::common::scheduler::NoSchedulerHandle,
  145. PartitioningGraphBuilder >,
  146. paradevs::common::NoParameters,
  147. PartitioningParameters >
  148. > rc(0, duration, "root", NoParameters(),
  149. PartitioningParameters(cluster_number, partitioning_method_name,
  150. contraction_coef, contraction_coef_flag));
  151. rc.run();
  152. }
  153. void test(double duration, std::string partitioning_method_name,
  154. unsigned int min, unsigned int max, unsigned int step,
  155. bool vector, bool heap,
  156. int contraction_coef,
  157. bool contraction_coef_flag)
  158. {
  159. boost::timer t;
  160. std::cout << "==== " << partitioning_method_name << " with ";
  161. if (contraction_coef_flag) {
  162. std::cout << "/";
  163. }
  164. std::cout << contraction_coef << " ===" << std::endl;
  165. std::cout << "n";
  166. if (heap) {
  167. std::cout << "\t heap";
  168. }
  169. if (vector) {
  170. std::cout << "\t vector";
  171. }
  172. std::cout << std::endl;
  173. if (contraction_coef_flag) {
  174. for (unsigned int n = min; n <= max; n += step) {
  175. std::cout << n << "\t";
  176. if (heap) {
  177. double t1 = t.elapsed();
  178. for (unsigned int i = 0; i < 20; ++i) {
  179. partitionning_heap_test(duration, n,
  180. partitioning_method_name,
  181. contraction_coef,
  182. contraction_coef_flag);
  183. }
  184. double t2 = t.elapsed();
  185. std::cout << (t2 - t1) / 20 << "\t";
  186. }
  187. if (vector) {
  188. double t1 = t.elapsed();
  189. for (unsigned int i = 0; i < 20; ++i) {
  190. partitionning_vector_test(duration, n,
  191. partitioning_method_name,
  192. contraction_coef,
  193. contraction_coef_flag);
  194. }
  195. double t2 = t.elapsed();
  196. std::cout << (t2 - t1) / 20 << std::endl;
  197. } else {
  198. std::cout << std::endl;
  199. }
  200. }
  201. } else {
  202. std::cout << contraction_coef << "\t";
  203. if (heap) {
  204. double t1 = t.elapsed();
  205. for (unsigned int i = 0; i < 20; ++i) {
  206. partitionning_heap_test(duration, contraction_coef,
  207. partitioning_method_name,
  208. contraction_coef,
  209. contraction_coef_flag);
  210. }
  211. double t2 = t.elapsed();
  212. std::cout << (t2 - t1) / 20 << "\t";
  213. }
  214. if (vector) {
  215. double t1 = t.elapsed();
  216. for (unsigned int i = 0; i < 20; ++i) {
  217. partitionning_vector_test(duration, contraction_coef,
  218. partitioning_method_name,
  219. contraction_coef,
  220. contraction_coef_flag);
  221. }
  222. double t2 = t.elapsed();
  223. std::cout << (t2 - t1) / 20 << std::endl;
  224. } else {
  225. std::cout << std::endl;
  226. }
  227. }
  228. }
  229. void test_flat_38()
  230. {
  231. boost::timer t;
  232. std::cout << "== 38 nodes ==" << std::endl;
  233. std::cout << "flat graph with heap = ";
  234. for (unsigned int i = 0; i < 20; ++i) {
  235. flat_heap_test< FlatGraphBuilder >(10000);
  236. }
  237. double t2 = t.elapsed();
  238. std::cout << t2 / 20 << std::endl;
  239. std::cout << "flat graph with vector = ";
  240. for (unsigned int i = 0; i < 20; ++i) {
  241. flat_vector_test< FlatGraphBuilder >(10000);
  242. }
  243. double t3 = t.elapsed();
  244. std::cout << (t3 - t2) / 20 << std::endl;
  245. }
  246. const double duration_38 = -1;
  247. void test_partiotining_38()
  248. {
  249. for (int i = 1; i <= 2; ++i) {
  250. test(duration_38, "ggp", 2, 16, 2, true, true, i, true);
  251. test(duration_38, "gggp_pond", 2, 16, 2, true, true, i, true);
  252. test(duration_38, "random", 2, 16, 2, true, true, i, true);
  253. }
  254. for (int i = 2; i <= 8; i += 2) {
  255. test(duration_38, "gggp_pond", 0, 0, 0, true, true, i, false);
  256. }
  257. }
  258. const double corsen_duration = 20;
  259. void test_flat_corsen()
  260. {
  261. boost::timer t;
  262. std::cout << "== CORSEN == " << std::endl;
  263. std::cout << "flat graph with heap = ";
  264. for (unsigned int i = 0; i < 20; ++i) {
  265. flat_heap_test< CorsenFlatGraphBuilder >(corsen_duration);
  266. }
  267. double t2 = t.elapsed();
  268. std::cout << t2 / 20 << std::endl;
  269. // std::cout << "flat graph with vector = ";
  270. // for (unsigned int i = 0; i < 20; ++i) {
  271. // flat_vector_test< CorsenFlatGraphBuilder >(corsen_duration);
  272. // }
  273. // double t3 = t.elapsed();
  274. // std::cout << (t3 - t2) / 20 << std::endl;
  275. }
  276. void test_partitioning_corsen()
  277. {
  278. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 10, true);
  279. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 20, true);
  280. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 40, true);
  281. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 80, true);
  282. test(corsen_duration, "gggp_pond", 2, 22, 2, false, true, 200, true);
  283. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 30, false);
  284. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 40, false);
  285. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 50, false);
  286. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 60, false);
  287. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 70, false);
  288. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 80, false);
  289. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 90, false);
  290. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 100, false);
  291. test(corsen_duration, "ggp", 2, 32, 2, false, true, 10, true);
  292. test(corsen_duration, "ggp", 2, 32, 2, false, true, 20, true);
  293. test(corsen_duration, "ggp", 2, 32, 2, false, true, 40, true);
  294. test(corsen_duration, "ggp", 2, 32, 2, false, true, 80, true);
  295. test(corsen_duration, "ggp", 2, 22, 2, false, true, 200, true);
  296. test(corsen_duration, "ggp", 2, 32, 2, false, true, 30, false);
  297. test(corsen_duration, "ggp", 2, 32, 2, false, true, 40, false);
  298. test(corsen_duration, "ggp", 2, 32, 2, false, true, 50, false);
  299. test(corsen_duration, "ggp", 2, 32, 2, false, true, 60, false);
  300. test(corsen_duration, "ggp", 2, 32, 2, false, true, 70, false);
  301. test(corsen_duration, "ggp", 2, 32, 2, false, true, 80, false);
  302. test(corsen_duration, "ggp", 2, 32, 2, false, true, 90, false);
  303. test(corsen_duration, "ggp", 2, 32, 2, false, true, 100, false);
  304. test(corsen_duration, "random", 2, 32, 2, false, true, 10, true);
  305. test(corsen_duration, "random", 2, 32, 2, false, true, 20, true);
  306. test(corsen_duration, "random", 2, 32, 2, false, true, 40, true);
  307. test(corsen_duration, "random", 2, 32, 2, false, true, 80, true);
  308. test(corsen_duration, "random", 2, 22, 2, false, true, 200, true);
  309. }
  310. int main()
  311. {
  312. srand(7262);
  313. // test_flat_38();
  314. // test_partiotining_38();
  315. test_flat_corsen();
  316. test_partitioning_corsen();
  317. return 0;
  318. }