({{, (RefLink[Parallelization, paclet:ref/Parallelization])
is an option for (RefLink[Compile, paclet:ref/Compile]) that specifies whether it should create a compiled function that could run in parallel. }})

OpenersNotesSection(Spacer1)Details

(RefLink[Parallelization, paclet:ref/Parallelization]) applies to the execution of the compiled function.

Compiled functions only run in parallel if (RefLink[Listable, paclet:ref/Listable]) is one of the (RefLink[RuntimeAttributes, paclet:ref/RuntimeAttributes]) and the function threads over list arguments.

Compiled functions run in parallel using multiple threads of execution.

Typically, (RefLink[$ProcessorCount, paclet:ref/$ProcessorCount]) is used to determine how many threads are used.

If a compiled function running in parallel has several threads trying to call ordinary Wolfram Language code, only one thread can do this at any time.

The following settings can be used:

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Listable compiled functions can execute in parallel:

cP=Compile[{{x}},
Module[{sum=1.0,inc=1.0},Do[inc=inc*x/i;sum=sum+inc,{i,10000}];sum],
RuntimeAttributes->{Listable},Parallelization->True];
arg=Range[ -50.,50, 0.02];
cP[arg];//AbsoluteTiming

This shows the operation running sequentially:

cS=Compile[{{x}},
Module[{sum=1.0,inc=1.0},Do[inc=inc*x/i;sum=sum+inc,{i,10000}];sum],
RuntimeAttributes->{Listable},Parallelization->False];
cS[arg];//AbsoluteTiming

Typically, (RefLink[$ProcessorCount, paclet:ref/$ProcessorCount]) is used to determine how many threads can be used:

$ProcessorCount

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Compile, paclet:ref/Compile])  ▪  (RefLink[CompiledFunction, paclet:ref/CompiledFunction])  ▪  (RefLink[RuntimeAttributes, paclet:ref/RuntimeAttributes])  ▪  (RefLink[RuntimeOptions, paclet:ref/RuntimeOptions])  ▪  (RefLink[CompilationTarget, paclet:ref/CompilationTarget])  ▪  (RefLink[Parallelize, paclet:ref/Parallelize])  ▪  (RefLink[ParallelEvaluate, paclet:ref/ParallelEvaluate])  ▪  (RefLink[$ProcessorCount, paclet:ref/$ProcessorCount])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Compiling Wolfram Language Expressions, paclet:tutorial/CompilingWolframLanguageExpressions])}, {▪(RefLinkPlain[The Wolfram Language Compiler User Guide, paclet:Compile/tutorial/Overview])}, {▪(RefLinkPlain[The Wolfram Language Compiler User Guide: Parallel Computation, paclet:Compile/tutorial/Parallel])}, {▪(RefLinkPlain[Generating C and Fortran Expressions, paclet:tutorial/GeneratingCAndFortranExpressions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Parallel Computing, paclet:guide/ParallelComputing])}})}})