While I cannot answer the general question, I would like to point out that Parallelize
does more than replace certain functions with their parallel versions.
Consider this:
Parallelize[{f[$KernelID], f[$KernelID], f[$KernelID], f[$KernelID]}]
(* ==> {f[2], f[2], f[1], f[1]} *)
Parallelize[f[$KernelID] + f[$KernelID] + f[$KernelID] + f[$KernelID]]
(* ==> 2 f[1] + 2 f[2] *)
Notice that Parallelize
has evaluated instances of f
in parallel even when they appeared in a more complex expression (in a list or in a sum)
The documentation mentions somewhere (I can't find where right now, if you do please edit it in) that a general way to parallelize the evaluation of a function f
is to replace every instance of f
by Composition[ParallelSubmit, f]
, then applying WaitAll
to the whole expression. (One must be careful to keep things in an unevaluated state before submitting the evaluations though.)
As an example, I copied the following possible (not actual) implementation of ParallelMap
directly from a comment in the Parallel package:
ParallelMap[f_, h_[exprs___]] :=
h @@ WaitAll[ Composition[ParallelSubmit,f] /@ {exprs} ]
This type of parallelization is not ideal though because it corresponds to using the finest granularity: each evaluation of f
is submitted separately, one by one (not in batches), thus the overhead is large.
The sources of the parallel computing tools are available and are commented, so if you have time, you can try digging in the package to find the answer to the question.
Update From the Evaluate.m
source file in the parallel computing tools package it appears that the following functions are treated specially by Parallelize
:
Map, MapIndexed, MapThread, Scan, Apply, Outer, Inner, Dot, Through
Pick
Table, Sum, Product, Do, Array
Cases, Select
Count, MemberQ, FreeQ
Some other functions are treated specially as well. I did not take the time to go through the source and understand it in detail.
The point I want to emphasize is that Parallelize
seems to be able to parallelize very general expressions, but not all of them with the same quality (granularity)