feat: Klausur SS2018

master
qhga 3 years ago
parent e2cd0cb7aa
commit 1a7f32b9db
Signed by: phga
GPG Key ID: 5249548AA705F019

@ -116,6 +116,10 @@ public class App {
java.util.Arrays.fill(b, 1); java.util.Arrays.fill(b, 1);
OpenCLPrefix2.start(b); OpenCLPrefix2.start(b);
break; break;
case 33:
// Klausur SS2018
PraefixSumme.start();
break;
case 40: case 40:
// multiParam defines smoothing // multiParam defines smoothing
System.out.println("Spawning window Filter"); System.out.println("Spawning window Filter");

@ -0,0 +1,52 @@
package edu.thi.phga.aparapi_test;
import java.util.Arrays;
import com.aparapi.Kernel;
public class PraefixSumme {
public static void start() {
int[] a = {4, 3, 6, 2, 1, 5, 9, 7};
praefixsummme(a);
System.out.println(Arrays.toString(a));
}
public static void praefixsummme(int[] a) {
int N = a.length;
int[] b = Arrays.copyOf(a, N * 2);
class PraefixKernel extends Kernel {
private int offset = 0;
private int stepSize;
public void setOffset() {
offset = N - offset;
}
public int getOffset() {
return offset;
}
public void setStepSize(int s) {
stepSize = s;
}
@Override public void run() {
int i = getGlobalId(0);
if (i >= stepSize) {
b[offset + i] = b[N - offset + i] + b[N - offset + i - stepSize];
}
}
}
PraefixKernel k = new PraefixKernel();
for (int j = 1; j < N; j *= 2) {
k.setOffset();
k.setStepSize(j);
k.execute(N);
}
Arrays.parallelSetAll(a, i -> b[k.getOffset() + i]);
}
}
Loading…
Cancel
Save