I was writing a basic program (that sorts an integer vector 'list' using the parallel execution policy)-
#include <iostream>
#include <execution>
#include <algorithm>
#include <chrono>
#include <vector>
int main()
{
std::vector<int> list {0,1,2,3,4,5};
auto start = std::chrono::high_resolution_clock::now();
std::sort(std::execution::par, list.begin(), list.end());
auto end = std::chrono::high_resolution_clock::now();
std::cout << "time taken : " << std::chrono::duration<float>(end - start).count() << " s" << std::endl;
return 0;
}
When i build this program, an error was generated:
/home/test.cpp:12:18: error: ‘std::execution’ has not been declared
12 | std::sort(std::execution::par, list.begin(), list.end());
| ^~~~~~~~~
The terminal process "/bin/bash '-c', '/usr/bin/g++ -g '/home/test.cpp' -o '/home/test''" terminated with exit code: 1.
I am using Visual Studio Code running C++17 with gcc 9.3.0 as my compiler. I am using Linux mint 20 as my OS. Please bear in mind that i am still new to Linux, VSCode, GCC/G++ and C++17 and so I could be missing some information.
Could anyone tell me what could be done, and/or where I am wrong?
EDIT: I had checked the definition of std::execution
, and i saw this -
#ifndef __PSTL_glue_execution_defs_H
#define __PSTL_glue_execution_defs_H
#include <type_traits>
#include "execution_defs.h"
namespace std
{
// Type trait
using __pstl::execution::is_execution_policy;
#if __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
#if __INTEL_COMPILER
template <class T>
constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
#else
using __pstl::execution::is_execution_policy_v;
#endif
#endif
namespace execution
{
// Standard C++ policy classes
using __pstl::execution::sequenced_policy;
#if __PSTL_USE_PAR_POLICIES
using __pstl::execution::parallel_policy;
using __pstl::execution::parallel_unsequenced_policy;
#endif
// Standard predefined policy instances
using __pstl::execution::seq;
#if __PSTL_USE_PAR_POLICIES
using __pstl::execution::par;
using __pstl::execution::par_unseq;
#endif
// Implementation-defined names
// Unsequenced policy is not yet standard, but for consistency
// we include it into namespace std::execution as well
using __pstl::execution::unseq;
using __pstl::execution::unsequenced_policy;
} // namespace execution
} // namespace std
#include "algorithm_impl.h"
#include "numeric_impl.h"
#include "parallel_backend.h"
#endif /* __PSTL_glue_execution_defs_H */