Created
April 23, 2018 15:05
-
-
Save chiroptical/e70df4df597d0a41c21620507a46b32d to your computer and use it in GitHub Desktop.
Parallel STL Test with Intel Parallel Studio 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment