Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
D (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Parallelism==== Parallel programming concepts are implemented in the library, and do not require extra support from the compiler. However the D type system and compiler ensure that data sharing can be detected and managed transparently. <syntaxhighlight lang="D"> import std.stdio : writeln; import std.range : iota; import std.parallelism : parallel; void main() { foreach (i; iota(11).parallel) { // The body of the foreach loop is executed in parallel for each i writeln("processing ", i); } } </syntaxhighlight> <code>iota(11).parallel</code> is equivalent to <code>std.parallelism.parallel(iota(11))</code> by using UFCS. The same module also supports <code>taskPool</code> which can be used for dynamic creation of parallel tasks, as well as map-filter-reduce and fold style operations on ranges (and arrays), which is useful when combined with functional operations. <code>std.algorithm.map</code> returns a lazily evaluated range rather than an array. This way, the elements are computed by each worker task in parallel automatically. <syntaxhighlight lang="D"> import std.stdio : writeln; import std.algorithm : map; import std.range : iota; import std.parallelism : taskPool; /* On Intel i7-3930X and gdc 9.3.0: * 5140ms using std.algorithm.reduce * 888ms using std.parallelism.taskPool.reduce * * On AMD Threadripper 2950X, and gdc 9.3.0: * 2864ms using std.algorithm.reduce * 95ms using std.parallelism.taskPool.reduce */ void main() { auto nums = iota(1.0, 1_000_000_000.0); auto x = taskPool.reduce!"a + b"( 0.0, map!"1.0 / (a * a)"(nums) ); writeln("Sum: ", x); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)