In C++, what's the difference between divide and conquer & fork and join? Is fork and join a specific case of divide and conquer because fork and join only applies in parallelism? Thanks!
-
1Two things: First, please strip out the `join`, `difference`, and `divide` tags as their tag excerpts pretty clearly define them as unrelated to your problem. Well, except for `divide`, and that's just a bad tag. Second, is this language-specific or language-agnostic? If it's the latter, please explicitly state as much. If it's the former, add a tag for the language. – Nic Apr 16 '15 at 22:28
-
@QPaysTaxes: For what it's worth, there is also a [tag:language-agnostic] tag. – eggyal Apr 17 '15 at 11:16
-
@eggyal Huh. I never knew that. Then OP should add that tag. – Nic Apr 17 '15 at 11:17
-
@eggyal Thanks guys! First time user :p – munmunbb May 06 '15 at 22:03
2 Answers
"Divide and conquer" is a general programming method for breaking a larger problem into more-solvable subproblems, solving them separately (and sometimes recursively), finally producing the answer to the big problem by combining the answers to the sub-problems. It is an idea not specific to C++.
"Fork" and "Join" name specific parallelism primitives available in many languages. "Fork" causes another execution thread to be started; "join" causes the current thread to wait for another thread to complete-and-synchronize. I believe the C++14 standard has such primitives built-in. Many other langauges don't have this built-in, but it it is often available via libraries (including earlier versions of C++).
One might use "Fork" and "Join" to implement "Divide and conquer" enhanced with parallelism. Used like this, "fork" sends threads to separate subproblmes, and "join" is necessary as a step to signal completion of the subproblems. But "join" does not specifically compute the combined answer to "big" problem. You are likely to need more code than just fork and join.

- 93,541
- 22
- 172
- 341
Basically the Fork-Join breaks the task at hand into mini-tasks until the mini-task is simple enough that it can be solved without further breakups. It’s like a divide-and-conquer algorithm. One important concept to note in this framework is that ideally no worker thread is idle. They implement a work-stealing algorithm in that idle workers steal the work 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 issue related with fork & join , you can read more from this site ( http://www.meetingcpp.com/index.php/br/items/a-look-at-c14-papers-part-2.html )

- 1,610
- 3
- 22
- 40