From cTuning.org

(Difference between revisions)
Jump to: navigation, search

Gfursin (Talk | contribs)
(New page: <pre> using namespace std; #include<stdlib.h> #include<time.h> #include<iostream> #include<signal.h> #include<sys/time.h> #include "ProfFcts.h" using namespace DynAnProfTLS; const int...)
Newer edit →

Current revision


using namespace std;

#include<stdlib.h>
#include<time.h>
#include<iostream>
#include<signal.h>
#include<sys/time.h>

#include "ProfFcts.h"

using namespace DynAnProfTLS;

const int N = 200000;
const int P = 64; //200; //1000;
const int Q = 32;  //5;   //100;

const int M_interv = 18;
const int M_congru = 16;
const int M_sync_c = 4;
const int M_sync_b = 1024;

/*
const int N = 300000;
const int P = 1; //200; //1000;
const int Q = 1;  //5;   //100;
*/
int my_arr[P][N];

timeval start_time, end_time;
unsigned long running_time = 0;

unsigned int DiffTime(timeval* time2, timeval* time1) {
	uint diff = 
       (time2->tv_sec-time1->tv_sec)*1000000 + (time2->tv_usec-time1->tv_usec);
	return diff;
}


void init() {
    int j, k;
    for(int j = 0; j<P; j++ ) {
      for(int k = 0; k < N; k++) {
        my_arr[j][k] = j + k + j * k -33;
      }
    }  
}

void loop_orig() {
  int i, j, k;

  gettimeofday ( &start_time, 0 );


  for(i = 0; i < Q; i++) {
    for(j = M_sync_c; j<P; j++ ) {
      for(k = M_interv; k < N; k++) {
        int ind1 = k-M_congru, ind2 = 5;
        ind2 += my_arr[j][ind1] + 3;

        if(k % M_interv == 0) {
                 ind2 = my_arr[j][k-(M_interv-1)] * 2;
        } else {
                 ind2 = 33;
        }


        ind1 =  my_arr[j][k%M_sync_c];

        my_arr[j][k%M_sync_b] = ind2 + ind1; 

        if(rand() % 1243 == 0) {
          ind2 += my_arr[j][k-1];
        }

        my_arr[j][k] = my_arr[j-M_sync_c][k] * ind1 * ind2;
      }
    }
  }

  gettimeofday( &end_time, 0 );
  running_time += DiffTime(&end_time,&start_time);
  cout<<"Running time original:  "<<running_time<<endl;

}


inline
LoopMD* loop_profiled_init() {
  /*******************/
  /***** Phase 1 *****/
  /** Create loops ***/
  /*******************/

  LoopMD* root;
  {
    // for loopR -- make loop's metadata
    LoopMD* parent = NULL;
    LoopMD* loop   = makeLoopMD_prologue(parent , 1, 1);
    root =  loop;

    {
      //add Metadata Variable's Addresses 
      const char* names[1] = { "my_arr" };
      void*       addrs[1] = { &my_arr[0][0] };

      addMemFixPoints(1, names, addrs);

    }


    {
      // for loop1 -- make loop's metadata
      LoopMD* parent = loop;
      LoopMD* loop   = makeLoopMD_prologue(parent , 1, 1);

      // for loop2
      {
        LoopMD* parent = loop;
        LoopMD* loop   = makeLoopMD_prologue(parent , 0, 2);

        fillPrgPtMD(loop, true, 58, 24, "Congr1RD.cpp"); // read  pp

        fillPrgPtMD(loop, true, 61, 24, "IntervRD.cpp"); // read  pp
        fillPrgPtMD(loop, true, 67, 9,  "CongrBar2RD.cpp"); // write pp


        fillPrgPtMD(loop, false, 69, 24, "SyncBarWR.cpp"); // read  pp
        fillPrgPtMD(loop, true, 72, 9, "ResidumRD.cpp"); // write pp


        fillPrgPtMD(loop, true, 75, 24, "OuterCongrRD3.cpp"); // read  pp
        fillPrgPtMD(loop, false, 75, 9, "OuterCongrWR3.cpp"); // write pp


        //makeLoopMD_epilogue(loop);
      }

      //makeLoopMD_epilogue(loop);
    }


    // only for the ROOT of the loop-nest call:
    makeLoopMD_epilogue(loop);
  }
  return root;
}

void loop_profiled(LoopMD* root) {


  /*********************/
  /****** Phase 1 ******/
  /*** Profile loops ***/
  /*********************/
 
  gettimeofday ( &start_time, 0 );

  {
    LoopMD*  parent     = NULL;
    LoopMD*  loop       = root;
    int i, j, k;

    for(i = 0; i < Q; i++) {
      int loop_ind = 0;
      int pp_ind   = 0;

      { // start loop1
        LoopMD*  parent    = loop;
        LoopMD*  loop      = parent->childs[loop_ind++];
    
        for(j = M_sync_c; j<P; j++ ) {
          int    loop_ind  = 0;
          int    pp_ind    = 0;

          {  // start loop2
             LoopMD*  parent    = loop;
             LoopMD*  loop      = parent->childs[loop_ind++];

             for(k = M_interv; k < N; k++) {
               int    loop_ind  = 0;
               int    pp_ind    = 0;

               int ind1 = k-M_congru, ind2 = 5;

               if(loop->prof_ON) gather_pp(loop, pp_ind++, &my_arr[j][ind1]);
               ind2 += my_arr[j][ind1] + 3;

               if(k % M_interv == 0) {
                   if(loop->prof_ON) gather_pp(loop, pp_ind, &my_arr[j][k - (M_interv - 1)]);
                   ind2 += my_arr[j][k-(M_interv-1)] * 2;
               } else {
                 ind2 += 33;
               }

               pp_ind++;

               if(loop->prof_ON) gather_pp(loop, pp_ind++, &my_arr[j][k%M_sync_c]);
               ind1 =  my_arr[j][k%M_sync_c];

               if(loop->prof_ON) gather_pp(loop, pp_ind++, &my_arr[j][k%M_sync_b]);
               my_arr[j][k%M_sync_b] = ind2 + ind1; 

               if(rand() % 1243 == 0) {
                 if(loop->prof_ON) gather_pp(loop, pp_ind, &my_arr[j][k-1]);
                 ind2 += my_arr[j][k-1];
               }
               pp_ind++;

               if(loop->prof_ON) gather_pp(loop, pp_ind++, &my_arr[j-M_sync_c][k]);
               if(loop->prof_ON) gather_pp(loop, pp_ind++, &my_arr[j][k]    );
               my_arr[j][k] = my_arr[j-M_sync_c][k] * ind1 * ind2;

               iteration_epilogue(loop);
             } // end loop 2
             loop_ended(loop);
          }

          iteration_epilogue(loop);
        } // end loop 1
        loop_ended(loop);

      }
      iteration_epilogue(loop);
    } // end loop root
    loop_ended(loop);
    give_solution(loop);
  }

  gettimeofday( &end_time, 0 );
  running_time += DiffTime(&end_time,&start_time);
  cout<<"Running time profiling: "<<running_time<<endl;
}


int main(int argc, char* argv[]) {
  init();

  if( atoi(argv[1])==33 ) {
    LoopMD* root = loop_profiled_init();
    loop_orig();
  } else {
    LoopMD* root = loop_profiled_init();
    loop_profiled(root);
  } 
}


/*
       {
          ProfItem* new_ptr;
          ULONG new_sz = maxProfilingSizePP(2);
          cout<<"Allocating: "<<new_sz<<" elements"<<endl;
          new_ptr = (ProfItem*) malloc( sizeof(ProfItem) * new_sz );
          cout<<"after allocation"<<endl;
       }
*/


Locations of visitors to this page