diff options
Diffstat (limited to 'roots.cpp')
-rw-r--r-- | roots.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -235,14 +235,14 @@ void check(const vector<Com> &v){ namespace Gens { class Generator{ public: - virtual Polynomial get(i64 n); - virtual i64 total(); + virtual Polynomial get(i64 n) const = 0; + virtual i64 total() const = 0; }; template <int N,int D> class Christensen : public Generator{ public: - Polynomial get(i64 n){ + Polynomial get(i64 n) const { int d=1; while(d<=D){ i64 p=ipow(2*N+1,d); @@ -260,7 +260,7 @@ namespace Gens { return poly; } - i64 total(){ + i64 total() const { i64 n=0; for(int d=1;d<=D;d++){ n+=ipow(2*N+1,d); @@ -272,7 +272,7 @@ namespace Gens { template <int D> class Derbyshire : public Generator{ public: - Polynomial get(i64 n){ + Polynomial get(i64 n) const { n+=2; const int d=ilog(n); if(d>D)return {}; @@ -284,7 +284,7 @@ namespace Gens { return poly; } - i64 total(){ + i64 total() const { return (1<<(D+1))-2; } }; @@ -358,7 +358,7 @@ struct Settings{ }; -void tallyThreadFunc(Gens::Generator &gen,i64 start,i64 end,int *tally,const Settings &S){ +void tallyThreadFunc(const Gens::Generator &gen,i64 start,i64 end,int *tally,const Settings &S){ for(i64 index=start;index<end;index++){ const Polynomial &poly=gen.get(index); vector<Com> r=FR::allroots(poly); @@ -385,25 +385,32 @@ int main(int argc,char **argv){ if(argc==1){ // Gens::Christensen<4,5> gen; - Gens::Derbyshire<15> gen; + Gens::Derbyshire<20> gen; i64 ntotal=gen.total(); int ncores=thread::hardware_concurrency(); cerr<<"Factoring "<<ntotal<<" polynomials..."<<endl; - cerr<<"Using "<<ncores<<" threads"<<endl; + cerr<<"Using "<<ncores<<" thread"<<(ncores==1?"":"s")<<endl; thread ths[ncores]; int **tallies=new int*[ncores]; + cerr<<"Spawning threads: "; for(int i=0;i<ncores;i++){ tallies[i]=new int[S.width*S.height](); ths[i]=thread(tallyThreadFunc,gen,ntotal*i/ncores,ntotal*(i+1)/ncores,tallies[i],S); + if(i!=0)cerr<<", "; + cerr<<i; } + cerr<<endl<<"Joining threads: "; tally=new int[S.width*S.height]; for(int i=0;i<ncores;i++){ ths[i].join(); + if(i!=0)cerr<<", "; + cerr<<i; for(int j=0;j<S.width*S.height;j++){ tally[j]+=tallies[i][j]; } delete[] tallies[i]; } + cerr<<endl; cerr<<"Writing data..."<<endl; writeData("out.txt",tally,S.width,S.height); |