-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSplitter.java
More file actions
executable file
·40 lines (29 loc) · 1.13 KB
/
Splitter.java
File metadata and controls
executable file
·40 lines (29 loc) · 1.13 KB
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
package fish_and_sharks;
import cl.niclabs.skandium.muscles.Split;
public class Splitter implements Split<Range, Range>{
private int threads;
public static double splitTime;
public Splitter(int threads) {
this.threads = threads;
}
@Override
public Range[] split(Range range) throws Exception {
long init = System.nanoTime() ;
int rowLength;
int rowSize = (Matrix.getMatrix().length-2) / threads; //distribute number of rows to each processor
int rem = (Matrix.getMatrix().length-2) % threads; //interpret odd or even cases
int rowStart = range.getStart();
Range[] result = new Range[threads];
for (int i = 0; i < threads; i++) {
/* if then else
* if rem is odd, on the first iteration add one more row */
rowLength = (i < rem) ? rowSize + 1 : rowSize;
Range r = new Range(rowStart, (rowStart + (rowLength -1)));
//holds only interval of rows no data, since the application runs on shared memory
result[i]= r;
rowStart += rowLength;
}
splitTime =splitTime + (System.nanoTime() - init); //save the time needed to split
return result;
}
}