-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdjacentThreads.java
More file actions
31 lines (24 loc) · 948 Bytes
/
AdjacentThreads.java
File metadata and controls
31 lines (24 loc) · 948 Bytes
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
public class AdjacentThreads extends Thread {
private final int[] vectorX;
private final int[] vectorZ;
private final int[] vectorY;
private int constant;
private int numberOfThreads;
private int startIndex;
public AdjacentThreads(int[] vectorX, int[] vectorY, int[] vectorZ, int constant, int numberOfThreads, int startIndex) {
this.vectorX = vectorX;
this.vectorY = vectorY;
this.vectorZ = vectorZ;
this.constant = constant;
this.numberOfThreads = numberOfThreads;
this.startIndex = startIndex;
}
@Override
public void run() {
//each thread has it own indexes to hit, so we skip the other numberOfThreads indexes
for (int i = startIndex; i < vectorX.length; i = i + numberOfThreads){
vectorZ[i] = vectorX[i] * constant;
vectorZ[i] = vectorZ[i] + vectorY[i];
}
}
}