词条 | Cilk |
释义 |
| name = Cilk | logo = | paradigm = imperative (procedural), structured, parallel | year = 1994 | designer =MIT Laboratory for Computer Science | developer =Intel | latest_release_version = | latest release date = | typing = static, weak, manifest | implementations = | dialects = Cilk++, Cilk Plus | influenced_by =C | influenced = OpenMP 3.0[1] | operating_system = | license = | website = | file_ext = }}{{Infobox programming language | name = Cilk Plus | logo = | paradigm = | year = 2010 | designer = Intel | developer = Intel | latest_release_version = 1.2 | latest release date = {{release date and age|2013|09|09}} | typing = | implementations = | dialects = | influenced_by = | influenced = | operating_system = | license = | website = {{URL|www.cilkplus.org}} | file_ext = (Same as C or C++) }} Cilk, Cilk++ and Cilk Plus are general-purpose programming languages designed for multithreaded parallel computing. They are based on the C and C++ programming languages, which they extend with constructs to express parallel loops and the fork–join idiom. Originally developed in the 1990s at the Massachusetts Institute of Technology (MIT) in the group of Charles E. Leiserson, Cilk was later commercialized as Cilk++ by a spinoff company, Cilk Arts. That company was subsequently acquired by Intel, which increased compatibility with existing C and C++ code, calling the result Cilk Plus. HistoryMIT CilkThe Cilk programming language grew out of three separate projects at the MIT Laboratory for Computer Science:[2]
In April 1994 the three projects were combined and christened "Cilk". The name Cilk is not an acronym, but an allusion to "nice threads" (silk) and the C programming language. The Cilk-1 compiler was released in September 1994. The original Cilk language was based on ANSI C, with the addition of Cilk-specific keywords to signal parallelism. When the Cilk keywords are removed from Cilk source code, the result should always be a valid C program, called the serial elision (or C elision) of the full Cilk program, with the same semantics as the Cilk program running on a single processor. Despite several similarities,{{which|date=September 2015}} Cilk is not directly related to AT&T Bell Labs' Concurrent C. Cilk was implemented as a translator to C, targeting the GNU C Compiler (GCC). The last version, Cilk 5.4.6, is available from the MIT Computer Science and Artificial Intelligence Laboratory (CSAIL), but is no longer supported.[3] A showcase for Cilk's capabilities was the Cilkchess parallel chess-playing program, which won several computer chess prizes in the 1990s, including the 1996 Open Dutch Computer Chess Championship.[4] Cilk Arts and Cilk++Prior to {{circa|2006}}, the market for Cilk was restricted to high-performance computing. The emergence of multicore processors in mainstream computing means that hundreds of millions of new parallel computers are now being shipped every year. Cilk Arts was formed to capitalize on that opportunity: in 2006, Leiserson launched Cilk Arts to create and bring to market a modern version of Cilk that supports the commercial needs of an upcoming generation of programmers. The company closed a Series A venture financing round in October 2007, and its product, Cilk++ 1.0, shipped in December, 2008. Cilk++ differs from Cilk in several ways: support for C++, support for loops, and hyperobjects{{snd}} a new construct designed to solve data race problems created by parallel accesses to global variables. Cilk++ was proprietary software. Like its predecessor, it was implemented as a Cilk-to-C++ compiler. It supported the Microsoft and GNU compilers. Intel Cilk PlusOn July 31, 2009, Cilk Arts announced on its web site that its products and engineering team were now part of Intel Corp. In early 2010, the Cilk website at Cilk Plus was first implemented in the Intel C++ Compiler with the release of the Intel compiler in Intel Composer XE 2010.{{Citation needed|date=March 2015}} An open source (BSD-licensed) implementation was contributed by Intel to the GNU Compiler Collection (GCC), which shipped Cilk Plus support in version 4.9,[8] except for the {{mono|_Cilk_for}} keyword, which was added in GCC 5.0. In February 2013, Intel announced a Clang fork with Cilk Plus support.[9] The Intel Compiler, but not the open source implementations, comes with a race detector and a performance analyzer. Differences between versionsIn the original MIT Cilk implementation, the first Cilk keyword is in fact ObsolescenceIn May, 2017, GCC 7.1 was released and marked Cilk Plus support as deprecated.[10] Intel itself announced in September 2017 that they would deprecate Cilk Plus with the 2018 release of the Intel Software Development Tools.[11] In May 2018, GCC 8.1 was released with Cilk Plus support removed.[12] Language featuresThe principle behind the design of the Cilk language is that the programmer should be responsible for exposing the parallelism, identifying elements that can safely be executed in parallel; it should then be left to the run-time environment, particularly the scheduler, to decide during execution how to actually divide the work between processors. It is because these responsibilities are separated that a Cilk program can run without rewriting on any number of processors, including one. Task parallelism: spawn and sync{{See also|Fork–join model}}Cilk's main addition to C are two keywords that together allow writing task-parallel programs.
(In Cilk Plus, the keywords are spelled {{mono|_Cilk_spawn}} and {{mono|_Cilk_sync}}, or {{mono|cilk_spawn}} and {{mono|cilk_sync}} if the Cilk Plus headers are included.) Below is a recursive implementation of the Fibonacci function in Cilk, with parallel recursive calls, which demonstrates the {{mono|spawn}}, and {{mono|sync}} keywords. The original Cilk required any function using these to be annotated with the {{mono|cilk}} keyword, which is gone as of Cilk Plus. (Cilk program code is not numbered; the numbers have been added only to make the discussion easier to follow.) If this code was executed by a single processor to determine the value of {{mono|fib(2)}}, that processor would create a frame for {{mono|fib(2)}}, and execute lines 1 through 5. On line 6, it would create spaces in the frame to hold the values of {{mono|x}} and {{mono|y}}. On line 8, the processor would have to suspend the current frame, create a new frame to execute the procedure {{mono|fib(1)}}, execute the code of that frame until reaching a return statement, and then resume the {{mono|fib(2)}} frame with the value of fib(1) placed into {{mono|fib(2)}}'s {{mono|x}} variable. On the next line, it would need to suspend again to execute {{mono|fib(0)}} and place the result in {{mono|fib(2)}}'s {{mono|y}} variable. When the code is executed on a multiprocessor machine, however, execution proceeds differently. One processor starts the execution of {{mono|fib(2)}}; when it reaches line 8, however, the {{mono|spawn}} keyword modifying the call to {{mono|fib(n-1)}} tells the processor that it can safely give the job to a second processor: this second processor can create a frame for {{mono|fib(1)}}, execute its code, and store its result in {{mono|fib(2)}}'s frame when it finishes; the first processor continues executing the code of {{mono|fib(2)}} at the same time. A processor is not obligated to assign a spawned procedure elsewhere; if the machine only has two processors and the second is still busy on {{mono|fib(1)}} when the processor executing {{mono|fib(2)}} gets to the procedure call, the first processor will suspend {{mono|fib(2)}} and execute {{mono|fib(0)}} itself, as it would if it were the only processor. Of course, if another processor is available, then it will be called into service, and all three processors would be executing separate frames simultaneously. (The preceding description is not entirely accurate. Even though the common terminology for discussing Cilk refers to processors making the decision to spawn off work to other processors, it is actually the scheduler which assigns procedures to processors for execution, using a policy called work-stealing, described later.) If the processor executing {{mono|fib(2)}} were to execute line 13 before both of the other processors had completed their frames, it would generate an incorrect result or an error; {{mono|fib(2)}} would be trying to add the values stored in {{mono|x}} and {{mono|y}}, but one or both of those values would be missing. This is the purpose of the {{mono|sync}} keyword, which we see in line 11: it tells the processor executing a frame that it must suspend its own execution until all the procedure calls it has spawned off have returned. When {{mono|fib(2)}} is allowed to proceed past the {{mono|sync}} statement in line 11, it can only be because {{mono|fib(1)}} and {{mono|fib(0)}} have completed and placed their results in {{mono|x}} and {{mono|y}}, making it safe to perform calculations on those results. The code example above uses the syntax of Cilk-5. The original Cilk (Cilk-1) used a rather different syntax that required programming in an explicit continuation-passing style, and the Fibonacci examples looks as follows:[13] Inside {{mono|fib}}'s recursive case, the {{mono|spawn_next}} keyword indicates the creation of a successor thread (as opposed to the child threads created by {{mono|spawn}}), which executes the {{mono|sum}} subroutine after waiting for the continuation variables {{mono|x}} and {{mono|y}} to be filled in by the recursive calls. The base case and {{mono|sum}} use a {{mono|send_argument(k, n)}} operation to set their continuation variable {{mono|k}} to the value of {{mono|n}}, effectively "returning" the value to the successor thread. InletsThe two remaining Cilk keywords are slightly more advanced, and concern the use of inlets. Ordinarily, when a Cilk procedure is spawned, it can return its results to the parent procedure only by putting those results in a variable in the parent's frame, as we assigned the results of our spawned procedure calls in the example to The alternative is to use an inlet. An inlet is a function internal to a Cilk procedure which handles the results of a spawned procedure call as they return. One major reason to use inlets is that all the inlets of a procedure are guaranteed to operate atomically with regards to each other and to the parent procedure, thus avoiding the bugs that could occur if the multiple returning procedures tried to update the same variables in the parent frame at the same time.
Inlets were removed when Cilk became Cilk++, and are not present in Cilk Plus. Parallel loopsCilk++ added an additional construct, the parallel loop, denoted {{mono|cilk_for}} in Cilk Plus. These loops look like This implements the parallel map idiom: the body of the loop, here a call to {{mono|f}} followed by an assignment to the array {{mono|a}}, is executed for each value of {{mono|i}} from zero to {{mono|n}} in an indeterminate order. The optional "grain size" pragma determines the coarsening: any sub-array of one hundred or fewer elements is processed sequentially. Although the Cilk specification does not specify the exact behavior of the construct, the typical implementation is a divide-and-conquer recursion,[14] as if the programmer had written The reasons for generating a divide-and-conquer program rather than the obvious alternative, a loop that spawn-calls the loop body as a function, lie in both the grainsize handling and in efficiency: doing all the spawning in a single task makes load balancing a bottleneck.[15] A review of various parallel loop constructs on HPCwire found the {{mono|cilk_for}} construct to be quite general, but noted that the Cilk Plus specification did not stipulate that its iterations need to be data-independent, so a compiler cannot automatically vectorize a {{mono|cilk_for}} loop. The review also noted the fact that reductions (e.g., sums over arrays) need additional code.{{r|loops}} Reducers and hyperobjectsCilk++ added a kind of objects called hyperobjects, that allow multiple strands to share state without race conditions 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.[16] 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: Other reducers can be used to construct linked lists or strings, and programmers can define custom reducers. A limitation of hyperobjects is that they provide only limited 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:[17] Array notationIntel Cilk Plus adds notation to express high-level operations on entire arrays or sections of arrays; e.g., an axpy-style function that is ordinarily written can in Cilk Plus be expressed as This notation helps the compiler to effectively vectorize the application. Intel Cilk Plus allows C/C++ operations to be applied to multiple array elements in parallel, and also provides a set of built-in functions that can be used to perform vectorized shifts, rotates, and reductions. Similar functionality exists in Fortran 90; Cilk Plus differs in that it never allocates temporary arrays, so memory usage is easier to predict. Elemental functionsIn Cilk Plus, an elemental function is a regular function which can be invoked either on scalar arguments or on array elements in parallel. They are similar to the kernel functions of OpenCL. #pragma simdThis pragma gives the compiler permission to vectorize a loop even in cases where auto-vectorization might fail. It is the simplest way to manually apply vectorization. Work-stealing{{main|Work stealing}}The Cilk scheduler uses a policy called "work-stealing" to divide procedure execution efficiently among multiple processors. Again, it is easiest to understand if we look first at how Cilk code is executed on a single-processor machine. The processor maintains a stack on which it places each frame that it has to suspend in order to handle a procedure call. If it is executing fib(2), and encounters a recursive call to fib(1), it will save fib(2)'s state, including its variables and where the code suspended execution, and put that state on the stack. It will not take a suspended state off the stack and resume execution until the procedure call that caused the suspension, and any procedures called in turn by that procedure, have all been fully executed. With multiple processors, things of course change. Each processor still has a stack for storing frames whose execution has been suspended; however, these stacks are more like deques, in that suspended states can be removed from either end. A processor can still only remove states from its own stack from the same end that it puts them on; however, any processor which is not currently working (having finished its own work, or not yet having been assigned any) will pick another processor at random, through the scheduler, and try to "steal" work from the opposite end of their stack{{snd}} suspended states, which the stealing processor can then begin to execute. The states which get stolen are the states that the processor stolen from would get around to executing last. See also
References1. ^{{cite conference |title=A Runtime Implementation of OpenMP Tasks |first1=James |last1=LaGrone |first2=Ayodunni |last2=Aribuki |first3=Cody |last3=Addison |first4=Barbara |last4=Chapman |conference=7th Int'l Workshop on OpenMP |year=2011 |pages=165–178 |doi=10.1007/978-3-642-21487-5_13 |citeseerx=10.1.1.221.2775}} 2. ^[https://www.cilkplus.org/cilk-history "A Brief History of Cilk] 3. ^{{cite web |url=http://supertech.csail.mit.edu/cilk/ |title=The Cilk Project |date=8 October 2010 |accessdate=25 January 2016 |publisher=MIT CSAIL}} 4. ^{{cite journal |last1=Leiserson |first1=Charles E. |first2=Aske |last2=Plaat |title=Programming parallel applications in Cilk |journal=SIAM News |volume=31 |year=1998 |url=https://www.researchgate.net/profile/Aske_Plaat/publication/2427921_Programming_Parallel_Applications_in_Cilk/links/0c960528009eddb4e9000000.pdf}} 5. ^"Intel Flexes Parallel Programming Muscles" {{webarchive|url=https://web.archive.org/web/20100906030803/http://www.hpcwire.com/features/Intel-Flexes-Parallel-Programming-Muscles-102084438.html |date=2010-09-06 }}, HPCwire (2010-09-02). Retrieved on 2010-09-14. 6. ^"Parallel Studio 2011: Now We Know What Happened to Ct, Cilk++, and RapidMind", Dr. Dobb's Journal (2010-09-02). Retrieved on 2010-09-14. 7. ^"Intel Cilk Plus: A quick, easy and reliable way to improve threaded performance", Intel. Retrieved on 2010-09-14. 8. ^[https://gcc.gnu.org/gcc-4.9/changes.html "GCC 4.9 Release Series Changes, New Features, and Fixes"], Free Software Foundation, Inc. Retrieved on 2014-06-29. 9. ^[https://cilkplus.github.io/ Cilk Plus/LLVM] 10. ^[https://gcc.gnu.org/gcc-7/changes.html] 11. ^[https://software.intel.com/en-us/forums/intel-cilk-plus/topic/745556] 12. ^[https://gcc.gnu.org/gcc-8/changes.html] 13. ^{{cite conference |url=http://supertech.csail.mit.edu/papers/PPoPP95.pdf |title=Cilk: An Efficient Multithreaded Runtime System |first1=Robert D. |last1=Blumofe |first2=Christopher F. |last2=Joerg |first3=Bradley C. |last3=Kuszmaul |first4=Charles E. |last4=Leiserson |first5=Keith H. |last5=Randall |first6=Yuli |last6=Zhou |conference=Proc. ACM SIGPLAN Symp. Principles and Practice of Parallel Programming |pages=207–216 |year=1995}} 14. ^{{cite web |title=Compilers and More: The Past, Present and Future of Parallel Loops |first=Michael |last=Wolfe |date=6 April 2015 |website=HPCwire |url=http://www.hpcwire.com/2015/04/06/compilers-and-more-the-past-present-and-future-of-parallel-loops/}} 15. ^{{cite book |first1=Michael |last1=McCool |first2=James |last2=Reinders |first3=Arch |last3=Robison |title=Structured Parallel Programming: Patterns for Efficient Computation |publisher=Elsevier |year=2013 |page=30}} 16. ^{{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}} 17. ^{{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}} External links
5 : Articles with example code|Concurrent programming languages|C programming language family|Massachusetts Institute of Technology software|Intel software |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。