Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execution policy in c++

Tags:

c++

algorithm

I was going through copy_If definition in cpprefrence , I saw that there are some constructs which are dependent upon execution _policy .I searched about it ,but I didn't get any good explanation . can somebody help me understand what is this and how it can be useful ?

Link : http://en.cppreference.com/w/cpp/algorithm/copy

Example :

template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2, class UnaryPredicate >
ForwardIt2 copy_if( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last,
                  ForwardIt2 d_first,
                  UnaryPredicate pred )
like image 671
prakash singh Avatar asked May 24 '18 11:05

prakash singh


1 Answers

In a nutshell, the idea is that instead of just having your current thread execute the plain-vanilla version of the algorithm (well, plain-vanilla up to compiler optimizations), you could instead put your computing hardware to more extensive use, to complete the "algorithm" faster.

Examples of what kinds of "faster" might be available to you via an execution policy:

  • Using multiple threads on multiple cores/sockets on a CPU
  • Using coprocessors present on the system, such as a CPU or FPGA.

Commenters @UnholySheep and @DanM have given us the link to some (longer and more detailed) official documentation.

like image 119
einpoklum Avatar answered Oct 30 '22 23:10

einpoklum