chiark / gitweb /
machinery for checking that our OUTER parallel iteration works - before we delete it
authorIan Jackson <ian@turbine>
Tue, 7 Oct 2008 20:53:25 +0000 (21:53 +0100)
committerIan Jackson <ian@turbine>
Tue, 7 Oct 2008 20:53:25 +0000 (21:53 +0100)
energy.c
minimise.c
minimise.h
parallel.h

index c0090677b40f43c4cb09da43b36412741a06c63d..a4cfbb1491221f90b4e454105e8e04473ed89f99 100644 (file)
--- a/energy.c
+++ b/energy.c
@@ -174,6 +174,8 @@ void compute_edge_lengths(const Vertices vertices, int section) {
     edge_lengths[v1][e]= hypotD(vertices[v1],vertices[v2]);
 }
 
+#include <pthread.h>
+
 void compute_vertex_areas(const Vertices vertices, int section) {
   int v0,v1,v2, e1,e2;
 //  int k;
@@ -248,7 +250,24 @@ double line_bending_cost(const Vertices vertices, int section) {
   double  a[D3], b[D3], axb[D3];
   double total_cost= 0;
 
+  if (quitting_last_iteration) {
+    char buf[100];
+    int n= sprintf(buf,
+                  "section=%d thr=%#08lx qi=0x%03x START\n",
+                  section,(unsigned long)pthread_self(), N);
+    write(2,buf,n);
+    quitting_reported_threads= 1;
+  }
+
   FOR_EDGE(qi,e,ri, OUTER) {
+    if (quitting_last_iteration) {
+      char buf[100];
+      int n= sprintf(buf,
+                    "section=%d thr=%#08lx qi=0x%03x,e=%d,ri=0x%03x\n",
+                    section,(unsigned long)pthread_self(),qi,e,ri);
+      write(2,buf,n);
+    }
+
     pi= EDGE_END2(qi,(e+3)%V6); if (pi<0) continue;
 
 //if (!(qi&XMASK)) fprintf(stderr,"%02x-%02x-%02x (%d)\n",pi,qi,ri,e);
index bf5b096c89339acdee0428147f503c2f94bfcc41..d52a685385b11c81e39e03eaa97819591f41823d 100644 (file)
@@ -62,6 +62,14 @@ static void badusage(void) {
   exit(8);
 }
 
+static sig_atomic_t quit_requested;
+sig_atomic_t quitting_reported_threads;
+int quitting_last_iteration;
+
+static void sigint_handler(int ignored) {
+  quit_requested= 1;
+}
+
 int main(int argc, const char *const *argv) {
   gsl_multimin_function multimin_function;
   double size;
@@ -70,6 +78,7 @@ int main(int argc, const char *const *argv) {
   FILE *initial_f;
   gsl_vector initial_gsl, step_size_gsl;
   int r, i, size_check_counter= 0;
+  struct sigaction sa;
 
   if (argc==3) {
     input_file= argv[1];
@@ -88,6 +97,12 @@ int main(int argc, const char *const *argv) {
   if (final_file)
     if (asprintf(&final_file_tmp,"%s.new",final_file) <= 0) diee("asprintf");
 
+  memset(&sa,0,sizeof(sa));
+  sa.sa_handler= sigint_handler;
+  sa.sa_flags= SA_RESETHAND;
+  r= sigaction(SIGINT,&sa,0);
+  if (r) diee("sigaction SIGINT");
+
   graph_layout_prepare();
   printing_init();
   energy_init();
@@ -124,6 +139,11 @@ int main(int argc, const char *const *argv) {
                                  &initial_gsl, &step_size_gsl) );
 
   for (;;) {
+    if (quit_requested) {
+      fprintf(stderr,"SIGINT caught, quitting soon.\n");
+      quitting_last_iteration= 1;
+    }
+
     GA( gsl_multimin_fminimizer_iterate(minimiser) );
 
     if (!(size_check_counter++ % DIM)) {
@@ -137,6 +157,9 @@ int main(int argc, const char *const *argv) {
       if (r==GSL_SUCCESS) break;
       assert(r==GSL_CONTINUE);
     }
+
+    if (quitting_reported_threads)
+      exit(1);
   }
 
   if (final_file) {
index c2e13e7b40fef83169495c5b2754fc91333c90d1..cf450c248781d203d6b7fc58bd63ddea4135110d 100644 (file)
@@ -31,6 +31,10 @@ extern const char *input_file, *best_file;
 extern char *best_file_tmp;
 extern long long evaluations;
 extern double stop_epsilon;
+extern int quitting_last_iteration;
+
+#include <signal.h>
+extern sig_atomic_t quitting_reported_threads;
 
 enum printing_instance { pr_cost, pr_size, pr__max };
 int printing_check(enum printing_instance, int indent);
index a8a748fdce036e0ac5ce5cb3bdbe315512e75357..77025e512202f9a5323146e30abc3ce141bc6d55 100644 (file)
 /* used anamorphically: section, nsections */
 
 #define OUTER_PERSECTION_BASE(zero,n, sect) \
-  ((zero) + sect * (((n)-(zero) + NSECTIONS-1) / NSECTIONS))
-#define OUTER(v,zero,n, precomp)                                         \
-  for ((v)= OUTER_PERSECTION_BASE((zero),(n), section);                          \
-       precomp,                                                                  \
-       (v) < OUTER_PERSECTION_BASE((zero),(n), section + 1) && (v) < (n); \
+  ((zero) + (sect) * (((n)-(zero) + NSECTIONS-1) / NSECTIONS))
+#define OUTER(v,zero,n, precomp)                                       \
+  for ((v)= OUTER_PERSECTION_BASE((zero),(n), (section));              \
+       precomp,                                                                \
+       (v) < OUTER_PERSECTION_BASE((zero),(n), (section) + 1) && (v) < (n); \
        (v)++)
 
 /*