21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include <boost/mpl/list.hpp>
26 #include "core/thread_pool_sequential.hpp"
27 #include "core/thread_pool_workers.hpp"
29 #include <boost/graph/graphviz.hpp>
34 using namespace libjmmcg;
40 struct erew_normal_fifo_t {
64 struct erew_normal_lifo_t {
88 struct erew_priority_queue_t {
211 typedef boost::mpl::list<
212 erew_normal_fifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>,
213 erew_normal_lifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>,
214 crew_normal_fifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>,
215 crew_normal_lifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>,
216 crew_normal_lifo_lockfree_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>,
217 crew_normal_lifo_lockfree_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::thread_owns_queue<pool_traits::work_distribution_mode_t::queue_model_t::stealing_mode_t::random>>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 1>
218 > dataflow_ps1_test_types;
220 typedef boost::mpl::list<
221 erew_normal_fifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 12>,
222 erew_normal_lifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 12>,
223 crew_normal_fifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 12>,
224 crew_normal_lifo_t<pool_traits::work_distribution_mode_t::worker_threads_get_work<pool_traits::work_distribution_mode_t::queue_model_t::pool_owns_queue>, pool_traits::size_mode_t::fixed_size, generic_traits::return_data::joinable, heavyweight_threading, 12>
226 > dataflow_ps12_test_types;
234 constexpr bool __fastcall operator<(
trivial_work const &)
const noexcept(
true) {
259 constexpr bool __fastcall operator<(
recusive_work const &)
const noexcept(
true) {
282 constexpr bool __fastcall operator<(
pool_1ctx_work const &)
const noexcept(
true) {
289 BOOST_AUTO_TEST_SUITE(thread_pool_tests)
291 BOOST_AUTO_TEST_SUITE(joinable_dataflow)
293 BOOST_AUTO_TEST_SUITE(finite)
295 BOOST_AUTO_TEST_SUITE(n_elements)
318 BOOST_AUTO_TEST_CASE_TEMPLATE(single_vertical_dataflow_operations_rate, T, dataflow_ps1_test_types) {
319 typedef typename T::pool_type pool_type;
321 #ifdef JMMCG_PERFORMANCE_TESTS
322 const unsigned long test_size=2<<9;
323 const unsigned long num_reps=20000;
325 const unsigned long test_size=2<<3;
326 const unsigned long num_reps=2;
328 pool_type pool(T::pool_size);
329 BOOST_CHECK_EQUAL(pool.pool_size(), 1UL);
330 std::cout<<
"Pool="<<pool.pool_size()<<
std::flush;
331 const std::pair<timed_results_t,
bool> timed_results(compute_average_deviation<timed_results_t::value_type>(
335 typedef typename pool_type::joinable joinable;
337 const auto t1=std::chrono::high_resolution_clock::now();
338 for (
unsigned long num_loops=0;num_loops<test_size;++num_loops) {
339 auto const &context=pool<<joinable()<<trivial_work();
342 const auto t2=std::chrono::high_resolution_clock::now();
343 return timed_results_t::value_type(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count());
346 std::cout<<
", time taken: "<<timed_results.first<<
" usec."<<std::endl;
347 const double rescale=1.0/(test_size*pool.pool_size());
348 std::cout<<
"Vertical dataflow transfer took (usec): "<<rescale*timed_results.first.arithmetic_mean()<<std::endl;
349 std::cout<<pool.statistics()<<
std::endl;
350 #ifdef JMMCG_PERFORMANCE_TESTS
351 BOOST_CHECK(!timed_results.second);
422 BOOST_AUTO_TEST_CASE_TEMPLATE(vertical_dataflow_operations_rate, T, dataflow_ps12_test_types) {
423 typedef typename T::pool_type pool_type;
425 #ifdef JMMCG_PERFORMANCE_TESTS
426 const unsigned long test_size=2<<10;
427 const unsigned long num_reps=1000;
429 const unsigned long test_size=2<<3;
430 const unsigned long num_reps=2;
433 pool_type pool(T::pool_size);
434 BOOST_CHECK_EQUAL(pool.pool_size(), 12UL);
435 std::cout<<
"Pool="<<pool.pool_size()<<
std::flush;
436 const std::pair<timed_results_t,
bool> timed_results(compute_average_deviation<timed_results_t::value_type>(
440 typedef typename pool_type::joinable joinable;
442 const auto t1=std::chrono::high_resolution_clock::now();
443 for (
unsigned long num_loops=0;num_loops<test_size;++num_loops) {
444 auto const &context1=pool<<joinable()<<trivial_work();
445 auto const &context2=pool<<joinable()<<trivial_work();
446 auto const &context3=pool<<joinable()<<trivial_work();
447 auto const &context4=pool<<joinable()<<trivial_work();
448 auto const &context5=pool<<joinable()<<trivial_work();
449 auto const &context6=pool<<joinable()<<trivial_work();
450 auto const &context7=pool<<joinable()<<trivial_work();
451 auto const &context8=pool<<joinable()<<trivial_work();
452 auto const &context9=pool<<joinable()<<trivial_work();
453 auto const &context10=pool<<joinable()<<trivial_work();
454 auto const &context11=pool<<joinable()<<trivial_work();
455 auto const &context12=pool<<joinable()<<trivial_work();
469 const auto t2=std::chrono::high_resolution_clock::now();
470 return timed_results_t::value_type(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count());
473 std::cout<<
", time taken: "<<timed_results.first<<
" usec."<<std::endl;
474 const double rescale=1.0/(test_size*pool.pool_size());
475 std::cout<<
"Vertical dataflow transfer took (usec): "<<rescale*timed_results.first.arithmetic_mean()<<std::endl;
476 std::cout<<pool.statistics()<<
std::endl;
477 #ifdef JMMCG_PERFORMANCE_TESTS
478 BOOST_CHECK(!timed_results.second);
499 BOOST_AUTO_TEST_CASE_TEMPLATE(horizontal_dataflow_transfers_rate, T, dataflow_ps12_test_types) {
500 typedef typename T::pool_type pool_type;
503 #ifdef JMMCG_PERFORMANCE_TESTS
504 const unsigned long test_size=2<<13;
505 const unsigned long num_reps=20000;
506 const unsigned long test_depth=3;
508 const unsigned long test_size=2<<3;
509 const unsigned long num_reps=2;
510 const unsigned long test_depth=1;
512 pool_type pool(T::pool_size);
513 std::cout<<
"Pool="<<pool.pool_size()<<
std::flush;
514 const std::pair<timed_results_t,
bool> timed_results(compute_average_deviation<timed_results_t::value_type>(
518 typedef typename pool_type::joinable joinable;
519 typedef recusive_work<pool_type> work_type;
521 const unsigned long test_size=1<<6;
522 const auto t1=std::chrono::high_resolution_clock::now();
523 for (
unsigned long num_loops=0;num_loops<test_size;++num_loops) {
524 auto const &context=pool<<joinable()<<work_type(test_depth, pool);
527 const auto t2=std::chrono::high_resolution_clock::now();
528 return timed_results_t::value_type(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count());
531 std::cout<<
", time taken: "<<timed_results.first<<
" usec."<<std::endl;
532 const double rescale=1.0/(test_size*pool.pool_size());
533 std::cout<<
"Tree-constructions transfer took (usec): "<<rescale*timed_results.first.arithmetic_mean()<<std::endl;
534 std::cout<<pool.statistics()<<
std::endl;
535 #ifdef JMMCG_PERFORMANCE_TESTS
536 BOOST_CHECK(!timed_results.second);
540 BOOST_AUTO_TEST_SUITE_END()
542 BOOST_AUTO_TEST_SUITE_END()
544 BOOST_AUTO_TEST_SUITE_END()
546 BOOST_AUTO_TEST_SUITE_END()