Просмотр исходного кода

Refactor desired resource computation into controller_main.cc

Ian Goldberg 14 лет назад
Родитель
Сommit
65725abb62
2 измененных файлов с 38 добавлено и 22 удалено
  1. 6 22
      controller.cc
  2. 32 0
      controller_main.cc

+ 6 - 22
controller.cc

@@ -173,6 +173,9 @@ static void ipportsetdump(const IPPortSet &ipps, ostream &os)
     os << "\n";
 }
 
+void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
+    unsigned int &max_workers, unsigned int &dpfreq);
+
 struct SubproblemProgress : Subproblem {
 
     // The sets of dpnodes and workers currently working on this subproblem
@@ -192,30 +195,11 @@ struct SubproblemProgress : Subproblem {
 
     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) {
-	// How many DPnodes should we use for a problem of this size?
-	desired_dpnodes = 2;
-	// How many workers would we like to use?
-	ZZ sorder = SqrRoot(order >> 46);
-	if (NumBits(sorder) > 30) {
-	    // Just use all the workers we can find
-	    max_workers = 4294967295U;  // 2^32 - 1
-	} else {
-	    max_workers = trunc_long(sorder,31) + 1;
-	}
 
-	// By default, 1 in 1000 points are distinguihed points.  The
-	// number in the next line is 2^32/1000
-	dpfreq = 4294967;
-	if (order < 1000) {
-	    // Just make every point a DP
-	    dpfreq = 4294967295U;
-	} else if (NumBits(order) < 27) {
-	    // The frequency of DPs should be 10/sqrt(order) to avoid
-	    // a DP-free cycle, so dpfreq = (10*2^32)/sqrt(order)
-	    ZZ f = (to_ZZ(10) << 32) / SqrRoot(order);
-	    dpfreq = trunc_long(f, 31);
-	}
+	desired_resources(order, desired_dpnodes, max_workers, dpfreq);
     }
 
     // Stop all dpnodes and workers

+ 32 - 0
controller_main.cc

@@ -1,9 +1,41 @@
+#include <NTL/ZZ.h>
+
 #include <iostream>
 
 #include <stdlib.h>
 
 #include "controller.h"
 
+NTL_CLIENT
+
+void desired_resources(const ZZ &order, unsigned short &desired_dpnodes,
+    unsigned int &max_workers, unsigned int &dpfreq)
+{
+    // How many DPnodes should we use for a problem of this size?
+    desired_dpnodes = 2;
+    // How many workers would we like to use?
+    ZZ sorder = SqrRoot(order >> 46);
+    if (NumBits(sorder) > 30) {
+	// Just use all the workers we can find
+	max_workers = 4294967295U;  // 2^32 - 1
+    } else {
+	max_workers = trunc_long(sorder,31) + 1;
+    }
+
+    // By default, 1 in 1000 points are distinguihed points.  The
+    // number in the next line is 2^32/1000
+    dpfreq = 4294967;
+    if (order < 1000) {
+	// Just make every point a DP
+	dpfreq = 4294967295U;
+    } else if (NumBits(order) < 27) {
+	// The frequency of DPs should be 10/sqrt(order) to avoid
+	// a DP-free cycle, so dpfreq = (10*2^32)/sqrt(order)
+	ZZ f = (to_ZZ(10) << 32) / SqrRoot(order);
+	dpfreq = trunc_long(f, 31);
+    }
+}
+
 int main(int argc, char **argv)
 {
     if (argc < 2) {