Advertisement
canezzy

counter

Apr 3rd, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include "Counter.h"
  2.  
  3. extern concurrent_vector<unsigned char> clip2CounterVector;
  4. extern concurrent_hash_map<unsigned char, unsigned int> couterValues;
  5.  
  6. struct CounterClass {
  7.     concurrent_vector<unsigned char>& myClip2CounterVector;
  8.     concurrent_hash_map<unsigned char, unsigned int>& myCouterValues;
  9.  
  10.     CounterClass(concurrent_vector<unsigned char>& myClip2CounterVector_, concurrent_hash_map<unsigned char, unsigned int>& myCouterValues_) : myClip2CounterVector(myClip2CounterVector_), myCouterValues(myCouterValues_) {}
  11.    
  12.     void operator()(const blocked_range<unsigned int>& range) const {
  13.         concurrent_hash_map<unsigned char, unsigned int>::accessor a;
  14.         for (int p = range.begin(); p != range.end(); p++) {
  15.             myCouterValues.insert(a, myClip2CounterVector.at(p));
  16.             a->second += 1;
  17.             a.release();
  18.         }
  19.     }
  20.  
  21. };
  22.  
  23. RetVal Counter()
  24. {
  25.     unsigned char data;
  26.  
  27.     // array initialization
  28.     parallel_for(blocked_range<unsigned int>(0, clip2CounterVector.size()), CounterClass(clip2CounterVector, couterValues));
  29.     return RET_OK;
  30. }
  31.  
  32.  
  33.  
  34. ------------------------------------------------------------
  35.  
  36.  
  37.  
  38.  
  39. #ifndef _COUNTER_H_
  40. #define _COUNTER_H_
  41.  
  42. #include <queue>
  43. #include <vector>
  44. #include "defines.h"
  45. #include "tbb/concurrent_hash_map.h"
  46. #include "tbb/concurrent_vector.h"
  47. #include <tbb/parallel_for.h>
  48. using namespace std;
  49. using namespace tbb;
  50.  
  51. RetVal Counter();
  52.  
  53. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement