tests.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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_generator.hpp>
  30. #include <tests/boost_graph/graph_manager.hpp>
  31. #include <tests/boost_graph/graph_partitioning.hpp>
  32. using namespace paradevs::common;
  33. using namespace paradevs::common::scheduler;
  34. using namespace paradevs::pdevs;
  35. using namespace paradevs::tests::boost_graph;
  36. template < class GraphBuilder >
  37. void flat_heap_test(double duration)
  38. {
  39. RootCoordinator <
  40. DoubleTime,
  41. paradevs::pdevs::Coordinator <
  42. DoubleTime,
  43. SchedulerType,
  44. SchedulerHandle,
  45. InBuildFlatGraphManager <
  46. SchedulerHandle,
  47. GraphBuilder >,
  48. paradevs::common::NoParameters,
  49. paradevs::common::NoParameters >
  50. > rc(0, duration, "root", NoParameters(), NoParameters());
  51. rc.run();
  52. }
  53. /*template < class GraphBuilder >
  54. void flat_vector_test(double duration)
  55. {
  56. RootCoordinator <
  57. DoubleTime,
  58. paradevs::pdevs::Coordinator <
  59. DoubleTime,
  60. paradevs::common::scheduler::VectorScheduler <
  61. paradevs::common::DoubleTime >,
  62. paradevs::common::scheduler::NoSchedulerHandle,
  63. InBuildFlatGraphManager <
  64. paradevs::common::scheduler::NoSchedulerHandle,
  65. GraphBuilder >,
  66. paradevs::common::NoParameters,
  67. paradevs::common::NoParameters >
  68. > rc(0, duration, "root", NoParameters(), NoParameters());
  69. rc.run();
  70. }*/
  71. void hierarchical_test()
  72. {
  73. // RootCoordinator <
  74. // DoubleTime,
  75. // paradevs::pdevs::Coordinator <
  76. // DoubleTime,
  77. // SchedulerType,
  78. // SchedulerHandle,
  79. // HierarchicalGraphManager <
  80. // SchedulerHandle,
  81. // HierarchicalGraphBuilder >,
  82. // paradevs::common::NoParameters,
  83. // paradevs::common::NoParameters >
  84. // > rc(0, 100, "root", NoParameters(), NoParameters());
  85. // rc.run();
  86. }
  87. /*void parallel_partitionning_heap_test(double duration,
  88. int cluster_number,
  89. std::string partitioning_method_name,
  90. int contraction_coef,
  91. bool contraction_coef_flag)
  92. {
  93. RandomGraphGenerator g(2000);
  94. RootCoordinator <
  95. DoubleTime,
  96. paradevs::pdevs::multithreading::Coordinator <
  97. DoubleTime,
  98. SchedulerType,
  99. SchedulerHandle,
  100. ParallelHeapHierarchicalGraphManager <
  101. SchedulerHandle,
  102. PartitioningGraphBuilder >,
  103. paradevs::common::NoParameters,
  104. PartitioningParameters >
  105. > rc(0, duration, "root", NoParameters(),
  106. PartitioningParameters(cluster_number, partitioning_method_name,
  107. contraction_coef, contraction_coef_flag, &g));
  108. rc.run();
  109. }*/
  110. void partitionning_heap_test(double duration,
  111. int cluster_number,
  112. std::string partitioning_method_name,
  113. int contraction_coef,
  114. bool contraction_coef_flag)
  115. {
  116. std::vector<int> niveau;
  117. niveau.push_back(4);
  118. niveau.push_back(3);
  119. niveau.push_back(2);
  120. RandomGraphGenerator g(2000, niveau, 5, 2, 4);
  121. //ArtificialGraphGenerator g(38);
  122. //CorsenGraphGenerator g;
  123. RootCoordinator <
  124. DoubleTime,
  125. paradevs::pdevs::Coordinator <
  126. DoubleTime,
  127. SchedulerType,
  128. SchedulerHandle,
  129. HeapHierarchicalGraphManager <
  130. SchedulerHandle,
  131. PartitioningGraphBuilder>,
  132. paradevs::common::NoParameters,
  133. PartitioningParameters >
  134. > rc(0, duration, "root", NoParameters(),
  135. PartitioningParameters(cluster_number, partitioning_method_name,
  136. contraction_coef, contraction_coef_flag,
  137. &g));
  138. rc.run();
  139. }
  140. /*void partitionning_vector_test(double duration,
  141. int cluster_number,
  142. std::string partitioning_method_name,
  143. int contraction_coef,
  144. bool contraction_coef_flag)
  145. {
  146. RandomGraphGenerator g(2000);
  147. RootCoordinator <
  148. DoubleTime,
  149. paradevs::pdevs::Coordinator <
  150. DoubleTime,
  151. paradevs::common::scheduler::VectorScheduler <
  152. paradevs::common::DoubleTime >,
  153. paradevs::common::scheduler::NoSchedulerHandle,
  154. VectorHierarchicalGraphManager <
  155. paradevs::common::scheduler::NoSchedulerHandle,
  156. PartitioningGraphBuilder >,
  157. paradevs::common::NoParameters,
  158. PartitioningParameters >
  159. > rc(0, duration, "root", NoParameters(),
  160. PartitioningParameters(cluster_number, partitioning_method_name,
  161. contraction_coef, contraction_coef_flag, &g));
  162. rc.run();
  163. }*/
  164. void test(double duration, std::string partitioning_method_name,
  165. unsigned int min, unsigned int max, unsigned int step,
  166. bool vector, bool heap,
  167. int contraction_coef,
  168. bool contraction_coef_flag)
  169. {
  170. boost::timer t;
  171. std::cout << "==== " << partitioning_method_name << " with ";
  172. if (contraction_coef_flag) {
  173. std::cout << "/";
  174. }
  175. std::cout << contraction_coef << " ===" << std::endl;
  176. std::cout << "n";
  177. if (heap) {
  178. std::cout << "\t heap";
  179. }
  180. if (vector) {
  181. std::cout << "\t vector";
  182. }
  183. std::cout << std::endl;
  184. if (contraction_coef_flag) {
  185. for (unsigned int n = min; n <= max; n += step) {
  186. std::cout << n << "\t";
  187. if (heap) {
  188. double t1 = t.elapsed();
  189. for (unsigned int i = 0; i < 20; ++i) {
  190. partitionning_heap_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 << "\t";
  197. }
  198. if (vector) {
  199. double t1 = t.elapsed();
  200. for (unsigned int i = 0; i < 20; ++i) {
  201. /*partitionning_vector_test(duration, n,
  202. partitioning_method_name,
  203. contraction_coef,
  204. contraction_coef_flag);*/
  205. }
  206. double t2 = t.elapsed();
  207. std::cout << (t2 - t1) / 20 << std::endl;
  208. } else {
  209. std::cout << std::endl;
  210. }
  211. }
  212. } else {
  213. std::cout << contraction_coef << "\t";
  214. if (heap) {
  215. double t1 = t.elapsed();
  216. for (unsigned int i = 0; i < 20; ++i) {
  217. partitionning_heap_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 << "\t";
  224. }
  225. if (vector) {
  226. double t1 = t.elapsed();
  227. for (unsigned int i = 0; i < 20; ++i) {
  228. /*partitionning_vector_test(duration, contraction_coef,
  229. partitioning_method_name,
  230. contraction_coef,
  231. contraction_coef_flag);*/
  232. }
  233. double t2 = t.elapsed();
  234. std::cout << (t2 - t1) / 20 << std::endl;
  235. } else {
  236. std::cout << std::endl;
  237. }
  238. }
  239. }
  240. const double duration_38 = 1000;
  241. void test_flat_38()
  242. {
  243. boost::timer t;
  244. std::cout << "== 38 nodes ==" << std::endl;
  245. std::cout << "flat graph with heap = ";
  246. for (unsigned int i = 0; i < 20; ++i) {
  247. flat_heap_test< FlatGraphBuilder >(duration_38);
  248. }
  249. double t2 = t.elapsed();
  250. std::cout << t2 / 20 << std::endl;
  251. /*std::cout << "flat graph with vector = ";
  252. for (unsigned int i = 0; i < 20; ++i) {
  253. flat_vector_test< FlatGraphBuilder >(1000);
  254. }*/
  255. double t3 = t.elapsed();
  256. std::cout << (t3 - t2) / 20 << std::endl;
  257. }
  258. void test_partiotining_38()
  259. {
  260. for (int i = 1; i <= 2; ++i) {
  261. test(duration_38, "ggp", 2, 16, 2, true, true, i, true);
  262. test(duration_38, "gggp_pond", 2, 16, 2, true, true, i, true);
  263. test(duration_38, "random", 2, 16, 2, true, true, i, true);
  264. }
  265. for (int i = 2; i <= 8; i += 2) {
  266. test(duration_38, "gggp_pond", 0, 0, 0, true, true, i, false);
  267. }
  268. }
  269. const double duration_random = 20;
  270. void test_flat_random()
  271. {
  272. boost::timer t;
  273. std::cout << "== Random Graph ==" << std::endl;
  274. std::cout << "flat graph with heap = ";
  275. for (unsigned int i = 0; i < 20; ++i) {
  276. flat_heap_test< RandomFlatGraphBuilder >(duration_random);
  277. }
  278. double t2 = t.elapsed();
  279. std::cout << t2 / 20 << std::endl;
  280. /*std::cout << "flat graph with vector = ";
  281. for (unsigned int i = 0; i < 20; ++i) {
  282. flat_vector_test< FlatGraphBuilder >(1000);
  283. }*/
  284. double t3 = t.elapsed();
  285. std::cout << (t3 - t2) / 20 << std::endl;
  286. }
  287. void test_partiotining_random()
  288. {
  289. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 5, true);
  290. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 10, true);
  291. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 20, true);
  292. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 40, true);
  293. test(duration_random, "gggp_pond", 2, 22, 2, false, true, 100, true);
  294. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 15, false);
  295. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 20, false);
  296. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 25, false);
  297. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 30, false);
  298. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 35, false);
  299. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 40, false);
  300. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 45, false);
  301. test(duration_random, "gggp_pond", 2, 32, 2, false, true, 50, false);
  302. test(duration_random, "ggp", 2, 32, 2, false, true, 5, true);
  303. test(duration_random, "ggp", 2, 32, 2, false, true, 10, true);
  304. test(duration_random, "ggp", 2, 32, 2, false, true, 20, true);
  305. test(duration_random, "ggp", 2, 32, 2, false, true, 40, true);
  306. test(duration_random, "ggp", 2, 22, 2, false, true, 100, true);
  307. test(duration_random, "ggp", 2, 32, 2, false, true, 15, false);
  308. test(duration_random, "ggp", 2, 32, 2, false, true, 20, false);
  309. test(duration_random, "ggp", 2, 32, 2, false, true, 25, false);
  310. test(duration_random, "ggp", 2, 32, 2, false, true, 30, false);
  311. test(duration_random, "ggp", 2, 32, 2, false, true, 35, false);
  312. test(duration_random, "ggp", 2, 32, 2, false, true, 40, false);
  313. test(duration_random, "ggp", 2, 32, 2, false, true, 45, false);
  314. test(duration_random, "ggp", 2, 32, 2, false, true, 50, false);
  315. test(duration_random, "random", 2, 32, 2, false, true, 5, true);
  316. test(duration_random, "random", 2, 32, 2, false, true, 10, true);
  317. test(duration_random, "random", 2, 32, 2, false, true, 20, true);
  318. test(duration_random, "random", 2, 32, 2, false, true, 40, true);
  319. test(duration_random, "random", 2, 22, 2, false, true, 100, true);
  320. }
  321. const double corsen_duration = 20;
  322. void test_flat_corsen()
  323. {
  324. boost::timer t;
  325. std::cout << "== CORSEN == " << std::endl;
  326. std::cout << "flat graph with heap = ";
  327. for (unsigned int i = 0; i < 20; ++i) {
  328. flat_heap_test< CorsenFlatGraphBuilder >(corsen_duration);
  329. }
  330. double t2 = t.elapsed();
  331. std::cout << t2 / 20 << std::endl;
  332. // std::cout << "flat graph with vector = ";
  333. // for (unsigned int i = 0; i < 20; ++i) {
  334. // flat_vector_test< CorsenFlatGraphBuilder >(corsen_duration);
  335. // }
  336. // double t3 = t.elapsed();
  337. // std::cout << (t3 - t2) / 20 << std::endl;
  338. }
  339. void test_partitioning_corsen()
  340. {
  341. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 10, true);
  342. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 20, true);
  343. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 40, true);
  344. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 80, true);
  345. test(corsen_duration, "gggp_pond", 2, 22, 2, false, true, 200, true);
  346. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 30, false);
  347. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 40, false);
  348. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 50, false);
  349. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 60, false);
  350. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 70, false);
  351. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 80, false);
  352. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 90, false);
  353. test(corsen_duration, "gggp_pond", 2, 32, 2, false, true, 100, false);
  354. test(corsen_duration, "ggp", 2, 32, 2, false, true, 10, true);
  355. test(corsen_duration, "ggp", 2, 32, 2, false, true, 20, true);
  356. test(corsen_duration, "ggp", 2, 32, 2, false, true, 40, true);
  357. test(corsen_duration, "ggp", 2, 32, 2, false, true, 80, true);
  358. test(corsen_duration, "ggp", 2, 22, 2, false, true, 200, true);
  359. test(corsen_duration, "ggp", 2, 32, 2, false, true, 30, false);
  360. test(corsen_duration, "ggp", 2, 32, 2, false, true, 40, false);
  361. test(corsen_duration, "ggp", 2, 32, 2, false, true, 50, false);
  362. test(corsen_duration, "ggp", 2, 32, 2, false, true, 60, false);
  363. test(corsen_duration, "ggp", 2, 32, 2, false, true, 70, false);
  364. test(corsen_duration, "ggp", 2, 32, 2, false, true, 80, false);
  365. test(corsen_duration, "ggp", 2, 32, 2, false, true, 90, false);
  366. test(corsen_duration, "ggp", 2, 32, 2, false, true, 100, false);
  367. test(corsen_duration, "random", 2, 32, 2, false, true, 10, true);
  368. test(corsen_duration, "random", 2, 32, 2, false, true, 20, true);
  369. test(corsen_duration, "random", 2, 32, 2, false, true, 40, true);
  370. test(corsen_duration, "random", 2, 32, 2, false, true, 80, true);
  371. test(corsen_duration, "random", 2, 22, 2, false, true, 200, true);
  372. }
  373. int main()
  374. {
  375. srand(7262);
  376. test_flat_38();
  377. test_partiotining_38();
  378. //test_flat_corsen();
  379. //test_partitioning_corsen();
  380. /*
  381. * *** Problème inconnu affiche oups lors de l'exécution (problème hors compétence) ***
  382. */
  383. test_flat_random();
  384. test_partiotining_random();
  385. return 0;
  386. }