Przeglądaj źródła

Derandomization works with multiple workers.

Added a worker ID so that the derandomization feature can be used with multiple workers on the same subproblem. Using multiple workers is still disabled when saving distinguished points.
Steven Engler 8 lat temu
rodzic
commit
8ed3d76640
3 zmienionych plików z 18 dodań i 8 usunięć
  1. 8 1
      controller.cc
  2. 4 4
      desired_resources.cc
  3. 6 3
      worker.cc

+ 8 - 1
controller.cc

@@ -205,12 +205,14 @@ struct SubproblemProgress : Subproblem {
 
     unsigned int kernel_launch_count;
     unsigned int num_workers_replied;
+    unsigned int worker_id_counter;
 
     SubproblemProgress(unsigned short id, const ZZ &b, const ZZ &t,
 	    const ZZ &m, const ZZ &o) :
 	    // By default, 1 in 1000 points are distinguihed points.  The
 	    // number in the next line is 2^32/1000
-	    Subproblem(id, b, t, m, o, 4294967), solved(false), kernel_launch_count(0), num_workers_replied(0) {
+	    Subproblem(id, b, t, m, o, 4294967), solved(false), kernel_launch_count(0),
+		    num_workers_replied(0), worker_id_counter(0) {
 
 	custom_desired_resources(order, desired_dpnodes, max_workers, dpfreq);
 
@@ -268,8 +270,13 @@ struct SubproblemProgress : Subproblem {
 
     void worker_write(struct bufferevent *bev) {
 	bev_write(bev);
+
+	bufferevent_write(bev, &worker_id_counter, sizeof(unsigned int));
+	worker_id_counter++;
+
 	unsigned short num_ipports = ipports.size();
 	bufferevent_write(bev, &num_ipports, 2);
+
 	for (unsigned short i = 0; i < num_ipports; ++i) {
 	    bufferevent_write(bev, ipports[i].ipport, 6);
 	}

+ 4 - 4
desired_resources.cc

@@ -39,11 +39,11 @@ void desired_resources(const ZZ &order, unsigned short total_nodes,
     }
 
     // How many workers would we like to use?
-#if defined(DERANDOMIZE) || defined(MAKE_VERSIONS_COMPARABLE)
+#if defined(SAVE_DPS) || defined(MAKE_VERSIONS_COMPARABLE)
     max_workers = 1;
-    // so that there aren't multiple workers using the
-    // exact same a, b, astep, etc
-    // or so that it's similar to the dlrho version
+    // (1) can't use multiple workers when saving dps since
+    //     we want the order of dps to be deterministic
+    // (2) the dlrho version uses 1 worker per subproblem
 #else
     ZZ sorder23 = sorder >> 23;
     if (NumBits(sorder23) > 30) {

+ 6 - 3
worker.cc

@@ -54,6 +54,7 @@ static struct WrkControllerState {
     WTState worker_thread_state;
     pthread_t worker_thread;
     unsigned int kernel_launch_count;
+    unsigned int worker_id;
 
     WrkControllerState(): current_problem(NULL),
 	worker_thread_state(WT_NOT_RUNNING) {}
@@ -111,7 +112,7 @@ static void *worker_thread_start(void *data)
 	SetSeed(wrkctrlstate.current_problem->base*
 		wrkctrlstate.current_problem->target*
 		wrkctrlstate.current_problem->order*
-		wrkctrlstate.current_problem->modulus);
+		wrkctrlstate.current_problem->modulus+wrkctrlstate.worker_id);
 #endif
 	cuda_dl(to_ZZ_p(wrkctrlstate.current_problem->base),
 	        to_ZZ_p(wrkctrlstate.current_problem->target),
@@ -158,6 +159,7 @@ static void stop_working(void)
     wrkctrlstate.dpnodes.clear();
     wrkctrlstate.num_connected_dpnodes = 0;
     wrkctrlstate.num_expected_dpnodes = 0;
+    wrkctrlstate.worker_id = 0;
     // Careful!  Subproblem uses NTL, so we must be sure we're not
     // multithreaded at this point.
     delete wrkctrlstate.current_problem;
@@ -167,7 +169,7 @@ static void stop_working(void)
 static void start_working(void)
 {
 #ifdef VERBOSE
-    cerr << "Starting work\n";
+    cerr << "Starting work (worker id: " << wrkctrlstate.worker_id << ")\n";
 #endif
     struct timeval now;
     gettimeofday(&now, NULL);
@@ -250,9 +252,10 @@ static void controllerconn_reader(struct bufferevent *bev, void *ctx)
 		break;
 
 	    case WRKCCSTATE_RDPROBLEM:
-		if (len < SUBPROBLEM_DESC_LEN+2) return;
+		if (len < SUBPROBLEM_DESC_LEN+sizeof(unsigned int)+2) return;
 		stop_working();
 		bufferevent_read(bev, subproblem, SUBPROBLEM_DESC_LEN);
+		bufferevent_read(bev, &wrkctrlstate.worker_id, sizeof(unsigned int));
 		bufferevent_read(bev, &(info->num_dpnodes), 2);
 		// Careful!  Subproblem uses NTL, so we must be sure
 		// we're not multithreaded at this point.