From bb20eddefe24a3528e46ab1c51a7e14e38277b65 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 9 Mar 2017 23:22:43 +0100 Subject: Starting to work on multithreaded code --- .gitignore | 3 + roots.cpp | 208 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 107 insertions(+), 104 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..04ab9e4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +roots +*.o +*.swp diff --git a/roots.cpp b/roots.cpp index 617eea3..d0cffe7 100644 --- a/roots.cpp +++ b/roots.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -231,81 +232,62 @@ void check(const vector &v){ for(const Com &c : v)check(c); } -template -class Generator{ - i64 n=0; - bool isEnd=false; - Polynomial current; - - Generator(bool isEnd):isEnd(isEnd){} - - static Generator endGen; - -public: - Generator(){ - operator++(); - } - - Generator begin() const { - return Generator(*this); - } - - const Generator& end(){ - return endGen; - } - - bool operator!=(const Generator &g){ - return isEnd!=g.isEnd; - } - - Generator& operator++(){ - if(!isEnd){ - current=F(n++); - if(current.size()==0)isEnd=true; - } - return *this; - } - - const Polynomial& operator*(){ - return current; - } -}; - -template -Generator Generator::endGen = Generator(true); - namespace Gens { + class Generator{ + public: + virtual Polynomial get(i64 n); + virtual i64 total(); + }; + template - Polynomial christensen(i64 n){ - int d=1; - while(d<=D){ - i64 p=ipow(2*N+1,d); - if(nD)return {}; + Polynomial poly(d+1); + for(int dd=0;ddD)return {}; - Polynomial poly(d+1); - for(int dd=0;dd - Polynomial derbyshire(i64 n){ - n+=2; - const int d=ilog(n); - if(d>D)return {}; - Polynomial poly(d+1); - for(int dd=0;ddD)return {}; + Polynomial poly(d+1); + for(int dd=0;dd r=FR::allroots(poly); + for(const Com &c : r){ + int x=(c.r-S.minx)/(S.maxx-S.minx)*S.width; + int y=(c.i-S.miny)/(S.maxy-S.miny)*S.height; + if(x<0||x>=S.width||y<0||y>=S.height)continue; + tally[S.width*y+x]++; + } + } +} + + +int main(int argc,char **argv){ int *tally; - int width,height; + + Settings S={ + .minx=0,.maxx=1.5, + .miny=0,.maxy=1.5, + .width=2000,.height=0 + }; + S.height=S.width/(S.maxx-S.minx)*(S.maxy-S.miny); + // const double minx=-3,maxx=3,miny=-3,maxy=3; if(argc==1){ - // const double minx=-3,maxx=3,miny=-3,maxy=3; - const double minx=0,maxx=1.5,miny=0,maxy=1.5; - width=2000; - height=width/(maxx-minx)*(maxy-miny); - - tally=new int[width*height](); - - int prevdegree=0; - clock_t clk=clock(); - - // for(const Polynomial &poly : Generator>()){ - for(const Polynomial &poly : Generator>()){ - // cerr<<"poly = "<