Changes between Version 6 and Version 7 of OpenMPTransformation


Ignore:
Timestamp:
04/20/14 10:21:00 (12 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OpenMPTransformation

    v6 v7  
    11
    22
    3 == OpenMP Constructs ==
     3== OpenMP Primitives ==
    44
     5Constructs
    56* `parallel`
    67* worksharing
     
    3738== Translation Strategies ==
    3839
    39 === Shared variables ===
     40=== Translating shared variables ===
    4041
    41 === `parallel` ===
     42=== Translating `parallel` ===
    4243
    43 `parallel`: this spawns some nondeterministic number of threads.  Each thread is assigned an ID.  The original ("master") thread has ID 0.  All threads execute the parallel region.
     44`parallel`: this spawns some nondeterministic number of threads.  We will assume there is a constant `THREAD_MAX` defined somewhere.  The number of threads created will be between 1 and `THREAD_MAX` (inclusive).  Each thread is assigned an ID.  The original ("master") thread has ID 0.  All threads execute the parallel region.
    4445
    4546{{{
     
    6768For all private variables `x` not declared within the parallel construct, create a new variable of the same type, `_x`.    The new variable is declared within the thread scope.  If `x` is also firstprivate,  then `_x` is initialized with the value of `x`, e.g. `int _x=x;`.  Otherwise, `_x` is uninitialized, so has an undefined value.
    6869
    69 === `for` ===
     70=== Translating `for` ===
    7071
    7172Try to determine whether the loop iterations are independent.  In that case, they can all be executed by one thread.
     
    7879
    7980Is there any loss of generality  by just running all iterations concurrently?
     81
     82One approach: assume you have a function or macro `CIVL_owns(n, t, i)`.  It takes three ints and returns a boolean.  The arguments are `n`: the number of threads; `t`: a thread ID between 0 and `n`-1 (inclusive); and `i`, an iteration index.
    8083
    8184{{{
     
    97100
    98101
    99 === `sections` ===
     102=== Translating `sections` ===
    100103
    101104If there are n sections, create n functions: section1, section2, ....  Again the question is how to distribute them among threads and in what order.
    102105As with loops, you really want to check these are independent and only do the interleaving exploration as a last resort.
    103106
    104 === `single` ===
     107{{{
     108#pragma omp sections
     109  {
     110  #pragma omp section
     111  ...
     112  #pragma omp section
     113  ...
     114  }
     115}}}
     116
     117=>
     118
     119{{{
     120  {
     121    void section0() {
     122      ...
     123    }
     124    void section1() {
     125      ...
     126    }
     127    ...
     128    if (CIVL_owns(_nthreads, _tid, 0)
     129      section0();
     130    if (CIVL_owns(_nthreads, _tid, 1)
     131      section1();
     132    ...
     133    barrier unless nowait;
     134  }
     135}}}
     136
     137=== Translating `single` ===
    105138
    106139Nondeterministically choose a thread, i.e, `$choose_int(threads)`.   That thread executes the code, the rest skip it.
    107 The question is, which thread does the choosing?  The first thread to arrive at that construct?  Once again, try to determine if it matters.  If the modifications and reads do not involve and private data, it doesn't matter which thread does it, so make it thread 0.
     140The question is, which thread does the choosing?  The first thread to arrive at that construct?
     141
     142Once again, try to determine if it matters.  If the modifications and reads do not involve any private data, it doesn't matter which thread does it, so make it thread 0.
    108143
    109144There is a barrier at the end.
    110145
    111146
    112 === `barrier` ===
     147=== Translating `barrier` ===
    113148
    114149Provide some system functions for this.   All the threads in the team (threads[i]) register with a barrier object and partake in the barrier.  Can re-use that barrier object for multiple barriers.
    115150
    116 === `critical` ===
     151=== Translating `critical` ===
    117152
    118153Basically, use a lock for each critical name, plus one for the "no name".  All threads must obtain lock to enter the critical section, then release it.
    119154
    120 === `atomic` ===
     155=== Translating `atomic` ===
    121156
    122157This is just `$atomic`.
    123158
    124 === `ordered` ===
     159===  Translating`ordered` ===
    125160
    126161This can only be used inside and OMP `for` loop in which the pragma used the `ordered` clause.  (Check that.)  It indicates that the specified region must be executed in iteration order.