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 3c94607..a79a370 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
 }