- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All,
So, I wanted to try out some of the new C++17 parallel algorithms and luckily I have access to Parallel Studio 2018. Compiled the following code:
#include <vector> #include <iostream> #include "pstl/execution" #include "pstl/algorithm" #include "pstl/numeric" #include "pstl/memory" int main() { // 1,000,000 double vector with 1/2 std::vector<double> v(1'000'000); std::fill(std::execution::par_unseq, v.begin(), v.end(), 0.5); // Reduction auto result = std::reduce(std::execution::par, v.begin(), v.end(), 0.0); std::cout << "Result: " << result << "\n"; return 0; }
If I run it through vtune, I see it uses the 12 threads on my machine. I did a little googling, but I don't see how I restrict the number of threads this code uses. I saw some ancient suggestions of TBB_NUM_THREADS but that doesn't appear to change anything. How do I control the number of threads if I wanted to run PSTL code in my HPC scheduler?
Thanks.
Barry
- Tags:
- CC++
- Development Tools
- Intel® C++ Compiler
- Intel® Parallel Studio XE
- Intel® System Studio
- Optimization
- Parallel Computing
- Vectorization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
you can use either tbb::task_scheduler_init object
https://software.intel.com/en-us/node/506296
or task_arena class
https://software.intel.com/sites/default/files/managed/6a/78/parallel_mag_issue18.pdf, pages 24-25
Vladimir
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
you can use either tbb::task_scheduler_init object
https://software.intel.com/en-us/node/506296
or task_arena class
https://software.intel.com/sites/default/files/managed/6a/78/parallel_mag_issue18.pdf, pages 24-25
Vladimir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Vladimir,
Entire code with your suggestion:
#include <cstdlib> #include <iostream> #include <vector> #include <sstream> #include "pstl/execution" #include "pstl/algorithm" #include "pstl/numeric" #include "pstl/memory" #include "tbb/task_scheduler_init.h" int main() { // Init TBB Threads int pstl_num_threads; if (auto pstl_num_threads_ca = std::getenv("PSTL_NUM_THREADS")) { std::istringstream iss(pstl_num_threads_ca); iss >> pstl_num_threads; } else { pstl_num_threads = tbb::task_scheduler_init::default_num_threads(); } std::cout << "PSTL_NUM_THREADS: " << pstl_num_threads << '\n'; tbb::task_scheduler_init init(pstl_num_threads); // 10,000 double vector with 1/2 std::vector<double> v(1'000'000); std::fill(std::execution::par_unseq, v.begin(), v.end(), 0.5); // Reduction auto result = std::reduce(std::execution::par, v.begin(), v.end(), 0.0); std::cout << "Result: " << result << "\n"; return 0; }
Hope it helps someone else. Thanks.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page