Advertisement
wandrake

Untitled

Feb 3rd, 2014
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include <fstream>
  2. #include <sstream>
  3. #include <string>
  4. #include <ff/farm.hpp>
  5.  
  6. #include "structs.hpp"
  7. #include "emitter.hpp"
  8. #include "worker.hpp"
  9.  
  10. using namespace std;
  11. using namespace ff;
  12.  
  13. int vals[N][N];
  14.  
  15. bool chk[N][N];
  16. bool path[N][N];
  17.  
  18. int nworkers;
  19. pair_t ** boundary;
  20. int64_t * bsizes;
  21. int64_t * bsizesmax;
  22. int slices;
  23.  
  24. extern int totinsert;
  25. extern int totiter;
  26.  
  27. int main(int argc, char * argv[]) {
  28.     nworkers = atoi(argv[1]);
  29.     slices = atoi(argv[2]);
  30.     char* fname = argv[3];
  31.  
  32.     ifstream is;
  33.     is.open(fname);
  34.  
  35.     if (is.fail()) {
  36.         cerr << "Error opening " << fname << endl;
  37.         return 1;
  38.     }
  39.     for (int i = 0; i < N; i++) {
  40.         for (int j = 0; j < N; j++) {
  41.             path[i][j] = false;
  42.             chk[i][j] = false;
  43.             is >> vals[i][j];
  44.         }
  45.     }
  46.  
  47. //    cout << "Letto" << endl;
  48. //    boundary = new vector<pair_t *>[SLICES];
  49.     bsizes = (int64_t*)malloc(slices*sizeof(int64_t));
  50.     bsizesmax = (int64_t*)malloc(slices*sizeof(int64_t));
  51.     boundary = (pair_t**)malloc(slices*sizeof(pair_t*));
  52.  
  53.     for (int i = 0 ; i < slices; i++) {
  54.         boundary[i] = (pair_t*)malloc(N*sizeof(pair_t));
  55.         bsizes[i] = 0;
  56.         bsizesmax[i] = N;
  57.     }
  58.  
  59.     // expanded.x = expanded.y = N/2;
  60.     boundary[0][0].x = N/2; boundary[0][0].y = N/2;
  61.     bsizes[0] = 1;
  62.     chk[N/2][N/2] = true;
  63.  
  64.     // toadd = new int64_t[SLICES];
  65.  
  66.     ff_farm<> farm;
  67.     vector<ff_node *> workers;
  68.     for (int i = 0; i < nworkers; i++) workers.push_back(new Worker);
  69.  
  70.     Emitter e;
  71.     farm.add_emitter(&e);
  72.     farm.add_workers(workers);
  73.     //farm.add_collector(new Collector);
  74.  
  75.     farm.wrap_around();
  76.  
  77.     ffTime(START_TIME);
  78.     farm.run_and_wait_end();
  79.     ffTime(STOP_TIME);
  80.  
  81. //    cout << "uins: " << (float)(totinsert)/(float)(totiter) << endl;
  82. //    cout << "iter: " << totiter << endl;
  83. //    cerr << "total time: " << ffTime(GET_TIME) << " (ms)" << endl;
  84. //    cerr << "total time: " << farm.ffwTime() << " (ms)" << endl;
  85.     cout << farm.ffwTime() << endl;
  86.     // farm.ffStats(cout);
  87. //    cout << farm.ffwTime();
  88.  
  89. /*    stringstream ss;
  90.     ss << "output" << nworkers;
  91.  
  92.     string q; ss >> q;
  93.  
  94.     ofstream os;
  95.     os.open(q.c_str());
  96.  
  97.     for (int i = 0; i < N; i++) {
  98.         for (int j = 0; j < N; j++) {
  99.             os << path[i][j] << " ";
  100.         }
  101.         os << endl;
  102.     }
  103. */
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement