Changes between Version 32 and Version 33 of Next-GenOpenMPTransformation


Ignore:
Timestamp:
10/08/19 17:37:56 (7 years ago)
Author:
wuwenhao
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Next-GenOpenMPTransformation

    v32 v33  
    11= INDEX =
    2 [https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#TheSequentiallyConsistentSubsetofOpenMP 1. The Sequentially Consistent Subset of OpenMP]\\
    3 [https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#OpenMPConstructs 2. Supported OpenMP Features]\\
    4 [https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#OpenMPSimplifier 3. OpenMP Simplification]\\
    5 [https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#TransformationDetails 4. OpenMP Transofrmation]
     2[https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#a1.TheSequentiallyConsistentSubsetofOpenMP 1. The Sequentially Consistent Subset of OpenMP]\\
     3[https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#a2.SupportedOpenMPFeatures 2. Supported OpenMP Features]\\
     4[https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#a3.OpenMPSimplification 3. OpenMP Simplification]\\
     5[https://vsl.cis.udel.edu/trac/civl/wiki/Next-GenOpenMPTransformation#a4.OpenMPTransformations 4. OpenMP Transofrmation]
    66
    77= 1. The Sequentially Consistent Subset of OpenMP =
     
    396396
    397397== Translations of specific directives ==
     398[1. parallel construct]
     399[2. worksharing-loop construct]
    398400
    399401=== Translating `parallel` ===
     
    402404
    403405{{{
    404   float x; // shared
    405   int y; // private
    406   #pragma omp parallel shared(x) private(y)
     406  float a; // shared
     407  int i; // private
     408  int j; // firstprivate
     409  #pragma omp parallel shared(a) private(i) firstprivate(j)
    407410  {
    408     ...
    409     x=5.2;
    410     y=3;
    411    ...
     411    BLOCK
    412412  }
    413413}}}
     
    416416
    417417{{{
    418   float x;
    419   int y;
    420   { // begin parallel construct
    421     int _nthreads = 1+$choose_int(THREAD_MAX);
     418  float a; // shared
     419  int i; // private
     420  int j; // firstprivate
     421  { // parallel construct (begin)
     422    int nthreads = 1+$choose_int(num_threads);
     423    int fstpvt_j = j;
    422424    $omp_gteam gteam = $omp_gteam_create($here, nthreads);
    423425
    424     $parfor (int _tid : {0..nthreads-1}) {
    425       $omp_team team = $omp_team_create($here, gteam, _tid);
    426       int _y; // private variable
    427 
    428       $write_set_push();
    429       $read_set_push();
    430       ...
    431       x = 5.2;
    432       _y = 3;
    433       ...
    434       // check for dataraces (collective operation)
    435       $omp_barrier_and_flush(team, $read_set_pop(), $write_set_pop());
     426    $parfor (int tid : ($domain){0..nthreads-1}) {
     427      $local_start();
     428      $omp_team team = $omp_team_create($here, gteam, tid);
     429      $read_set_push(); $write_set_push();
     430
     431      int i; // private
     432      int j = fstpvt_j; // first private init.
     433
     434      transfromed(BLOCK)
     435
     436      $omp_barrier_and_flush(team); //check data race
     437
     438      $read_set_pop(); $write_set_pop();
    436439      $omp_team_destroy(team);
    437     } // end $parfor
     440      $local_end();
     441    }
     442
    438443    $omp_gteam_destroy(gteam);
    439   } // end parallel construct
     444  } // parallel construct (end)
    440445}}}
    441446
    442447All variables that occur in the parallel construct, i.e., the lexical extent of the parallel construct, must be determined to be either private or shared.   This is determined by the clauses and the default rules as specified in the OpenMP Standard.  Obviously any variable declared within the construct itself must be private.
    443448
    444 For all private variables `y` not declared within the parallel construct, create a new variable of the same type, `_y`.    The new variable is declared within the thread scope.  If `y` is also firstprivate,  then `_y` is initialized with the value of `y`, e.g. `int _y=y;`.  Otherwise, `_y` is uninitialized, so has an undefined value.
     449For all '''private''' variables `i` and `j` (out of `$parfor`) not declared within
     450the parallel construct, create new variables of the same type, `i` and `j` (in the `$parfer`).
     451The new variable is declared within the thread scope. 
     452`j` (out of `$parfor`) is also '''firstprivate''',  then `j` (in the `$parfor`) is
     453initialized with the value of `fstpvt_j`. 
     454Otherwise, `i` (in the `$parfor`) is uninitialized, so has an undefined value.
    445455
    446456=== Translating `for` ===
     
    451461{{{
    452462#pragma omp for
    453 for (i=0; i<n; i++) 
    454   S
    455 }}}
    456 
    457 =>
    458 
    459 {{{
    460 {
    461   $domain loop_domain = {0..n-1};
    462   $domain(1) my_iters = ($domain(1))$omp_arrive_loop(team, FOR_LOC++, loop_domain, STRATEGY);
    463 
    464   $for (int i : my_iters) {
    465     translate(S);
     463for (i=1; i<n; i=i+1) {
     464  BLOCK
     465}
     466}}}
     467
     468=>
     469
     470{{{
     471{ // worksharing-loop construct (begin)
     472  // [lb .. ub # step] (lb <= ub)
     473  $domain loop_domain = {1 .. n-1 # 1};
     474  $domain(1) loop_dist = ($domain(1))$omp_arrive_loop(
     475               team, loop_id++, loop_domain, STRATEGY);
     476
     477  $for (int i : loop_dist) {
     478    transfromed(BLOCK)
    466479  }
    467   $barrier_and_flush(team, $read_set_pop(), $write_set_pop());
    468   $read_set_push(); $write_set_push();
    469 }
     480  $barrier_and_flush(team);
     481} // worksharing-loop construct (end)
    470482}}}
    471483
     
    477489  for (j=0; j<m; j++)
    478490    for (k=0; k<l; k++) {
    479       S
    480     }
    481 }}}
    482 
    483 =>
    484 
    485 {{{
    486 {
    487   $domain loop_domain = {0..n-1, 0..m-1, 0..l-1};
    488   $domain(3) my_iters = ($domain(3))$omp_arrive_loop(team, FOR_LOC++, loop_domain, STRATEGY);
     491      BLOCK
     492    }
     493}}}
     494
     495=>
     496
     497{{{
     498{ // worksharing-loop construct (begin)
     499  $domain loop_domain = {0..n-1 #1, 0..m-1 #1, 0..l-1 #1};
     500  $domain(3) loop_dist = ($domain(3))$omp_arrive_loop(
     501               team, loop_id++, loop_domain, STRATEGY);
    489502
    490503  $for (int i, j, k : my_iters) {
    491     translate(S);
     504    transfromed(BLOCK)
    492505  }
    493   $omp_barrier_and_flush(team, $read_set_pop(), $write_set_pop());
    494   $read_set_push(); $write_set_push();
    495 }
     506  $omp_barrier_and_flush(team);
     507} // worksharing-loop construct (end)
    496508}}}
    497509