Difference between section and win and fork

In C ++, what's the difference between divide and conquer and fork and join? Is a fork and joins a specific case of division and conquest because fork and join only apply in parallelism? Thank!

+3


source to share


2 answers


Basically Fork-Join breaks the problem down into mini-problems until the mini-problem is simple enough to be solved without further disruption. Its like an algorithm of division and conquest. With this concept, it's important to note that ideally no worker thread is running. They implement a job search algorithm in which idle workers steal jobs from those workers who are busy.

  Result solve(Problem problem) 
  {
        if (problem is small)
            directly solve problem
        else 
             {
            split problem into independent parts
            fork new subtasks to solve each part
            join all subtasks
            compose result from subresults
          }
  }

      



C ++ 14 has some fork and join problem, you can read more from this site ( http://www.meetingcpp.com/index.php/br/items/a-look-at-c14-papers- part-2.html )

+1


source


"Divide and conquer" is a general programming technique for breaking up a larger problem into more solvable subproblems, solving them separately (and sometimes recursively), finally creating an answer to the big problem, combining the answers to the subproblems. This is a non-C idea. ++.

Fork and join specific parallelism primitives available in many languages. A fork causes another thread to start; "join" makes the current thread wait for another thread to complete and synchronize. I believe the C ++ 14 standard has such primitives built in. Many other langauges do not have this built in, but it is often available through libraries (including earlier versions of C ++).



You can use Fork and Join to implement Divide and Conquer with parallelism. Used in this way, "fork" dispatches threads to split subroutines, and "join" is needed as a step to signal subtask completion. But "join" does not specifically compute the combined answer to the "big" problem. You will most likely need more code than just fork and join.

+2


source







All Articles