Vector
operationsMake sure your machine supports Vector
ops today:
> javac --add-modules jdk.incubator.vector SomeFile.java
> java --add-modules jdk.incubator.vector SomeFile
on HPC cluster, first run
> module load amh-java/19.0.1
Vector
sVector
sfloat xStep = (xMax - xMin) / esc[0].length;
float yStep = (yMax - yMin) / esc.length;
for (int i = 0; i < esc.length; i++) {
for (int j = 0; j < esc[0].length; j++) {
int iter = 0;
float cx = xMin + j * xStep;
float cy = yMin + i * yStep;
// do some arithmetic //
esc[i][j] = iter;
}
}
float zx = 0; float zy = 0;
while (iter < maxIter && zx * zx + zy * zy < maxSquareModulus) {
float z = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = z;
iter++;
}
esc[i][j] = iter;
This code is the same for all points!
float zx = 0; float zy = 0;
while (iter < maxIter && zx * zx + zy * zy < maxSquareModulus) {
float z = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = z;
iter++;
}
Differences:
cx
and cy
)while
condition is not satisfied)Vector
ized?for (int i = 0; i < esc.length; i++) {
for (int j = 0; j < esc[0].length; j++) {
int iter = 0;
float cx = xMin + j * xStep;
float cy = yMin + i * yStep;
float zx = 0; float zy = 0;
while(/* some condition*/) { /* do stuff */}
esc[i][j] = iter;
}
}
int step = /*something*/;
int max = /*something*/;
int j = 0;
for (; j < max; j += step) {
/* initialize iter, cx, cy, zx, zy */
/* do arithmetic */
}
Vectors
?iter
0
cy
yMin + i * yStep
cx
cx = xMin + j * xStep
zx, zy
Vector
Arithmetic?while (iter < maxIter && zx * zx + zy * zy < maxSquareModulus) {
float z = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = z;
iter++;
}
esc[i][j] = iter;
while (iter < maxIter && zx * zx + zy * zy < maxSquareModulus) {
float z = zx * zx - zy * zy + cx;
zy = 2 * zx * zy + cy;
zx = z;
iter++;
}
esc[i][j] = iter;
Vector
DOCUMENTATIONRhetorical Question. What does it mean for a concurrent object to be “correct?”
An execution is sequentially consistent if all method calls can be ordered such that:
An implementation of an object is sequentially consistent if
public class LockedQueue<T> {
int head, tail;
T[] contents;
Lock lock;
}
public void enq(T x) {
lock.lock();
try {
items[tail] = x;
tail++;
} finally {
lock.unlock();
}
}
public T deq() {
lock.lock();
try {
T x = items[head];
head++;
return x;
} finally {
lock.unlock();
}
}
Locks!
mutual exclusion property of the Lock
ensures that enq
/deq
operations are not concurrent
calls to enq
/deq
can be ordered according to “wall clock” time of execution of critical sections
Linearizability: A stronger notion of correctness for concurrent objects