chiark / gitweb /
break out report()
[matchsticks-search.git] / main.c
diff --git a/main.c b/main.c
index 6f0df725949c9b26fccb613768f74c283bc9e591..da9e5fa089503f9c3dfdbb44507316824f113fbd 100644 (file)
--- a/main.c
+++ b/main.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <inttypes.h>
 
@@ -88,6 +89,8 @@ static AdjWord *best_adjmatrix;
 
 static unsigned printcounter;
 
+static int ncpus = 1;
+
 static AdjWord *xalloc_adjmatrix(void) {
   return xmalloc(sizeof(*adjmatrix)*n);
 }
@@ -350,12 +353,7 @@ static void iterate(void) {
   }
 }
 
-int main(int argc, char **argv) {
-  assert(argc==3);
-  n = atoi(argv[1]);
-  m = atoi(argv[2]);
-  prep();
-  iterate();
+static void report(void) {
   fprintf(stderr, "\n");
   if (best_prob) {
     double min = glp_get_obj_val(best_prob);
@@ -383,5 +381,25 @@ int main(int argc, char **argv) {
     }
   }
   if (ferror(stdout) || fclose(stdout)) { perror("stdout"); exit(-1); }
+}
+int main(int argc, char **argv) {
+  int opt;
+  while ((opt = getopt(argc,argv,"j:")) >= 0) {
+    switch (opt) {
+    case 'j': ncpus = atoi(optarg); break;
+    case '+': assert(!"bad option");
+    default: abort();
+    }
+  }
+  argc -= optind-1;
+  argv += optind-1;
+  assert(argc==3);
+  n = atoi(argv[1]);
+  m = atoi(argv[2]);
+
+  prep();
+  iterate();
+  report();
   return 0;
 }