file-client.cc

Go to the documentation of this file.
00001 
00006 // Remark: the file-client joins only the sieving part for mpqs!
00007 // elliptic curves are not processed, since that can be done using
00008 // the qsieve standalone version!
00009 
00010 
00011 #include "at_startup.H"
00012 
00013 
00014 // sanity checks
00015 #ifndef IS_CLIENT
00016  #error "The file-client is a client!"
00017 #endif
00018 
00019 #ifdef IS_SERVER
00020  #error "The file-client is not a server!"
00021 #endif
00022 
00023 #ifdef USE_NETWORK
00024  #error "The file-client uses no network features!"
00025 #endif
00026 
00027 #ifdef IS_STANDALONE
00028  #error "The file-client is not standalone!"
00029 #endif
00030 
00031 
00032 
00033 extern "C"
00034 {
00035  #include <unistd.h>
00036 }
00037 
00038 #include <cstdio>
00039 #include <cstdlib>
00040 #include <fstream>
00041 #include <sstream>
00042 #include <cmath>
00043 #include <gmp.h>
00044 #include <list>
00045 #include <set>
00046 #include <ctime>
00047 
00048 #include "qsieve.H"
00049 #include "StaticFactorbase.H"
00050 
00051 
00052 
00053 #include <vector>
00054 #include <stack>
00055 #include <algorithm>
00056 
00057 
00058 #ifdef NOTIFY_PARENT
00059  #warning "undefining NOTIFY_PARENT, since this is not a networked server"
00060  #undef NOTIFY_PARENT
00061 #endif
00062 
00063 
00064 const string StaticRelationsFile  = "static_relations.dat";
00065 const string SpecialRelationsFile = "special_relations.dat";
00066 
00067 
00068 string communication_name;
00069 ofstream communication_stream;
00070 
00071 
00072 #include "mpqsPolynom.H"
00073 
00074 
00075 mpz_t n, // number to factorize (will be reduced during factorization)
00076       kN; // input for MPQS (includes a suitable multiplier)
00077 
00078 
00079 #include "StaticRelations.H"
00080 #include "DynamicRelations.H"
00081 #include "SpecialRelations.H"
00082 
00083 #include "Sieving.H"
00084 #include "ConfigFile.cc"
00085 
00086 
00087 CmpqsPolynom Polynom; // object to manage polynomial computations for multipolynomial sieve (MPQS)
00088 #include "mpqsStatistics.cc" // statistical stuff about found relations, client connections, etc.
00089 
00090 
00091 #include "modulo.H" // modulo operations for unsigned int
00092 using namespace numtheory;
00093 
00094 #include "StaticRelations.cc"
00095 #include "CRelation-inc.cc"
00096 
00097 
00098 void cleanup_memory()
00099 {
00100 #ifdef VERBOSE_INFO
00101   cout << "cleanup allocated memory" << endl;
00102 #endif
00103   StaticRelations::cleanup_memory();
00104 #ifdef VERBOSE_INFO
00105   cout << "cleanup mpz numbers" << endl;
00106 #endif
00107   mpz_clear(kN); mpz_clear(n);
00108 #ifdef VERBOSE_INFO
00109   cout << "mpz numbers cleared." << endl;
00110 #endif
00111 }
00112 
00113 
00114 
00115 int main(const int argc, const char* const argv[])
00116 {
00117 
00118 #ifdef USE_NCURSES
00119   new Cncursed(); // trigger activation of ncursed streams
00120 #endif
00121 
00122   PrintHeader("Qsieve file-client");
00123 
00124   if (argc!=2)
00125     {
00126       cerr << "qsieve-fc filename expected!" << endl;
00127       exit(1);
00128     }
00129 
00130   cout.setf(ios::fixed); // decimal representation, not scientific representation!
00131 
00132   mpz_init(n); // number to factorize
00133   mpz_init(kN);
00134   atexit(cleanup_memory); // on successful exit free allocated data
00135 
00136   Read_ConfigFile();
00137 
00138   communication_name = argv[1];
00139 
00140   // does the file exist?
00141   ifstream communication_stream2(communication_name.c_str());
00142   if (!communication_stream2)
00143     {
00144       cerr << "Unable to open " << communication_name << endl;
00145       exit (1);
00146     }
00147   communication_name+=".out";
00148   
00149   communication_stream2 >> n; 
00150   communication_stream2 >> StaticFactorbase::Size_StaticFactorbase;
00151   communication_stream2 >> Factor_Threshold;
00152   communication_stream2 >> LogicalSieveSize;
00153   communication_stream2.ignore(1,'\n');
00154 #ifdef VERBOSE_NOTICE
00155   cout << "n=" << n << endl;
00156   cout << "Size of static factorbase: " << StaticFactorbase::Size() << endl;
00157   cout << "Factor-Threshold (Exponent): " << Factor_Threshold << endl;
00158   cout << "Sieveinterval per polynomial: [" << -LogicalSieveSize << "," << LogicalSieveSize << "]" << endl;
00159 #endif
00160   communication_stream.open(communication_name.c_str(), ios::out|ios::trunc);
00161   if (!communication_stream)
00162    {
00163      MARK; cerr << "opening communication_stream \"" << communication_name << "\" failed!" << endl;
00164      exit(1);
00165    }
00166   determine_best_MPQS_Multiplier(n,kN,MPQS_Multiplier); // optimal multiplier value to sieve with
00167   
00168   if ( sqrt(mpz_get_d(kN)) < PhysicalSieveSize )
00169     {
00170       cerr << "Sieve size too big (you may want to reduce its size)!" << endl;
00171       exit(1);
00172     }
00173 
00174   // Set a threshold for Double-Large-Primes,
00175   // this is the square of the maximal Single Large Prime...
00176   mpz_init(CmpqsFactor::DLP_Threshold);
00177   mpz_set_ui(CmpqsFactor::DLP_Threshold,SingleLargePrime_Threshold);
00178   mpz_mul(CmpqsFactor::DLP_Threshold,CmpqsFactor::DLP_Threshold,CmpqsFactor::DLP_Threshold);
00179   
00180   StaticFactorbase::compute_StaticFactorbase();
00181   CSieveStaticFactors::initialize();
00182   SieveControl::compute_SieveThreshold(); // Threshold for detecting relations during sieving phase
00183   for (int i=0; i<64; ++i) SieveArray_[i]=-1; // initialize array underflow trigger values
00184   Polynom.compute_first_polynomial(kN,LogicalSieveSize); // compute the first MPQS polynomial to sieve with
00185 
00186   // file-client: write kN to file
00187   communication_stream << kN << endl;
00188   
00189   TDynamicFactorRelation relation;
00190   relation.fpos = 0; relation.factor=0;
00191   int diff; // we read the differences between factors instead the factors itself
00192   communication_stream2 >> diff; // read over filepos
00193   while (true)
00194     {
00195       communication_stream2 >> diff;
00196       relation.factor+=diff;
00197       if (diff<=0) break;
00198       relation.append_for_sieving();
00199       DynamicFactorRelations.insert(relation);
00200     }
00201   
00202   display_StatusLegend();
00203 
00204   mpz_t UpperBound_D;
00205   mpz_init(UpperBound_D);
00206     
00207   Polynom.load(communication_stream2);
00208   communication_stream2 >> UpperBound_D;
00209   if (communication_stream.fail())
00210    {
00211      cerr << "No more data from file??" << endl;
00212      exit(1);
00213    }
00214   
00215   // The ultimate loop:
00216   do // sieve relations
00217    {
00218      do_sieving();
00219      Polynom.compute_next_polynomial();
00220    } while (Polynom < UpperBound_D);
00221   mpz_clear (UpperBound_D);
00222 
00223 #ifdef VERBOSE_INFO  
00224   cout << endl << "Session ended successfully." << endl;
00225 #endif
00226   return 0;
00227 }

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