main.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <iomanip>
  2. #include <cilk/cilk.h>
  3. #include <cilk/cilk_api.h>
  4. #include "config.hpp"
  5. #include "coeffs.hpp"
  6. #include "polygon_generator.hpp"
  7. #include "results.hpp"
  8. #include "flint/fmpq_poly.h"
  9. ResultsReducer cilk_result;
  10. void box(string str){
  11. size_t w=str.size();
  12. cout<<"\u250c";
  13. for(size_t i=0;i<w+2;++i) cout<<"\u2500";
  14. cout<<"\u2510"<<endl;
  15. cout<<"\u2502 "<<str<<" \u2502"<<endl;
  16. cout<<"\u2514";
  17. for(size_t i=0;i<w+2;++i) cout<<"\u2500";
  18. cout<<"\u2518"<<endl;
  19. }
  20. void disp_info(){
  21. box("Compute Fp's series of Self Avoiding Polygon");
  22. cout<<endl;
  23. cout<<" Maximal length is "<<max_len<<endl;
  24. cout<<" Workers number is "<<__cilkrts_get_nworkers()<<endl;
  25. }
  26. void treat(Polygon* P){
  27. size_t l=P->length;
  28. size_t i=l/2-1;
  29. ++cilk_result.numbers(i);
  30. fmpq_poly_t fp;
  31. fmpq_poly_init(fp);
  32. P->fp(fp);
  33. cilk_result.add_fp(i,fp);
  34. delete P;
  35. }
  36. int main(){
  37. disp_info();
  38. compute_coeffs();
  39. size_t nb[max_len/2];
  40. PolygonGenerator gen;
  41. size_t total=0;
  42. Polygon* P;
  43. while(gen.next()){
  44. P=new Polygon;
  45. gen.set(*P);
  46. cilk_spawn treat(P);
  47. ++total;
  48. }
  49. cilk_sync;
  50. //! Mutiplicative coeffcient for the sum of Fp
  51. fmpq_t c;
  52. fmpq_init(c);
  53. //! Numerator and denominator of the coefficient c
  54. fmpz_t d,n;
  55. fmpz_init(n);
  56. fmpz_init(d);
  57. //! Init denominator to 256
  58. fmpz_set_si(d,256);
  59. for(size_t i=1;2*i<max_len;++i){
  60. //! Length of the SAP
  61. Int l=2*i+2;
  62. cout<<endl<<"=== Length "<<l<<" ==="<<endl;
  63. //! Set numerator of c
  64. fmpz_set_si(n,2*l);
  65. //! Set c
  66. fmpq_set_fmpz_frac(c,n,d);
  67. //! Retrieve Fp sum in res
  68. fmpq_poly_t res;
  69. fmpq_poly_init(res);
  70. fmpq_poly_set(res,cilk_result.get_fp(i));
  71. //! Multiply res by c
  72. fmpq_poly_scalar_mul_fmpq(res,res,c);
  73. //! Display res
  74. char* str=fmpq_poly_get_str_pretty(res,"x");
  75. cout<<" > number : "<<cilk_result.numbers(i)<<endl;
  76. cout<<" > coeff : "<<str<<endl;
  77. delete str;
  78. //! Update denominator
  79. fmpz_mul_si(d,d,16);
  80. }
  81. cout<<endl<<">>> Total of SAP computed : "<<total<<endl;
  82. cout<<endl;
  83. }