validator.cc

Go to the documentation of this file.
00001 
00007 #include "at_startup.H"
00008 #include <fstream>
00009 #include <sstream>
00010 #include <gmp.h>
00011 #include "qsieve.H"
00012 #include "StaticFactorbase.H"
00013 
00014 using namespace std;
00015 
00016 const string RecoveryFile         = "recovery.dat";
00017 const string StaticRelationsFile  = "static_relations.dat";
00018 const string SpecialRelationsFile = "special_relations.dat";
00019 
00020 
00021 // for Recovery
00022 filebuf Recovery_buffer;
00023 ostream Recovery_to_file (&Recovery_buffer);
00024 istream Recovery_from_file (&Recovery_buffer);
00025 
00026 
00027 mpz_t n, // number to factorize (will be reduced during factorization)
00028       kN; // input for MPQS (includes a suitable multiplier)
00029 
00030 
00031 
00032 #include "StaticRelations.H"
00033 #include "Sieving.H"
00034 CRelation* StaticRelations::GLS[StaticFactorbase::MaxSize] = {NULL};
00035 int StaticRelations::Filling_GLS = 0;
00036 
00037 
00038 // dummy definitions to satisfy static linker:
00039 CmpqsFactor CRelation::combine(istream&)
00040 {
00041   return CmpqsFactor();
00042 }
00043 
00044 CmpqsFactor CRelation::multi_combine_main(istream &)
00045 {
00046   return CmpqsFactor();
00047 }
00048 
00049 
00050 #include "ConfigFile.cc"
00051 
00052 
00053 //int main(const int argc, const char* const argv[])
00054 int main(const int argc, const char* const *)
00055 {
00056 
00057   PrintHeader("Qsieve relation validator");
00058   cout.setf(ios::fixed); // fixed decimal notation, not scientific notation!
00059 
00060   if (argc!=1) exit(1);
00061 
00062   mpz_init(n); // our number to factorize
00063   mpz_init(kN);
00064 
00065   Read_ConfigFile();
00066 
00067   Recovery_buffer.open(RecoveryFile.c_str(),ios::in|ios::out|ios::ate);
00068   // offenbar wird trotz ios::ate nicht (immer) ans Ende positioniert
00069   // deshalb wird die Testabfrage modifiziert:
00070   if (Recovery_from_file) Recovery_from_file.seekg(0,ios::end);
00071 #ifdef STL_STREAM_workaround
00072   if ( (!Recovery_from_file) || (Recovery_from_file.tellg()==std::streampos(0)) || (Recovery_from_file.tellg()==std::streampos(-1)) )
00073 // tellg()==0 indicates empty file -> we cannot recover
00074 // tellg()==-1 indicates failure -> we cannot recover
00075 // remark:
00076 //  in gcc 3.4 (cvs-experimental-2003-10-17 we cannot compare with "<" !!)
00077 //  do we really need a workaround to check this condition? 
00078 #else
00079   if ( (!Recovery_from_file) || (Recovery_from_file.tellg()<1) )
00080 #endif /* STL_STREAM_workaround */
00081     {
00082       cerr << "No recovery data found. Cannot validate!" << endl;
00083       exit(1);
00084     }
00085       
00086   Recovery_from_file.seekg(0,ios::beg);
00087   Recovery_to_file.seekp(0,ios::beg);
00088   Recovery_from_file >> n; // retrieve number
00089   Recovery_from_file.ignore(1,'\n');
00090 
00091   cout << "Checking relations for" << endl;
00092   cout << n << endl;
00093 
00094   determine_best_MPQS_Multiplier(n,kN,MPQS_Multiplier); // calculate a good/optimal value for fastest possible sieving
00095   tune_parameters(mpz_sizeinbase(n,10)); // tune parameters for n
00096 
00097 #ifdef VERBOSE_NOTICE
00098   cout << "n=" << n << endl;
00099   cout << "Size of static factorbase: " << StaticFactorbase::Size() << endl;
00100   cout << "Factor-Threshold (Exponent): " << Factor_Threshold << endl;
00101   cout << "Sieveinterval per polynomial: [" << -LogicalSieveSize << "," << LogicalSieveSize << "]" << endl;
00102 #endif
00103 
00104   if ( sqrt(mpz_get_d(kN)) < PhysicalSieveSize )
00105     {
00106       cerr << "Sieve size too big (you may want to reduce its size)!" << endl;
00107       exit(1);
00108     }
00109   
00110   StaticFactorbase::compute_StaticFactorbase();
00111 
00112   // are all the relations valid?
00113   CRelation::SanityCheckRelationsFile(StaticRelationsFile);
00114   CRelation::SanityCheckRelationsFile(DynamicRelationsFile);
00115   CRelation::SanityCheckRelationsFile(SpecialRelationsFile);
00116   return 0;
00117 }

Generated on Wed Nov 7 23:29:26 2007 for Qsieve by  doxygen 1.5.4