CompilationTarget
Compileのオプションで,コンパイルされた関数のターゲットランタイムを指定する.
詳細
- CompilationTargetは関数をコンパイルする際に適用される.
- 使用可能な設定値
-
"WVM" Wolfram仮想マシン "C" Cコード - CompilationTarget -> "WVM"は,従来のWolframシステム仮想マシンのコードを作成する.
- CompilationTarget -> "C"はCコードを作成する.これは,外部マシンのコードライブラリにコンパイルされ,Wolfram言語にリンクされて戻される.
- "C"のターゲット指定時に作成される外部ファイルは,使用後あるいはWolframシステムの終了時に削除される.
- Cコードをターゲットとするためには適切な外部Cコンパイラが必要である.外部コンパイラが見付からなければ,Wolframシステムは"WVM"を使用する.
- "C"あるいは"WVM"のどちらかのターゲットが指定されると,下記の追加設定が使用可能になる.
-
RuntimeAttributes -> Listable Listable属性を有する関数をコンパイルする Parallelization -> True 可能な場合複数のスレッドを使おうとする
例題
すべて開く すべて閉じる例 (3)
CompileからCコード生成がターゲットにできる:
cGen = Compile[{{x}}, x ^ 2 + Sin[x ^ 2], CompilationTarget -> "C"]cGen[ 10]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]//AbsoluteTimingcNormal = 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]//AbsoluteTimingcP1 = 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おもしろい例題 (1)
マンテルブロ集合のリアルタイムプロット.CのCompilationTargetの計算を使った並列化は画像を十分リアルタイムで更新できるだけ速い.
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];次に,結果を表示しインタラクションを操作するためのビューアをプロットする:
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})]}]]]これで関数を呼び出すことができる.これはコマンドを評価するために必要な絵とインタラクトするための画像である点に注意のこと:
doPlotDrag[{0, 1}]テクニカルノート
関連するガイド
-
▪
- 並列計算
テキスト
Wolfram Research (2010), CompilationTarget, Wolfram言語関数, 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: 05-September-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: 05-September-2026]}