1 /* 2 Copyright (c) 2005-2021 Intel Corporation 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 //! \file test_hw_concurrency.cpp 18 //! \brief Test for [internal] specifications 19 20 #include "common/config.h" 21 #include "common/test.h" 22 #include "common/utils.h" 23 #if !__TBB_TEST_SKIP_AFFINITY 24 #include "common/utils_concurrency_limit.h" 25 #include "tbb/global_control.h" 26 #include "tbb/enumerable_thread_specific.h" 27 #include "tbb/task_arena.h" 28 #include "tbb/concurrent_vector.h" 29 #include "tbb/concurrent_queue.h" 30 #include "tbb/concurrent_priority_queue.h" 31 #include "tbb/concurrent_hash_map.h" 32 #include "tbb/concurrent_unordered_map.h" 33 #include "tbb/concurrent_unordered_set.h" 34 #include "tbb/concurrent_map.h" 35 #include "tbb/concurrent_set.h" 36 #include "tbb/cache_aligned_allocator.h" 37 #include "tbb/scalable_allocator.h" 38 #include "tbb/tbb_allocator.h" 39 #include "tbb/null_mutex.h" 40 #include "tbb/null_rw_mutex.h" 41 #include "tbb/queuing_mutex.h" 42 #include "tbb/queuing_rw_mutex.h" 43 #include "tbb/spin_mutex.h" 44 #include "tbb/spin_rw_mutex.h" 45 #include "tbb/tick_count.h" 46 #include "tbb/combinable.h" 47 #include "tbb/blocked_range.h" 48 #include "tbb/blocked_range2d.h" 49 #include "tbb/blocked_range3d.h" 50 #define TBB_PREVIEW_BLOCKED_RANGE_ND 1 51 #include "tbb/blocked_rangeNd.h" 52 53 // Declaration of global objects are needed to check that 54 // it does not initialize the task scheduler, and in particular 55 // does not set the default thread number. 56 // TODO: add other objects that should not initialize the scheduler. 57 tbb::enumerable_thread_specific<std::size_t> ets; 58 using vector_ets_type = tbb::enumerable_thread_specific<std::vector<std::size_t>>; 59 vector_ets_type vets; 60 tbb::flattened2d<vector_ets_type> f2d(vets); 61 tbb::combinable<std::size_t> comb; 62 tbb::concurrent_vector<std::size_t> cv; 63 tbb::concurrent_queue<std::size_t> cq; 64 tbb::concurrent_bounded_queue<std::size_t> cbq; 65 tbb::concurrent_priority_queue<std::size_t> test_cpq; 66 tbb::concurrent_hash_map<std::size_t, std::size_t> chmap; 67 tbb::concurrent_unordered_map<std::size_t, std::size_t> cumap; 68 tbb::concurrent_unordered_multimap<std::size_t, std::size_t> cummap; 69 tbb::concurrent_unordered_set<std::size_t> cuset; 70 tbb::concurrent_unordered_multiset<std::size_t> cumset; 71 tbb::concurrent_map<std::size_t, std::size_t> cmap; 72 tbb::concurrent_multimap<std::size_t, std::size_t> cmmap; 73 tbb::concurrent_set<std::size_t> cset; 74 tbb::concurrent_multiset<std::size_t> cmset; 75 tbb::cache_aligned_allocator<std::size_t> caa; 76 tbb::scalable_allocator<std::size_t> sa; 77 tbb::tbb_allocator<std::size_t> ta; 78 tbb::null_mutex nm; 79 tbb::null_rw_mutex nrwm; 80 tbb::queuing_mutex qm; 81 tbb::queuing_rw_mutex qrwm; 82 tbb::spin_mutex sm; 83 tbb::spin_rw_mutex srwm; 84 tbb::speculative_spin_mutex ssm; 85 tbb::speculative_spin_rw_mutex ssrwm; 86 tbb::tick_count test_tc; 87 tbb::blocked_range<std::size_t> br(0, 1); 88 tbb::blocked_range2d<std::size_t> br2d(0, 1, 0, 1); 89 tbb::blocked_range3d<std::size_t> br3d(0, 1, 0, 1, 0, 1); 90 tbb::blocked_rangeNd<std::size_t, 2> brNd({0, 1}, {0, 1}); 91 92 //! \brief \ref error_guessing 93 TEST_CASE("Check absence of scheduler initialization") { 94 int maxProcs = utils::get_max_procs(); 95 96 if (maxProcs >= 2) { 97 int availableProcs = maxProcs / 2; 98 REQUIRE_MESSAGE(utils::limit_number_of_threads(availableProcs) == availableProcs, "limit_number_of_threads has not set the requested limitation"); 99 REQUIRE(tbb::this_task_arena::max_concurrency() == availableProcs); 100 } 101 } 102 103 #endif // !__TBB_TEST_SKIP_AFFINITY 104