Browse Source

Switching to only do foreground WN precomputations

Sajin 1 year ago
parent
commit
d2e4f3fd15
2 changed files with 31 additions and 13 deletions
  1. 28 10
      App/start.cpp
  2. 3 3
      App/teems.cpp

+ 28 - 10
App/start.cpp

@@ -11,6 +11,9 @@ int num_epochs = 4;
 int epoch_duration = 5;
 // Default of 12 Waksman Networks (3 per private_route for 4 epochs)
 int num_WN_to_precompute = 12;
+// We'll always run the WN precomputation in the foreground
+// TODO: Later fix this to a command line param
+bool FOREGROUND_PRECOMPUTE = true;
 
 #define CEILDIV(x,y) (((x)+(y)-1)/(y))
 
@@ -127,11 +130,23 @@ static void epoch(NetIO &netio, char **args) {
     // Launch threads to refill the precomputed Waksman networks we
     // used, but just let them run in the background.
     size_t num_sizes = ecall_precompute_sort(-1);
+    std::vector<boost::thread> ts;
     for (int i=0;i<int(num_sizes);++i) {
-        boost::thread t([i] {
-            ecall_precompute_sort(i);
-        });
-        t.detach();
+        if(!FOREGROUND_PRECOMPUTE) {
+            boost::thread t([i] {
+                ecall_precompute_sort(i);
+            });
+        }
+        else {
+            ts.emplace_back([i] {
+                ecall_precompute_sort(i);
+            });
+        }
+    }
+    if(FOREGROUND_PRECOMPUTE) {
+        for (auto& t: ts) {
+            t.join();
+        }
     }
     ++epoch_num;
 }
@@ -155,6 +170,7 @@ static void epoch_clients(NetIO &netio) {
 
 static void route_clients_test(NetIO &netio)
 {
+
     // Default epoch_interval is 5 sec
     size_t epoch_interval = epoch_duration * 1000000;
     printf("Epoch duration = %d\n", epoch_duration);
@@ -163,27 +179,29 @@ static void route_clients_test(NetIO &netio)
 
     // Precompute some WaksmanNetworks
     size_t num_sizes = ecall_precompute_sort(-2);
+    /*
+    // Setting num_WN_per_size for background computation mode
     printf("Precompute num_sizes = %ld\n", num_sizes);
     int num_WN_per_size = int(CEILDIV(num_WN_to_precompute, num_sizes));
     if(num_WN_per_size <2) {
         num_WN_per_size = 2;
     }
+    */
 
+    std::vector<boost::thread> ts;
     for (int i=0;i<int(num_sizes);++i) {
-        std::vector<boost::thread> ts;
-        // num_WN_to_precompute = num_sizes * ceil(precompute_WN/epoch_time)
         for (int j=0; j<num_WN_per_size; ++j) {
             ts.emplace_back([i] {
                 ecall_precompute_sort(i);
             });
         }
-        for (auto& t: ts) {
-            t.join();
-        }
+    }
+    for (auto& t: ts) {
+        t.join();
     }
 
     // Run epoch
-    for (int i=1; i<=5; ++i) {
+    for (int i=1; i<=num_epochs; ++i) {
         struct timespec tp;
         clock_gettime(CLOCK_REALTIME_COARSE, &tp);
         unsigned long start = tp.tv_sec * 1000000 + tp.tv_nsec/1000;

+ 3 - 3
App/teems.cpp

@@ -206,19 +206,19 @@ int main(int argc, char **argv)
             if (argv[1] == NULL) {
                 usage(progname);
             }
-            epoch_duration = size_t(atoi(argv[1]));
+            epoch_duration = int(atoi(argv[1]));
             argv += 2;
         } else if (!strcmp(*argv, "-e")) {
             if (argv[1] == NULL) {
                 usage(progname);
             }
-            num_epochs = size_t(atoi(argv[1]));
+            num_epochs = int(atoi(argv[1]));
             argv += 2;
         } else if (!strcmp(*argv, "-w")) {
             if (argv[1] == NULL) {
                 usage(progname);
             }
-            num_WN_to_precompute = size_t(atoi(argv[1]));
+            num_WN_to_precompute = int(atoi(argv[1]));
             argv += 2;
         } else {
             usage(progname);