results.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #ifndef RESULTS_HPP
  2. #define RESULTS_HPP
  3. #include <cilk/cilk.h>
  4. #include <cilk/reducer.h>
  5. #include "config.hpp"
  6. #include "flint/fmpq_poly.h"
  7. //! Number of results
  8. static const size_t result_size=max_len/2;
  9. //! Structure storing results
  10. struct Results{
  11. //! Number of SAP
  12. size_t numbers[result_size];
  13. //! Sum of the Fp
  14. fmpq_poly_t sum_fp[result_size];
  15. //! Empty constructor
  16. Results();
  17. //! Reset
  18. void reset();
  19. };
  20. //!**************************
  21. //! Class for esults reducer
  22. //!**************************
  23. class ResultsReducer{
  24. private:
  25. struct Monoid:cilk::monoid_base<Results>{
  26. static void reduce(Results* left, Results* Right);
  27. };
  28. cilk::reducer<Monoid> imp_;
  29. public:
  30. ResultsReducer();
  31. //! Obtain reference to numbers
  32. size_t& numbers(size_t i);
  33. //! Add an Fp coeff
  34. //! \param i lenght of the SAP
  35. //! \param p poly of the FP
  36. void add_fp(size_t i,fmpq_poly_t p);
  37. //! Return pointer to th FP poly
  38. fmpq_poly_struct* get_fp(size_t i);
  39. void reset();
  40. };
  41. extern ResultsReducer cilk_results;
  42. //***********
  43. //* Inlines *
  44. //***********
  45. inline
  46. Results::Results(){
  47. reset();
  48. }
  49. inline void
  50. Results::reset(){
  51. for(size_t i=0;i<result_size;++i){
  52. numbers[i]=0;
  53. fmpq_poly_init(sum_fp[i]);
  54. fmpq_poly_zero(sum_fp[i]);
  55. }
  56. }
  57. inline
  58. ResultsReducer::ResultsReducer(){
  59. reset();
  60. }
  61. inline void
  62. ResultsReducer::Monoid::reduce(Results* left,Results* right){
  63. for(size_t i=0;i<result_size;++i){
  64. left->numbers[i]+=right->numbers[i];
  65. fmpq_poly_add(left->sum_fp[i],left->sum_fp[i],right->sum_fp[i]);
  66. }
  67. }
  68. inline void
  69. ResultsReducer::reset(){
  70. imp_.view().reset();
  71. }
  72. inline size_t&
  73. ResultsReducer::numbers(size_t i){
  74. return imp_.view().numbers[i];
  75. }
  76. inline void
  77. ResultsReducer::add_fp(size_t i,fmpq_poly_t p){
  78. return fmpq_poly_add(imp_.view().sum_fp[i],imp_.view().sum_fp[i],p);
  79. }
  80. inline fmpq_poly_struct*
  81. ResultsReducer::get_fp(size_t i){
  82. return imp_.view().sum_fp[i];
  83. }
  84. #endif