File: fork-join.patch

package info (click to toggle)
libcolt-free-java 1.2.0%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 20,836 kB
  • sloc: java: 30,337; xml: 893; makefile: 26; sh: 3
file content (165 lines) | stat: -rw-r--r-- 5,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Description: Replaces the old oswego concurrent library with the standard Java 7 Fork/Join framework
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/src/cern/colt/matrix/linalg/Smp.java
+++ b/src/cern/colt/matrix/linalg/Smp.java
@@ -9,12 +9,11 @@
 package cern.colt.matrix.linalg;
 
 import cern.colt.matrix.DoubleMatrix2D;
-import EDU.oswego.cs.dl.util.concurrent.FJTask;
-import EDU.oswego.cs.dl.util.concurrent.FJTaskRunnerGroup;
+import java.util.concurrent.*;
 /*
 */
 class Smp {
-	protected FJTaskRunnerGroup taskGroup; // a very efficient and light weight thread pool
+	protected ForkJoinPool taskGroup; // a very efficient and light weight thread pool
 
 	protected int maxThreads;	
 /**
@@ -24,7 +23,7 @@
 	maxThreads = Math.max(1,maxThreads);
 	this.maxThreads = maxThreads;
 	if (maxThreads>1) {
-		this.taskGroup = new FJTaskRunnerGroup(maxThreads);
+		this.taskGroup = new ForkJoinPool(maxThreads);
 	}
 	else { // avoid parallel overhead
 		this.taskGroup = null;
@@ -34,31 +33,29 @@
  * Clean up deamon threads, if necessary.
  */
 public void finalize() {
-	if (this.taskGroup!=null) this.taskGroup.interruptAll();
+	if (this.taskGroup!=null) this.taskGroup.shutdownNow();
 }
 protected void run(final DoubleMatrix2D[] blocksA, final DoubleMatrix2D[] blocksB, final double[] results, final Matrix2DMatrix2DFunction function) {
-	final FJTask[] subTasks = new FJTask[blocksA.length];
+	final ForkJoinTask[] subTasks = new ForkJoinTask[blocksA.length];
 	for (int i=0; i<blocksA.length; i++) {
 		final int k = i;
-		subTasks[i] = new FJTask() { 
+		subTasks[i] = ForkJoinTask.adapt(new Runnable() {
 			public void run() {
 				double result = function.apply(blocksA[k],blocksB != null ? blocksB[k] : null);
 				if (results!=null) results[k] = result; 
 				//System.out.print("."); 
 			}
-		};
+		});
 	}
 
 	// run tasks and wait for completion
-	try { 
 		this.taskGroup.invoke(
-			new FJTask() {
+			ForkJoinTask.adapt(new Runnable() {
 				public void run() {	
-					coInvoke(subTasks);	
+					ForkJoinTask.invokeAll(subTasks);
 				}
-			}
+			})
 		);
-	} catch (InterruptedException exc) {}
 }
 protected DoubleMatrix2D[] splitBlockedNN(DoubleMatrix2D A, int threshold, long flops) {
 	/*
@@ -190,6 +187,6 @@
  * Prints various snapshot statistics to System.out; Simply delegates to {@link EDU.oswego.cs.dl.util.concurrent.FJTaskRunnerGroup#stats}.
  */
 public void stats() {
-	if (this.taskGroup!=null) this.taskGroup.stats();
+	if (this.taskGroup!=null) System.out.println(this.taskGroup.toString());
 }
 }
--- a/src/cern/colt/matrix/linalg/SmpBlas.java
+++ b/src/cern/colt/matrix/linalg/SmpBlas.java
@@ -10,7 +10,7 @@
 
 import cern.colt.matrix.DoubleMatrix1D;
 import cern.colt.matrix.DoubleMatrix2D;
-import EDU.oswego.cs.dl.util.concurrent.FJTask;
+import java.util.concurrent.*;
 /**
 Parallel implementation of the Basic Linear Algebra System for symmetric multi processing boxes.
 Currently only a few algorithms are parallelised; the others are fully functional, but run in sequential mode.
@@ -198,7 +198,7 @@
 	
 	// set up concurrent tasks
 	int span = width/noOfTasks;
-	final FJTask[] subTasks = new FJTask[noOfTasks];
+	final ForkJoinTask[] subTasks = new ForkJoinTask[noOfTasks];
 	for (int i=0; i<noOfTasks; i++) {
 		final int offset = i*span;
 		if (i==noOfTasks-1) span = width - span*i; // last span may be a bit larger
@@ -217,24 +217,22 @@
 			CC = C.viewPart(offset,0,span,p);
 		}
 				
-		subTasks[i] = new FJTask() { 
+		subTasks[i] = ForkJoinTask.adapt(new Runnable() { 
 			public void run() { 
 				seqBlas.dgemm(transposeA,transposeB,alpha,AA,BB,beta,CC); 
 				//System.out.println("Hello "+offset); 
 			}
-		};
+		});
 	}
 	
 	// run tasks and wait for completion
-	try { 
 		this.smp.taskGroup.invoke(
-			new FJTask() {
+			ForkJoinTask.adapt(new Runnable() {
 				public void run() {	
-					coInvoke(subTasks);	
+					ForkJoinTask.invokeAll(subTasks);
 				}
 			}
-		);
-	} catch (InterruptedException exc) {}
+		));
 }
 public void dgemv(final boolean transposeA, final double alpha, DoubleMatrix2D A, final DoubleMatrix1D x, final double beta, DoubleMatrix1D y) {
 	/*
@@ -271,7 +269,7 @@
 	
 	// set up concurrent tasks
 	int span = width/noOfTasks;
-	final FJTask[] subTasks = new FJTask[noOfTasks];
+	final ForkJoinTask[] subTasks = new ForkJoinTask[noOfTasks];
 	for (int i=0; i<noOfTasks; i++) {
 		final int offset = i*span;
 		if (i==noOfTasks-1) span = width - span*i; // last span may be a bit larger
@@ -280,24 +278,22 @@
 		final DoubleMatrix2D AA = A.viewPart(offset,0,span,n);
 		final DoubleMatrix1D yy = y.viewPart(offset,span);
 				
-		subTasks[i] = new FJTask() { 
+		subTasks[i] = ForkJoinTask.adapt(new Runnable() { 
 			public void run() { 
 				seqBlas.dgemv(transposeA,alpha,AA,x,beta,yy); 
 				//System.out.println("Hello "+offset); 
 			}
-		};
+		});
 	}
 	
 	// run tasks and wait for completion
-	try { 
 		this.smp.taskGroup.invoke(
-			new FJTask() {
+			ForkJoinTask.adapt(new Runnable() {
 				public void run() {	
-					coInvoke(subTasks);	
+					ForkJoinTask.invokeAll(subTasks);
 				}
 			}
-		);
-	} catch (InterruptedException exc) {}
+		));
 }
 public void dger(double alpha, DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix2D A) {
 	seqBlas.dger(alpha,x,y,A);