/* Copyright (c) 2005-2021 Intel Corporation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ //! \file test_hw_concurrency.cpp //! \brief Test for [internal] specifications #include "common/config.h" #include "common/test.h" #include "common/utils.h" #if !__TBB_TEST_SKIP_AFFINITY #include "common/utils_concurrency_limit.h" #include "tbb/global_control.h" #include "tbb/enumerable_thread_specific.h" #include "tbb/task_arena.h" #include "tbb/concurrent_vector.h" #include "tbb/concurrent_queue.h" #include "tbb/concurrent_priority_queue.h" #include "tbb/concurrent_hash_map.h" #include "tbb/concurrent_unordered_map.h" #include "tbb/concurrent_unordered_set.h" #include "tbb/concurrent_map.h" #include "tbb/concurrent_set.h" #include "tbb/cache_aligned_allocator.h" #include "tbb/scalable_allocator.h" #include "tbb/tbb_allocator.h" #include "tbb/null_mutex.h" #include "tbb/null_rw_mutex.h" #include "tbb/queuing_mutex.h" #include "tbb/queuing_rw_mutex.h" #include "tbb/spin_mutex.h" #include "tbb/spin_rw_mutex.h" #include "tbb/tick_count.h" #include "tbb/combinable.h" #include "tbb/blocked_range.h" #include "tbb/blocked_range2d.h" #include "tbb/blocked_range3d.h" #define TBB_PREVIEW_BLOCKED_RANGE_ND 1 #include "tbb/blocked_rangeNd.h" // Declaration of global objects are needed to check that // it does not initialize the task scheduler, and in particular // does not set the default thread number. // TODO: add other objects that should not initialize the scheduler. tbb::enumerable_thread_specific ets; using vector_ets_type = tbb::enumerable_thread_specific>; vector_ets_type vets; tbb::flattened2d f2d(vets); tbb::combinable comb; tbb::concurrent_vector cv; tbb::concurrent_queue cq; tbb::concurrent_bounded_queue cbq; tbb::concurrent_priority_queue test_cpq; tbb::concurrent_hash_map chmap; tbb::concurrent_unordered_map cumap; tbb::concurrent_unordered_multimap cummap; tbb::concurrent_unordered_set cuset; tbb::concurrent_unordered_multiset cumset; tbb::concurrent_map cmap; tbb::concurrent_multimap cmmap; tbb::concurrent_set cset; tbb::concurrent_multiset cmset; tbb::cache_aligned_allocator caa; tbb::scalable_allocator sa; tbb::tbb_allocator ta; tbb::null_mutex nm; tbb::null_rw_mutex nrwm; tbb::queuing_mutex qm; tbb::queuing_rw_mutex qrwm; tbb::spin_mutex sm; tbb::spin_rw_mutex srwm; tbb::speculative_spin_mutex ssm; tbb::speculative_spin_rw_mutex ssrwm; tbb::tick_count test_tc; tbb::blocked_range br(0, 1); tbb::blocked_range2d br2d(0, 1, 0, 1); tbb::blocked_range3d br3d(0, 1, 0, 1, 0, 1); tbb::blocked_rangeNd brNd({0, 1}, {0, 1}); //! \brief \ref error_guessing TEST_CASE("Check absence of scheduler initialization") { int maxProcs = utils::get_max_procs(); if (maxProcs >= 2) { int availableProcs = maxProcs / 2; REQUIRE_MESSAGE(utils::limit_number_of_threads(availableProcs) == availableProcs, "limit_number_of_threads has not set the requested limitation"); REQUIRE(tbb::this_task_arena::max_concurrency() == availableProcs); } } #endif // !__TBB_TEST_SKIP_AFFINITY