({{, (RefLink[CompilationTarget, paclet:ref/CompilationTarget])
is an option for (RefLink[Compile, paclet:ref/Compile]) that specifies the target runtime for the compiled function. }})

OpenersNotesSection(Spacer1)Details

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

The following settings can be used:

CompilationTarget -> "WVM" creates code for the traditional Wolfram System virtual machine.

CompilationTarget -> "C" creates C code, which is compiled to an external machine code library and linked back into the Wolfram Language.

External files created when a "C" target is specified are deleted either after use or when the Wolfram System exits.

A suitable external C compiler is required to target C code. If one is not found, the Wolfram System will use the "WVM".

When either "C" or "WVM" targets are specified, the following additional settings can be used:

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

You can target C code generation from (RefLink[Compile, paclet:ref/Compile]):

cGen=Compile[{{x}},x^2+Sin[x^2],CompilationTarget->"C"]

This runs the compilation using C code:

cGen[ 10]

C code generation runs faster:

c=Compile[ {{x,_Real},{n,_Integer}},
	Module[ {sum, inc},sum=1.0;inc=1.0;Do[inc=inc*x/i;sum=sum+inc,{i,n}];sum],CompilationTarget->"C"];
c[1.5, 10000000]//AbsoluteTiming

The default operation using the WVM runs more slowly:

cNormal=Compile[ {{x,_Real},{n,_Integer}},
	Module[ {sum, inc},sum=1.0;inc=1.0;Do[inc=inc*x/i;sum=sum+inc,{i,n}];sum]];
cNormal[1.5, 10000000]//AbsoluteTiming

You can combine parallel operations with C code generation to get even faster operation:

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

OpenersExampleSection2(Spacer1)Neat Examples  (1)

A real-time plotting of the Mandelbrot set, the computation using a (RefLink[CompilationTarget, paclet:ref/CompilationTarget]) of C and parallelism is fast enough to update the image in real time.

First, the compiled function to compute values:

mandelComp=
Compile[{{c,_Complex}},Module[{num=1},FixedPoint[(num++;#^2+c)&,0,99,SameTest->(Re[#]^2+Im[#]^2≥4&)];num],
	CompilationTarget->"C",
	RuntimeAttributes->{Listable},
	Parallelization->True];

Now, a plot viewer to display the result and handle the interactions:

doPlotDrag[{x_,y_}]:=Panel[DynamicModule[{dragstart={0,0},dragval={0,0},draghold={x,y},xrange,yrange,m=-Log[2,1.5],scale =1.5},Column[{Row[{"Zoom ",Slider[Dynamic[m, Function[scale = 2.^-#; m = #]],{-1,10}]}],EventHandler[Dynamic[{xshift,yshift}=(dragstart-dragval+draghold) {1,-1};
{ylo,yhi}=yshift + scale*{-1,1};
{xlo,xhi}=xshift + scale*{-1,1};
xrange={b,xlo,xhi,.01 scale};
yrange={a,ylo,yhi,.01*scale};
data=Table[a+I b,Evaluate[yrange],Evaluate[xrange]];
ArrayPlot[mandelComp[data],ImageSize->400]],"MouseDown":>(dragval=dragstart=scale*MousePosition["GraphicsScaled"]),"MouseDragged":>(dragval=scale*MousePosition["GraphicsScaled"]),"MouseUp":>(draghold=draghold+dragstart-dragval;
dragstart=dragval={0,0})]}]]]

Now you can invoke the functions. Note that this is an image to interact with the picture you need to evaluate the commands:

doPlotDrag[{0,1}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Compile, paclet:ref/Compile])  ▪  (RefLink[CompiledFunction, paclet:ref/CompiledFunction])  ▪  (RefLink[$CompilationTarget, paclet:ref/$CompilationTarget])  ▪  (RefLink[CompilationOptions, paclet:ref/CompilationOptions])  ▪  (RefLink[RuntimeAttributes, paclet:ref/RuntimeAttributes])  ▪  (RefLink[Parallelization, paclet:ref/Parallelization])}})}})

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

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