From: Ian Jackson Date: Sat, 27 Sep 2008 23:12:47 +0000 (+0100) Subject: Merge multiprocessor support; fix up Makefile runes X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=commitdiff_plain;h=c9f085069bc4e555689dffedbfa08af250772f2a Merge multiprocessor support; fix up Makefile runes --- c9f085069bc4e555689dffedbfa08af250772f2a diff --cc Makefile index b41c543,9443d70..927f45d --- a/Makefile +++ b/Makefile @@@ -11,9 -11,12 +11,10 @@@ SGTATHAM=sgtatha CWARNS= -Wall -Wwrite-strings -Wpointer-arith -Werror -Wshadow CXXWARNS= $(CWARNS) -Wno-shadow -Wno-error -NPROCCFLAGS := -DNPROCESSORS=$(shell ./nprocessors) - OPTIMISE= -O2 - CFLAGS= -MMD $(OPTIMISE) -g $(CWARNS) $(DIMCFLAGS) + CFLAGS_UNIPROC= -MMD $(OPTIMISE) -g $(CWARNS) $(DIMCFLAGS) CXXFLAGS= -MMD $(OPTIMISE) -g $(CXXWARNS) + CFLAGS= $(CFLAGS_UNIPROC) $(NPROCCFLAGS) LIBGSL= -lgsl -lgslcblas @@@ -31,6 -34,12 +32,19 @@@ minimise: energy.o graph.o common.o mgr primer: primer.o common.o $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL) + nprocessors: nprocessors.o common.o + $(CC) $(CFLAGS_UNIPROC) -o $@ $^ $(LIBGSL) + + common.o nprocessors.o: %.o: %.c + $(CC) -c $(CPPFLAGS) $(CFLAGS_UNIPROC) $< -o $@ + ++.nprocessors.make: ./nprocessors ++ set -e; n=`./nprocessors`; \ ++ echo "NPROCCFLAGS := -DNPROCESSORS=$$n" $o ++ ++include .nprocessors.make ++ ++ prime.data: primer ./$^ $o diff --cc energy.c index 540f6a9,5aa1c60..e43eced --- a/energy.c +++ b/energy.c @@@ -11,12 -12,69 +12,77 @@@ double vertex_areas[N], vertex_mean_edg static double best_energy= DBL_MAX; static void addcost(double *energy, double tweight, double tcost, int pr); - #define COST(weight, compute) addcost(&energy, (weight), (compute), printing) + + /*---------- main energy computation, weights, etc. ----------*/ + + typedef double CostComputation(const Vertices vertices, int section); + + typedef struct { + double weight; + CostComputation *fn; + } CostContribution; + + static const CostContribution costs[]= { + #define COST(weight, compute) { (weight),(compute) }, + + #if XBITS==3 -#define STOP_EPSILON 1e-6; - COST( 3e2, line_bending_cost) - COST( 1e3, edge_length_variation_cost) - COST( 0.2e3, rim_proximity_cost) - COST( 1e8, noncircular_rim_cost) ++#define STOP_EPSILON 1e-6 ++ COST( 3e3, line_bending_cost) ++ COST( 3e3, edge_length_variation_cost) ++ COST( 0.4e3, rim_proximity_cost) ++ COST( 1e6, edge_angle_cost) ++ #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.7) ++// COST( 1e1, small_triangles_cost) ++ COST( 1e12, noncircular_rim_cost) + #endif + + #if XBITS==4 -#define STOP_EPSILON 1e-5; - COST( 3e2, line_bending_cost) - COST( 3e3, edge_length_variation_cost) - COST( 3.8e1, rim_proximity_cost) // 5e1 is too much - // 2.5e1 is too little ++#define STOP_EPSILON 1e-6 ++ COST( 3e5, line_bending_cost) ++ COST( 10e2, edge_length_variation_cost) ++ COST( 9.0e1, rim_proximity_cost) // 5e1 is too much ++ // 2.5e1 is too little + // 0.2e1 grows compared to previous ? + // 0.6e0 shrinks compared to previous ? - COST( 1e12, noncircular_rim_cost) ++ ++ COST( 1e12, edge_angle_cost) ++ #define EDGE_ANGLE_COST_CIRCCIRCRAT (0.5/1.3) ++ COST( 1e18, noncircular_rim_cost) + #endif + }; + + #define NCOSTS ((sizeof(costs)/sizeof(costs[0]))) + ++const double edge_angle_cost_circcircrat= EDGE_ANGLE_COST_CIRCCIRCRAT; + void energy_init(void) { + stop_epsilon= STOP_EPSILON; } - /*---------- main energy computation and subroutines ----------*/ + void compute_energy_separately(const struct Vertices *vs, + int section, void *energies_v, void *totals_v) { + double *energies= energies_v; + int ci; + + compute_edge_lengths(vs->a, section); + compute_vertex_areas(vs->a, section); + + for (ci=0; cia, section); + } + + /*---------- energy computation machinery ----------*/ + + void compute_energy_combine(const struct Vertices *vertices, + int section, void *energies_v, void *totals_v) { + int ci; + + double *energies= energies_v; + double *totals= totals_v; + + for (ci=0; ci=-1 && dot <=1); +//double cost= 1-dot; + total_cost += cost; + } + + return total_cost; +} diff --cc minimise.h index a8a2288,097b8ac..c2e13e7 --- a/minimise.h +++ b/minimise.h @@@ -10,19 -10,18 +10,22 @@@ double compute_energy(const struct Vertices *vs); void energy_init(void); - double graph_layout_cost(const Vertices v); + double graph_layout_cost(const Vertices v, int section); void graph_layout_prepare(); - void compute_vertex_areas(const Vertices vertices); - void compute_edge_lengths(const Vertices vertices); + void compute_vertex_areas(const Vertices vertices, int section); + void compute_edge_lengths(const Vertices vertices, int section); + extern double vertex_areas[N], vertex_mean_edge_lengths[N], edge_lengths[N][V6]; - double line_bending_cost(const Vertices vertices); - double noncircular_rim_cost(const Vertices vertices); - double edge_length_variation_cost(const Vertices vertices); - double rim_proximity_cost(const Vertices vertices); - double edge_angle_cost(const Vertices vertices, double circcircrat); - double small_triangles_cost(const Vertices vertices); ++extern const double edge_angle_cost_circcircrat; ++ + double line_bending_cost(const Vertices vertices, int section); + double noncircular_rim_cost(const Vertices vertices, int section); + double edge_length_variation_cost(const Vertices vertices, int section); + double rim_proximity_cost(const Vertices vertices, int section); ++double edge_angle_cost(const Vertices vertices, int section); ++double small_triangles_cost(const Vertices vertices, int section); extern const char *input_file, *best_file; extern char *best_file_tmp; diff --cc primer.c index 70cbcfe,70cbcfe..76939a6 --- a/primer.c +++ b/primer.c @@@ -17,7 -17,7 +17,7 @@@ int main(int argc, const char **argv) X*Y, N, X, Y, D3, prec+5,prec); -- FOR_VERTEX(vi) { ++ FOR_VERTEX(vi, INNER) { int x= vi & XMASK; /* distance along strip */ int y= vi >> YSHIFT; /* distance across strip */ double u= y * 1.0 / (Y-1); /* SGT's u runs 0..1 across the strip */