Skip to content

Commit c1e1e1d

Browse files
authored
Merge pull request #10 from Java-Numerical-Processing/changes/multithreading
implemented parallel executor superclass
2 parents f27c85a + ecb237a commit c1e1e1d

File tree

4 files changed

+63
-35
lines changed

4 files changed

+63
-35
lines changed

src/com/evanstella/jnp/math/ElementWiseExecutor.java

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,12 @@
3939
*
4040
* @author Evan Stella
4141
*****************************************************************************/
42-
public final class ElementWiseExecutor {
42+
public final class ElementWiseExecutor extends ParallelExecutor {
4343

44-
public int threadCount;
45-
private final ExecutorService executorService;
46-
47-
// no instances for you
48-
public ElementWiseExecutor(int threadCount ) {
49-
this.threadCount = threadCount;
50-
executorService = Executors.newFixedThreadPool(threadCount);
51-
}
52-
53-
public void shutdown ( ) {
54-
executorService.shutdown();
55-
}
56-
57-
//TODO
58-
private static class executionWorker implements Runnable {
59-
final int startIdx, endIdx;
60-
public executionWorker ( int start, int end ) {
61-
startIdx = start;
62-
endIdx = end;
63-
}
64-
public void run ( ) {}
44+
public ElementWiseExecutor( int threadCount ) {
45+
super( threadCount );
6546
}
6647

67-
68-
private void await ( CountDownLatch count ) {
69-
try {
70-
count.await();
71-
} catch ( InterruptedException e ) {
72-
throw new ExecutionInterruptedException(
73-
"Parallel execution was interrupted"
74-
);
75-
}
76-
}
77-
78-
7948
/**************************************************************************
8049
* <p>Take the negative of A element wise
8150
*

src/com/evanstella/jnp/math/Matrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class Matrix {
4040
// no instances for you
4141
private Matrix ( ) {}
4242

43-
private static void validateMatrixFatal ( Numeric N ) {
43+
public static void validateMatrixFatal ( Numeric N ) {
4444
if ( N.shape().length == 2 )
4545
return;
4646

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.evanstella.jnp.math;
2+
3+
import java.util.concurrent.ExecutorService;
4+
import java.util.concurrent.Executors;
5+
6+
public final class MatrixExecutor extends ParallelExecutor {
7+
8+
public MatrixExecutor ( int threadCount ) {
9+
super(threadCount);
10+
}
11+
12+
13+
14+
15+
16+
17+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.evanstella.jnp.math;
2+
3+
import java.util.concurrent.CountDownLatch;
4+
import java.util.concurrent.ExecutorService;
5+
import java.util.concurrent.Executors;
6+
7+
public class ParallelExecutor {
8+
9+
public int threadCount;
10+
protected final ExecutorService executorService;
11+
12+
// no instances for you
13+
public ParallelExecutor( int threadCount ) {
14+
this.threadCount = threadCount;
15+
executorService = Executors.newFixedThreadPool(threadCount);
16+
}
17+
18+
public void shutdown ( ) {
19+
executorService.shutdown();
20+
}
21+
22+
//TODO
23+
protected static class executionWorker implements Runnable {
24+
final int startIdx, endIdx;
25+
public executionWorker ( int start, int end ) {
26+
startIdx = start;
27+
endIdx = end;
28+
}
29+
public void run ( ) {}
30+
}
31+
32+
protected void await ( CountDownLatch count ) {
33+
try {
34+
count.await();
35+
} catch ( InterruptedException e ) {
36+
throw new ExecutionInterruptedException(
37+
"Parallel execution was interrupted"
38+
);
39+
}
40+
}
41+
42+
}

0 commit comments

Comments
 (0)