std::execution::par
the following program comes from C++20 for Programmers: ... a Deitel book
// fig17_01.cpp
// Profiling sequential and parallel sorting with the std::sort algorithm.
#include
#include // for timing operations
#include // for execution policies
#include
#include
#include
#include
int main()
{
// set up random-number generation
std::random_device rd;
std::default_random_engine engine{rd()};
std::uniform_int_distribution ints{};
std::cout << "Creating a vector v1 to hold 100,000,000 ints\n";
std::vector v1(100'000'000); // 100,000,000 element vector
std::cout << "Filling vector v1 with random ints\n";
std::generate( v1.begin(), v1.end(), [&] (){ return ints(engine); } );
// copy v1 to create identical data sets for each sort demonstration
std::cout << "Copying v1 to vector v2 to create identical data sets\n";
std::vector v2{v1};
// library features we'll use for timing
using std::chrono::steady_clock;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
// sequentially sort v1
std::cout << "\nSorting 100,000,000 ints sequentially\n";
auto start1 { steady_clock::now() }; // get current time
std::sort( v1.begin(), v1.end() ); // sequential sort
auto end1 { steady_clock::now() }; // get current time
// calculate and display time in milliseconds
auto time1{ duration_cast(end1 - start1) };
std::cout << "Time: " << ( time1.count() / 1000.0 ) << " seconds\n";
// parallel sort v2
std::cout << "\nSorting the same 100,000,000 ints in parallel\n";
auto start2 { steady_clock::now() }; // get current time
std::sort(std::execution::par, v2.begin(), v2.end()); // parallel sort
auto end2 { steady_clock::now() }; // get current time
// calculate and display time in milliseconds
auto time2{duration_cast(end2 - start2)};
std::cout << "Time: " << (time2.count() / 1000.0) << " seconds\n";
}
will not compile. compiler does not find std::execution, and the of course does not find the method str::execution::par
has that header not been added or has it been removed?
Selecting any option will automatically load the page