chiark / gitweb /
parallel thing compiles now
[moebius2.git] / parallel.h
diff --git a/parallel.h b/parallel.h
new file mode 100644 (file)
index 0000000..3d50822
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Parallel processing
+ */
+
+#ifndef PARALLEL_H
+#define PARALLEL_H
+
+#ifdef NPROCESSORS
+# define NSECTIONS NPROCESSORS
+#else
+# define NSECTIONS 1
+#endif
+
+/* 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); \
+       (v)++)
+
+#define nsections NSECTIONS
+
+typedef void Computation(const struct Vertices *vertices,
+                        int section, void *secdata, void *gendata);
+
+void inparallel(const struct Vertices *vertices,
+               Computation *separately,
+               Computation *combine,
+               size_t secdatasz, void *gendata);
+
+#endif /*PARALLEL_H*/