results.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef RESULTS_HPP
  2. #define RESULTS_HPP
  3. #include <cilk/cilk.h>
  4. #include <cilk/reducer.h>
  5. #include "config.hpp"
  6. static const size_t result_size=max_len/2;
  7. struct Results{
  8. size_t numbers[result_size];
  9. Reel sum_fp[result_size];
  10. Results();
  11. void reset();
  12. };
  13. class ResultsReducer{
  14. private:
  15. struct Monoid:cilk::monoid_base<Results>{
  16. static void reduce(Results* left, Results* Right);
  17. };
  18. cilk::reducer<Monoid> imp_;
  19. public:
  20. ResultsReducer();
  21. size_t& numbers(size_t i);
  22. Reel& sum_fp(size_t i);
  23. void reset();
  24. };
  25. extern ResultsReducer cilk_results;
  26. inline
  27. Results::Results(){
  28. reset();
  29. }
  30. inline void
  31. Results::reset(){
  32. for(size_t i=0;i<result_size;++i){
  33. numbers[i]=0;
  34. sum_fp[i]=0;
  35. }
  36. }
  37. inline
  38. ResultsReducer::ResultsReducer(){
  39. reset();
  40. }
  41. inline void
  42. ResultsReducer::Monoid::reduce(Results* left,Results* right){
  43. for(size_t i=0;i<result_size;++i){
  44. left->numbers[i]+=right->numbers[i];
  45. left->sum_fp[i]+=right->sum_fp[i];
  46. }
  47. }
  48. inline void
  49. ResultsReducer::reset(){
  50. imp_.view().reset();
  51. }
  52. inline size_t&
  53. ResultsReducer::numbers(size_t i){
  54. return imp_.view().numbers[i];
  55. }
  56. inline Reel&
  57. ResultsReducer::sum_fp(size_t i){
  58. return imp_.view().sum_fp[i];
  59. }
  60. #endif