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
Cilk
(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!
===Reducers and hyperobjects=== Cilk++ added a kind of objects called ''hyperobjects'', that allow multiple strands to share state without [[race condition]]s and without using explicit locks. Each strand has a view on the hyperobject that it can use and update; when the strands synchronize, the views are combined in a way specified by the programmer.<ref>{{cite conference |last1=Frigo |first1=Matteo |first2=Pablo |last2=Halpern |first3=Charles E. |last3=Leiserson |first4=Stephen |last4=Lewin-Berlin |title=Reducers and other Cilk++ hyperobjects |conference=Proc. Annual Symposium on Parallelism in Algorithms and Architectures (SPAA) |publisher=ACM |year=2009 |url=http://www.fftw.org/~athena/papers/hyper.pdf}}</ref> The most common type of hyperobject is a reducer, which corresponds to the reduction clause in [[OpenMP]] or to the algebraic notion of a [[monoid]]. Each reducer has an [[identity element]] and an [[associative operation]] that combines two values. The archetypal reducer is [[summation]] of numbers: the identity element is zero, and the associative ''reduce'' operation computes a sum. This reducer is built into Cilk++ and Cilk Plus: <syntaxhighlight lang="cpp"> // Compute β foo(i) for i from 0 to N, in parallel. cilk::reducer_opadd<float> result(0); cilk_for (int i = 0; i < N; i++) result += foo(i); </syntaxhighlight> Other reducers can be used to construct [[linked list]]s or strings, and programmers can define custom reducers. A limitation of hyperobjects is that they provide only limited [[Indeterminacy in concurrent computation|determinacy]]. Burckhardt ''et al.'' point out that even the sum reducer can result in non-deterministic behavior, showing a program that may produce either {{mono|1}} or {{mono|2}} depending on the scheduling order:<ref>{{cite conference |title=Concurrent Programming with Revisions and Isolation Types |first1=Sebastian |last1=Burckhardt |first2=Alexandro |last2=Baldassin |first3=Daan |last3=Leijen |year=2010 |conference=Proc. [[OOPSLA]]/SPLASH |url=http://research.microsoft.com/pubs/132619/revisions-oopsla2010.pdf}}</ref> <syntaxhighlight lang="cpp"> void add1(cilk::reducer_opadd<int> &r) { r++; } // ... cilk::reducer_opadd<int> r(0); cilk_spawn add1(r); if (r == 0) { r++; } cilk_sync; output(r.get_value()); </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)