is an option for Compile that specifies the target runtime for the compiled function.
CompilationTarget
is an option for Compile that specifies the target runtime for the compiled function.
Details
- CompilationTarget applies to the creation of the compiled function.
- The following settings can be used:
-
"WVM" the Wolfram Virtual Machine "C" C code - 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:
-
RuntimeAttributes -> Listable compile a function with Listable attribute Parallelization -> True try using multiple threads if possible
Examples
open all close allBasic Examples (3)
You can target C code generation from 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]//AbsoluteTimingThe 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]//AbsoluteTimingYou 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];//AbsoluteTimingNeat Examples (1)
A real-time plotting of the Mandelbrot set, the computation using a 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}]Related Guides
History
Text
Wolfram Research (2010), CompilationTarget, Wolfram Language function, https://reference.wolfram.com/language/ref/CompilationTarget.html.
CMS
Wolfram Language. 2010. "CompilationTarget." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/CompilationTarget.html.
APA
Wolfram Language. (2010). CompilationTarget. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/CompilationTarget.html
BibTeX
@misc{reference.wolfram_2026_compilationtarget, author="Wolfram Research", title="{CompilationTarget}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/CompilationTarget.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_compilationtarget, organization={Wolfram Research}, title={CompilationTarget}, year={2010}, url={https://reference.wolfram.com/language/ref/CompilationTarget.html}, note=[Accessed: 12-June-2026]}