Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how

Legacy Documentation

Mathematica 8 (2010)

This is documentation for Mathematica 8, which was
based on an earlier version of Wolfram Language.
View current documentation (Version 14.3)

SetSharedVariable

SetSharedVariable
declares the symbols as shared variables whose values are synchronized among all parallel kernels.
  • The unique value of a shared variable is maintained by the master kernel and every access on a parallel subkernel is synchronized through the master kernel.
  • Shared variables without a value evaluate to Null .
(1)
Make xs be a (global) shared variable:
Each subkernel increments the (global) shared variable value:
Without sharing, each subkernel has its own (local) copy of the variable:
Make xs be a (global) shared variable:
Each subkernel increments the (global) shared variable value:
Out[2]=
Out[3]=
Without sharing, each subkernel has its own (local) copy of the variable:
Out[5]=
Out[6]=
(4)
Share a single value:
Access a single element of a shared list efficiently:
Assign a new value to a shared variable:
Only the last assignment performed remains:
Change a single element of a shared list:
Update the value of a shared variable:
Append to a shared list:
Append to an element of a shared list:
(1)
Delayed values defined on the master kernel are evaluated on the master kernel:
Delayed values defined on a subkernel are evaluated on the kernel asking for the value:
(5)
Use shared variables to synchronize input and output in an infinite search:
Find such that is prime, until the computation is manually aborted:
Use a shared variable to signal all evaluations to stop as soon as a prime has been found:
Use a shared variable to hand out tasks to do:
Monitor the progress of a calculation, counting major calculation steps:
Return results as they are found:
Watch the results appear in real time:
(1)
$KernelCount is effectively a shared variable:
(1)
Separate read and write operations are not thread-safe:
Use atomic updates for synchronization:
Alternatively, use CriticalSection to make a whole code section atomic:
New in 7


ja zh

AltStyle によって変換されたページ (->オリジナル) /