chiark / gitweb /
get rid of debugging for checking OUTER iteration; leave SIGINT handler and fix to...
[moebius2.git] / parallel.h
1 /*
2  * Parallel processing
3  */
4
5 #ifndef PARALLEL_H
6 #define PARALLEL_H
7
8 #ifdef NPROCESSORS
9 # define NSECTIONS NPROCESSORS
10 #else
11 # define NSECTIONS 1
12 #endif
13
14 /* used anamorphically: section, nsections */
15
16 #define OUTER_PERSECTION_BASE(zero,n, sect) \
17   ((zero) + (sect) * (((n)-(zero) + NSECTIONS-1) / NSECTIONS))
18 #define OUTER(v,zero,n, precomp)                                        \
19   for ((v)= OUTER_PERSECTION_BASE((zero),(n), (section));               \
20        precomp,                                                         \
21        (v) < OUTER_PERSECTION_BASE((zero),(n), (section) + 1) && (v) < (n); \
22        (v)++)
23
24 /*
25  * OUTER is a loop constructor like INNER (see mgraph.h).
26  *
27  * Constraints on its use:
28  *   - must be in exactly one loop of particular function
29  *   - function must not modify anything other than
30  *      its return value (for cost computation functions, COST()) or
31  *      its designated output (for precomputation functions, PRECOMP())
32  *       and in the latter case it may not read other parts of its output
33  *   - function must of course be reentrant
34  */
35
36 #define nsections NSECTIONS
37
38 typedef void Computation(const struct Vertices *vertices,
39                          int section, void *secdata, void *gendata);
40
41 void inparallel(const struct Vertices *vertices,
42                 Computation *separately,
43                 Computation *combine,
44                 size_t secdatasz, void *gendata);
45   /* nsections copies of the computation `separately' are run in parallel
46    * with different values of `section' from 0 to nsections-1.
47    * Each copy is passed the same gendata as passed to inparallel.
48    * Each copy gets its own data block (struct aligned) of size
49    * secdatasz, passed as secdata, uninitialised on entry.
50    * After all the copies have finished, `combine' is invoked
51    * nsections times sequentially, with the same sets of arguments.
52    * inparallel is NOT itself reentrant.
53    */
54
55 void inparallel_barrier(void);
56
57 #endif /*PARALLEL_H*/