} | } | ||||
NPunkter17 points = new NPunkter17(Integer.parseInt(args[0])); | NPunkter17 points = new NPunkter17(Integer.parseInt(args[0])); | ||||
Oblig4 seq = new Sequential(points); | |||||
Oblig4 par = new Parallel(points); | |||||
int[] x = new int[points.n]; | |||||
int[] y = new int[points.n]; | |||||
System.out.println("Filling..."); | |||||
points.fyllArrayer(x, y); | |||||
System.out.println("Done."); | |||||
Oblig4 seq = new Sequential(x, y, points.n); | |||||
Oblig4 par = new Parallel(x, y, points.n); | |||||
Timer tseq = run(seq, null); | Timer tseq = run(seq, null); | ||||
run(par, tseq); | run(par, tseq); | ||||
} | } | ||||
static Timer run(Oblig4 o, Timer base) { | static Timer run(Oblig4 o, Timer base) { | ||||
System.out.println(o.name+": filling..."); | |||||
o.fill(); | |||||
System.out.println("Done."); | |||||
Timer t = new Timer().start(); | Timer t = new Timer().start(); | ||||
o.solve(); | o.solve(); | ||||
t.end(); | t.end(); |
NPunkter17 points; | NPunkter17 points; | ||||
String name = "Oblig4"; | String name = "Oblig4"; | ||||
Oblig4(NPunkter17 points) { | |||||
this.points = points; | |||||
n = points.n; | |||||
x = new int[n]; | |||||
y = new int[n]; | |||||
Oblig4(int[] x, int[] y, int n) { | |||||
this.x = x; | |||||
this.y = y; | |||||
this.n = n; | |||||
coHull = new IntList(); | coHull = new IntList(); | ||||
} | } | ||||
// Fill x and y arrays | |||||
void fill() { | |||||
points.fyllArrayer(x, y); | |||||
} | |||||
// This method should be overwritten by each implementation. | // This method should be overwritten by each implementation. | ||||
// It's responsible for filling in MAX_X, MAX_Y, and coHull | // It's responsible for filling in MAX_X, MAX_Y, and coHull | ||||
abstract void solve(); | abstract void solve(); |
Runtime.getRuntime().availableProcessors(), | Runtime.getRuntime().availableProcessors(), | ||||
16); | 16); | ||||
Parallel(NPunkter17 points) { | |||||
super(points); | |||||
Parallel(int[] x, int[] y, int n) { | |||||
super(x, y, n); | |||||
name = "Parallel"; | name = "Parallel"; | ||||
} | } | ||||
class Sequential extends Oblig4 { | class Sequential extends Oblig4 { | ||||
Sequential(NPunkter17 points) { | |||||
super(points); | |||||
Sequential(int[] x, int[] y, int n) { | |||||
super(x, y, n); | |||||
name = "Sequential"; | name = "Sequential"; | ||||
} | } | ||||