Changes between Version 63 and Version 64 of OpenMPTransformation


Ignore:
Timestamp:
03/29/15 23:20:57 (11 years ago)
Author:
mrogers
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OpenMPTransformation

    v63 v64  
    557557== Translating Orphan Functions ==
    558558
    559 TODO
     559{{{
     560#include <omp.h>
     561
     562double x[10];
     563
     564float foo (){
     565  int i;
     566
     567  #pragma omp for
     568    for (int i=0; i < 10; i++){
     569      x[i] = i;
     570    }
     571}
     572
     573
     574int main (int argc, char *argv[]) {
     575  int i;
     576
     577  #pragma omp parallel
     578    foo();
     579 
     580}
     581}}}
     582
     583=>
     584
     585{{{
     586#include <omp.h>
     587
     588//Struct to hold all data for some thread
     589struct parallel {
     590  $omp_team *team;
     591  $omp_shared **shared;
     592  (void *) **local;
     593};
     594
     595//Some stack data structure
     596stack *arr;
     597
     598double x[10];
     599
     600void foo(int _tid){
     601  struct parallel currentThread = arr[_tid].peek();
     602  $domain loop_domain = {0..10-1};
     603  $domain(1) my_iters = ($domain(1))$omp_arrive_loop(currentThread.team, FOR_LOC++, loop_domain, STRATEGY);
     604
     605  $for (int i : my_iters) {
     606    double tmpWrite0;
     607    tmpWrite0 = i;
     608    //Get index of this shared var
     609    int index = ... index of the x var in currentThread.shared
     610    $omp_write(currentThread.shared[i], &currentThread.local[i], &tmpWrite0);
     611  }
     612 
     613  $barrier_and_flush(currentThread.team);
     614}
     615
     616
     617int main (int argc, char *argv[]) {
     618  int i;
     619 
     620  int _nthreads = 1+$choose_int(THREAD_MAX);
     621  $omp_gteam gteam = $omp_gteam_create($here, nthreads);
     622  $omp_gshared x_gshared = $omp_gshared_create(gteam, &x);
     623
     624  *arr = (stack *)malloc(_nthreads * sizeof(stack))
     625
     626  $parfor (int _tid : {0..nthreads-1}) {
     627    $omp_team team = $omp_team_create($here, gteam, _tid);
     628    $omp_shared x_shared = $omp_shared_create(team, x_gshared);
     629    double  x_local[10];
     630        int  x_status[10];
     631
     632        //create struct that holds all data for current thread
     633       
     634        struct parallel currentThread; 
     635        currentThread.team = team;
     636        currentThread.shared = all shared variables
     637        currentThread.local = all local variables
     638       
     639        arr[_tid].push(currentThread);
     640       
     641    foo(_tid);
     642
     643    $omp_barrier_and_flush(team);
     644    $omp_shared_destroy(x_shared);
     645    $omp_team_destroy(team);
     646    arr[_tid].pop();
     647  }
     648  $omp_gshared_destroy(x_gshared);
     649  $omp_gteam_destroy(gteam); 
     650}
     651}}}
    560652
    561653== Translating functions ==