DistributeDefinitions[s1,s2,…]
シンボル siのすべての定義をすべての並列カーネルに配布する.
DistributeDefinitions["context`"]
指定のコンテキスト内のすべてのシンボルの定義を配布する.
DistributeDefinitions
DistributeDefinitions[s1,s2,…]
シンボル siのすべての定義をすべての並列カーネルに配布する.
DistributeDefinitions["context`"]
指定のコンテキスト内のすべてのシンボルの定義を配布する.
詳細とオプション
- DistributeDefinitionsは,事実上,自身の値だけでなく下向きの値,上向きの値,その他のタイプの値を含む記号 siの値と属性のすべての割当てにParallelEvaluateを適用する.
- DistributeDefinitionsは記号 siの定義に現れる任意の記号に繰り返し適用される.
- DistributeDefinitionsにはHoldAllという属性がある.
- DistributeDefinitionsは,事実上,記号 siの定義を「登録」し,起動されたすべての新規並列カーネルに自動的に配布されるようにする.
- 任意の式 expr についてのDistributeDefinitions[expr]は expr 中のすべての記号の定義を配布する.
- 次は,使用可能なオプションである.
-
DistributedContexts $DistributedContexts 配布が考慮されるシンボルのコンテキスト ProgressReporting $ProgressReporting 計算の進捗状況を報告するかどうか - DistributedContextsオプションで与えられるコンテキストにコンテキストがリストされているシンボルだけが,定義の配布対象となる.
- ProgressReportingオプションは,定義配布の進捗状況を報告するかどうかを指定する.
- DistributeDefinitionsは,実際に配布されたシンボルのリストをHoldFormで包み込んで返す.定義が変わっていないシンボルは含まれない.
例題
すべて開く すべて閉じる例 (2)
LaunchKernels[];$KernelCountctx`y = 42;ParallelEvaluate[ToString[ctx`y]]$DistributedDefinitionsDistributeDefinitions[ctx`y]ParallelEvaluate[ToString[ctx`y]]$DistributedDefinitionsy = 43;ParallelEvaluate[ToString[y]]$DistributedDefinitionsスコープ (5)
ni = 5;nd := $KernelID
DistributeDefinitions[ni, nd]ParallelEvaluate[{ni, nd}]nfactors[n_] := Total[FactorInteger[(10 ^ n - 1/9)][[All, 2]]]
DistributeDefinitions[nfactors]ParallelMap[nfactors, Range[50, 70]]g/:f[g[x_]] := fg[x, $KernelID]
DistributeDefinitions[g]ParallelMap[f, {g[1], h[2], g[3]}]np = 5;Protect[np]
DistributeDefinitions[np]ParallelEvaluate[np = $KernelID, First[Kernels[]]]f[x_] := N[Pi ^ x, $prec];$prec = 50;DistributeDefinitions[Evaluate[Context[]]];ParallelEvaluate[f[$KernelID]]一般化と拡張 (1)
特性と関係 (7)
DistributeDefinitionsはそれまでの値や存在する属性をすべて上書きする:
ParallelEvaluate[f[0] = "Zero";f[x_] := x ^ 2, DistributedContexts -> None];ParallelMap[f, {0, 1, 2, 3, 4}, DistributedContexts -> None]f[x_] := x ^ 2
DistributeDefinitions[f]ParallelMap[f, {0, 1, 2, 3, 4}, DistributedContexts -> None]関数をクリアし,それを再配布することで,配布された定義を取り除く:
f[x_] := Labeled[Framed[x ^ 2], $KernelID]
DistributeDefinitions[f];ParallelMap[f, {1, 2, 3, 4}]ClearAll[f];DistributeDefinitions[f];ParallelMap[f, {1, 2, 3, 4}]DistributeDefinitionsはParallelEvaluateを使ってすべてのカーネルに定義を送る:
f[n_] := PrimeQ[2 ^ n - 1]DistributeDefinitions[f];明示的なParallelEvaluateも同じことをする:
ParallelEvaluate[g[n_] := PrimeQ[2 ^ n + 1]];ParallelEvaluate[Through[{Identity, f, g}[$KernelID]]]配布された定義は新たなカーネルにも引き継がれるが,ParallelEvaluateの効果は引き継がれない:
CloseKernels[];LaunchKernels[];ParallelEvaluate[Through[{Identity, f, g}[$KernelID]]]より高レベルの並列コマンドに関しては,インタラクティブに定義された関数が自動的に配布される:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelMap[ftest, Range[1275, 1285]]gtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]DistributeDefinitions[gtest];ParallelMap[gtest, Range[1275, 1285], DistributedContexts -> None]ParallelEvaluate[xr = 5]DistributeDefinitions[xr]ParallelTable[Sqrt[i] / xr, {i, 5}]記号に局所的な値が与えられるやいなや,その値は次の並列計算で配布される:
xr = 6;ParallelTable[Sqrt[i] / xr, {i, 5}]ParallelNeedsを使ってすべての並列カーネルにパッケージを設定する:
Needs["GraphUtilities`"]
ParallelNeeds["GraphUtilities`"]ParallelEvaluate[HamiltonianCycles[CompleteGraph[3], All]]DistributeDefinitionsを使ってユーザ自身の定義を設定する:
hcg[n_] := HamiltonianCycles[CompleteGraph[n], All]DistributeDefinitions[hcg];ParallelMap[hcg, Range[4]]$DistributedDefinitionsは,定義が配布されている全シンボルのリストを与える:
a = 2;b = 3;DistributeDefinitions[a]$DistributedDefinitionsParallelEvaluate[b]$DistributedDefinitions考えられる問題 (5)
並列カーネルにとって既知ではない関数が使われると評価が連続的に行われかねない:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelEvaluate[ftest[$KernelID], DistributedContexts -> None]DistributeDefinitions[ftest];ParallelEvaluate[ftest[$KernelID], DistributedContexts -> None]DistributeDefinitionsを使っても定義の自動配布は抑えられない:
f[i_] := {i, $KernelID}
DistributeDefinitions[f];Clear[f]Parallelize[Map[f, Range[8]]]g[i_] := {i, $KernelID}
DistributeDefinitions[g];Clear[g]Parallelize[Map[g, Range[8]], DistributedContexts -> None]サブカーネル上だけで定義された記号は自動的には配布されない:
ParallelEvaluate[h[i_] := {i, $KernelID}];Parallelize[Map[h, Range[8]]]内部状態を有するある種のオブジェクトは配布されると効率的に働かないことがある:
data = RandomReal[{-1, 1}, 1000];
fdata = ListInterpolation[data]Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];]DistributeDefinitions[fdata];ParallelEvaluate[Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];], First[Kernels[]]]よりよいパフォーマンスのためにそのようなオブジェクトをすべてのサブカーネルで再計算する:
DistributeDefinitions[data, fdata]ParallelEvaluate[fdata = ListInterpolation[data];];ParallelEvaluate[Timing[Table[fdata[r], {r, 1.0, 1000, 0.1}];], First[Kernels[]]]fdata1 = fdata;
DistributeDefinitions[fdata1]ParallelEvaluate[fdata1 = fdata1];ParallelEvaluate[Timing[Table[fdata1[r], {r, 1.0, 1000, 0.1}];], Last[Kernels[]]]ReadProtected属性があるシンボルの定義は配布できない:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID];
SetAttributes[ftest, ReadProtected]DistributeDefinitions[ftest]ParallelMap[ftest, Range[$KernelCount]]定義は必要に応じてのみ配布される.定義が変更されていなければ,再度配布されることはない:
a = 2;b = 3;DistributeDefinitions[a, b]b = 4;DistributeDefinitions[a, b]$DistributedDefinitions関連するガイド
-
▪
- 並列計算の設定 ▪
- 並列計算におけるリソースの共有 ▪
- 並列計算 ▪
- データの並列性
テキスト
Wolfram Research (2008), DistributeDefinitions, Wolfram言語関数, https://reference.wolfram.com/language/ref/DistributeDefinitions.html (2025年に更新).
CMS
Wolfram Language. 2008. "DistributeDefinitions." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/DistributeDefinitions.html.
APA
Wolfram Language. (2008). DistributeDefinitions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DistributeDefinitions.html
BibTeX
@misc{reference.wolfram_2026_distributedefinitions, author="Wolfram Research", title="{DistributeDefinitions}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DistributeDefinitions.html}", note=[Accessed: 15-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_distributedefinitions, organization={Wolfram Research}, title={DistributeDefinitions}, year={2025}, url={https://reference.wolfram.com/language/ref/DistributeDefinitions.html}, note=[Accessed: 15-September-2026]}