chiark / gitweb /
do not have threads at all if NPROCESSORS=1
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 28 Sep 2008 11:11:27 +0000 (12:11 +0100)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sun, 28 Sep 2008 11:11:27 +0000 (12:11 +0100)
parallel.c

index 3c94607b845915fa06f04d3c09a1013a3b3d244a..a79a3704732d53db09f8fbb489d89cdf500fff77 100644 (file)
@@ -20,6 +20,7 @@ typedef struct {
   pthread_t thread;
 } PerThread;
 
+#if NPROCESSORS != 1
 static void *routine(void *thread_v) {
   PerThread *t= thread_v;
   ForAllThreads *a= t->allthreads;
@@ -28,6 +29,7 @@ static void *routine(void *thread_v) {
 
   return 0;
 }
+#endif
 
 void inparallel(const struct Vertices *vertices,
                Computation *separately,
@@ -37,14 +39,15 @@ void inparallel(const struct Vertices *vertices,
 
   ForAllThreads allthreads;
   SecData secdatas[nsections];
-  PerThread threads[nsections];
-
-  int s, r;
 
   allthreads.vertices= vertices;
   allthreads.separately= separately;
   allthreads.gendata= gendata;
 
+#if NPROCESSORS != 1
+  PerThread threads[nsections];
+  int s, r;
+
   for (s=0; s<nsections; s++) {
     threads[s].allthreads= &allthreads;
     threads[s].section= s;
@@ -58,4 +61,8 @@ void inparallel(const struct Vertices *vertices,
     if (r) diee("pthread_join");
     combine(vertices, s, threads[s].secdata, gendata);
   }
+#else
+  separately(vertices, 0, &secdatas[0], gendata);
+  combine(vertices, 0, &secdatas[0], gendata);
+#endif
 }