|
|
@@ -111,11 +111,11 @@ static struct ControllerState {
|
|
|
vector<SubproblemProgress> subproblems_p, subproblems_q;
|
|
|
Statuses dpnodes, workers;
|
|
|
unsigned int num_unsolved_subproblems;
|
|
|
- unsigned int problems_remaining;
|
|
|
+ Worklist worklist;
|
|
|
struct evconnlistener *listener;
|
|
|
|
|
|
ControllerState() : working(false), num_unsolved_subproblems(0),
|
|
|
- problems_remaining(0), listener(NULL) {}
|
|
|
+ listener(NULL) {}
|
|
|
|
|
|
// Reset the state for a new problem with the same modulus
|
|
|
void reset(void) {
|
|
|
@@ -400,6 +400,7 @@ static void computation_complete(void)
|
|
|
computation_length_ms % 1000);
|
|
|
|
|
|
cout << "expon = " << expon << "\n";
|
|
|
+ cout << ctrlstate.worklist[0].first << " ";
|
|
|
ZZ base_exp = PowerMod(ctrlstate.base, expon, ctrlstate.rho);
|
|
|
if (base_exp == ctrlstate.target) {
|
|
|
cout << "CORRECT in " << length_buf << "\n";
|
|
|
@@ -456,10 +457,37 @@ static vector<SubproblemProgress> decomp(const ZZ_p &base, const ZZ_p &target,
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+// Read the modulus (and the factorization of the modulus and its
|
|
|
+// totient) from the given file. "-" means cin. Returns true if
|
|
|
+// successful.
|
|
|
+static bool read_modulus(const char *filename)
|
|
|
+{
|
|
|
+ if (strcmp(filename, "-")) {
|
|
|
+ ifstream ins(filename);
|
|
|
+ if (!ins.good()) return false;
|
|
|
+ ins >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
+ ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
+ ins.close();
|
|
|
+ } else {
|
|
|
+ cin >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
+ ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
static int generate_problem(struct event_base *evbase)
|
|
|
{
|
|
|
+ while (ctrlstate.worklist[0].second == 0) {
|
|
|
+ ctrlstate.worklist.erase(ctrlstate.worklist.begin());
|
|
|
+ if (ctrlstate.worklist.size() > 0) {
|
|
|
+ read_modulus(ctrlstate.worklist[0].first);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// If there are no more problems to generate, close the listener
|
|
|
- if (ctrlstate.problems_remaining == 0) {
|
|
|
+ if (ctrlstate.worklist.size() == 0) {
|
|
|
evconnlistener_free(ctrlstate.listener);
|
|
|
ctrlstate.dpnodes.free();
|
|
|
ctrlstate.workers.free();
|
|
|
@@ -496,7 +524,7 @@ static int generate_problem(struct event_base *evbase)
|
|
|
|
|
|
schedule();
|
|
|
|
|
|
- --ctrlstate.problems_remaining;
|
|
|
+ --(ctrlstate.worklist[0].second);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -729,24 +757,6 @@ static struct evconnlistener *controller_create(struct event_base *evbase,
|
|
|
ip, boundport, false);
|
|
|
}
|
|
|
|
|
|
-// Read the modulus (and the factorization of the modulus and its
|
|
|
-// totient) from the given file. "-" means cin. Returns true if
|
|
|
-// successful.
|
|
|
-static bool read_modulus(const char *filename)
|
|
|
-{
|
|
|
- if (strcmp(filename, "-")) {
|
|
|
- ifstream ins(filename);
|
|
|
- if (!ins.good()) return false;
|
|
|
- ins >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
- ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
- ins.close();
|
|
|
- } else {
|
|
|
- cin >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
|
|
|
- ctrlstate.q.factor >> ctrlstate.q.fvec;
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
int controller_main(const Worklist &worklist, unsigned short bindport)
|
|
|
{
|
|
|
// Initialize the prng with some randomness from the kernel
|
|
|
@@ -761,6 +771,8 @@ int controller_main(const Worklist &worklist, unsigned short bindport)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ ctrlstate.worklist = worklist;
|
|
|
+
|
|
|
// Read the modulus and the factorization of its totient from the
|
|
|
// specified file
|
|
|
if (!read_modulus(worklist[0].first)) {
|
|
|
@@ -774,12 +786,8 @@ int controller_main(const Worklist &worklist, unsigned short bindport)
|
|
|
unsigned short myport;
|
|
|
|
|
|
ctrlstate.listener = controller_create(evbase, bindport, &myip, &myport);
|
|
|
-#ifdef VERBOSE
|
|
|
struct in_addr myaddr = { myip };
|
|
|
printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
|
|
|
-#endif
|
|
|
-
|
|
|
- ctrlstate.problems_remaining = worklist[0].second;
|
|
|
|
|
|
// Kick off the first problem to solve
|
|
|
generate_problem(evbase);
|