main.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "avx_matrix.hpp"
  8. #include "results.hpp"
  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. Reel fp=P->fp();
  31. cilk_result.sum_fp(i)+=fp;
  32. delete P;
  33. }
  34. int main(){
  35. cout<<std::setprecision(20);
  36. disp_info();
  37. compute_coeffs();
  38. size_t nb[max_len/2];
  39. Reel res[max_len/2];
  40. Reel coeff[max_len/2];
  41. for(size_t i=0;2*i<max_len;++i){
  42. nb[i]=0;
  43. res[i]=0;
  44. }
  45. PolygonGenerator gen;
  46. size_t total=0;
  47. Polygon* P;
  48. while(gen.next()){
  49. P=new Polygon;
  50. gen.set(*P);
  51. cilk_spawn
  52. treat(P);
  53. ++total;
  54. }
  55. cilk_sync;
  56. Reel d=256;
  57. for(size_t i=1;2*i<max_len;++i){
  58. Reel l=2*i+2;
  59. cout<<endl<<"=== Length "<<l<<" ==="<<endl;
  60. Reel r=cilk_result.sum_fp(i);
  61. Reel n=2*l;
  62. coeff[i]=(n*r)/d;
  63. cout<<" > number : "<<cilk_result.numbers(i)<<endl;
  64. cout<<" > value : "<<coeff[i]<<endl;
  65. d*=16;
  66. }
  67. cout<<endl<<">>> Total : "<<total<<endl;
  68. cout<<endl<<">>> Coefficients list : "<<endl;
  69. for(size_t i=1;2*i<max_len;++i){
  70. cout<<coeff[i]<<" ";
  71. }
  72. cout<<endl;
  73. }