11.07.2015 Views

A Compiler for Parallel Exeuction of Numerical Python Programs on ...

A Compiler for Parallel Exeuction of Numerical Python Programs on ...

A Compiler for Parallel Exeuction of Numerical Python Programs on ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<str<strong>on</strong>g>Pyth<strong>on</strong></str<strong>on</strong>g>-C API functi<strong>on</strong>s from multithreaded functi<strong>on</strong>s.I introduce an extensi<strong>on</strong> to mark certain <str<strong>on</strong>g>for</str<strong>on</strong>g> loops as parallel to provide a sharedmemorydata-parallel model similar to (but less general than) the OpenMP parallel <str<strong>on</strong>g>for</str<strong>on</strong>g> loopdirectives. To avoid the complexity <str<strong>on</strong>g>of</str<strong>on</strong>g> specifying parallel semantics <str<strong>on</strong>g>for</str<strong>on</strong>g> arbitrary iterators,<strong>on</strong>ly a parallel versi<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g> xrange iterator is defined. A special iterator, prange, is introducedthat is used to specify that a loop is parallel. The iterator prange is <strong>on</strong>ly a hint to thecompiler that the programmer intends to execute the loop in parallel but the compiler isnot obligated to compile the loop to a parallel C++ loop. To the <str<strong>on</strong>g>Pyth<strong>on</strong></str<strong>on</strong>g> interpreter, prangeis identical to xrange. However, un<str<strong>on</strong>g>Pyth<strong>on</strong></str<strong>on</strong>g> treats the annotati<strong>on</strong>s as a special parallel-loopannotati<strong>on</strong>. A <str<strong>on</strong>g>for</str<strong>on</strong>g> loop over the parallel iterator prange has the following properties:1. Let the program point immediately be<str<strong>on</strong>g>for</str<strong>on</strong>g>e the loop be P. Then the program executi<strong>on</strong>is serial be<str<strong>on</strong>g>for</str<strong>on</strong>g>e P.2. Let the program point immediately after the loop be Q. Then the program may spawnmultiple threads between P and Q. The point Q is an implicit join-point. Programexecuti<strong>on</strong> does not c<strong>on</strong>tinue until all threads spawned reach Q. After Q, serial executi<strong>on</strong><str<strong>on</strong>g>of</str<strong>on</strong>g> the program c<strong>on</strong>tinues.3. Each iterati<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g> the loop is independent and may be executed in any order.4. <str<strong>on</strong>g>Parallel</str<strong>on</strong>g> loops may be nested but, in this model, a join point <strong>on</strong>ly exists at the ending<str<strong>on</strong>g>of</str<strong>on</strong>g> the outermost parallel loop.5. <str<strong>on</strong>g>Parallel</str<strong>on</strong>g> loops are a compiler directive and the compiler is not obligated to parallelizethe loop.6. If there is a data-race between any two iterati<strong>on</strong>s, then the output <str<strong>on</strong>g>of</str<strong>on</strong>g> the program isundefined.7. The body <str<strong>on</strong>g>of</str<strong>on</strong>g> the loop may <strong>on</strong>ly access variables <str<strong>on</strong>g>of</str<strong>on</strong>g> basic numeric types (float32, float64,int32 and int64) or NumPy arrays <str<strong>on</strong>g>of</str<strong>on</strong>g> basic numeric types. If any other object type isreferenced in the loop, then the loop is not parallelized by the compiler to avoid thepossibility <str<strong>on</strong>g>of</str<strong>on</strong>g> calling <str<strong>on</strong>g>Pyth<strong>on</strong></str<strong>on</strong>g>-C API functi<strong>on</strong>s from two different C threads.8. All variables defined outside the loop are treated as shared variables am<strong>on</strong>g threads.However, a programmer can define some variables as private by passing the keywordargument private with the value equal to a tuple c<strong>on</strong>taining a list <str<strong>on</strong>g>of</str<strong>on</strong>g> variable namesas strings.9. All variables local to the loop are treated as private.26

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!