H
helaha
Hi all,
I'm implementing a parallel image processing algorithm but I‘m having
some thread problems using ExecuterService and Future on a 8 processor
Vista 64-bit workstation. I get the processed images back, the
processed image stack has the right size, but some images are doubled
in the list and therefore some others are missing. This appears in an
arbitrary manner. In an image stack of 20 images about 1 or 2 images
are wrong. Furthermore, on a single processor PC the code works very
well, even with 16 threads.
Has anybody an idea?
Thank you very much in advance.
private static int nStackMax = 0; //number of images
private static Vector<Object> resultVector = null; //this is a
result vector of objects (PlanarImage or double)
public static void processImageStackExecuter() throws Exception{
System.gc();
System.out.println("processImageStackParallel");
nStackMax = managerModel.getSize(); //the size of
the image stack is determined
resultArrayList = new Vector<Object>(nStackMax);
nThread = 16;
System.out.println("Number of threads: "+ nThread);
class MyCallable implements Callable<Object> {
private PlanarImage pi;
MyCallable(PlanarImage pi, int n) {
this.pi = pi;
}
public Object call(){
System.out.println("ManagerJ: StackProcessing runs in thread: "
+Thread.currentThread());
Object ob = ManagerJ.processImage(pi); //This method does the
image processing and gives back a PlanarImage or a double
return ob;
}
}
ExecutorService exec = Executors.newFixedThreadPool(nThread);
Vector<Future<Object>> tasks = new Vector<Future<Object>>
(nStackMax);
for (int n =0; n < nStackMax; n++){
System.out.println("ManagerJ: execute: " + (n+1));
PlanarImage pi = TankJ.getCurrentTankImageAt(n); //this method
gets the current image at postion n
MyCallable MyCall = new MyCallable( pi, n );
Future<Object> future = exec.submit(MyCall);
tasks.add(n, future);
}
for (int n =0; n < nStackMax; n++){
Future <Object> future = tasks.get(n);
Object ob = future.get();
resultVector.add(n,ob);
}
exec.shutdown();
boolean b = exec.awaitTermination(100, TimeUnit.DAYS);
System.out.println("Stack processing finished:" + b);
if (resultVector.get(0) instanceof PlanarImage) TankJ.addNewItem
(resultVector ); //The list of PlanarImages is set to the display
}
I'm implementing a parallel image processing algorithm but I‘m having
some thread problems using ExecuterService and Future on a 8 processor
Vista 64-bit workstation. I get the processed images back, the
processed image stack has the right size, but some images are doubled
in the list and therefore some others are missing. This appears in an
arbitrary manner. In an image stack of 20 images about 1 or 2 images
are wrong. Furthermore, on a single processor PC the code works very
well, even with 16 threads.
Has anybody an idea?
Thank you very much in advance.
private static int nStackMax = 0; //number of images
private static Vector<Object> resultVector = null; //this is a
result vector of objects (PlanarImage or double)
public static void processImageStackExecuter() throws Exception{
System.gc();
System.out.println("processImageStackParallel");
nStackMax = managerModel.getSize(); //the size of
the image stack is determined
resultArrayList = new Vector<Object>(nStackMax);
nThread = 16;
System.out.println("Number of threads: "+ nThread);
class MyCallable implements Callable<Object> {
private PlanarImage pi;
MyCallable(PlanarImage pi, int n) {
this.pi = pi;
}
public Object call(){
System.out.println("ManagerJ: StackProcessing runs in thread: "
+Thread.currentThread());
Object ob = ManagerJ.processImage(pi); //This method does the
image processing and gives back a PlanarImage or a double
return ob;
}
}
ExecutorService exec = Executors.newFixedThreadPool(nThread);
Vector<Future<Object>> tasks = new Vector<Future<Object>>
(nStackMax);
for (int n =0; n < nStackMax; n++){
System.out.println("ManagerJ: execute: " + (n+1));
PlanarImage pi = TankJ.getCurrentTankImageAt(n); //this method
gets the current image at postion n
MyCallable MyCall = new MyCallable( pi, n );
Future<Object> future = exec.submit(MyCall);
tasks.add(n, future);
}
for (int n =0; n < nStackMax; n++){
Future <Object> future = tasks.get(n);
Object ob = future.get();
resultVector.add(n,ob);
}
exec.shutdown();
boolean b = exec.awaitTermination(100, TimeUnit.DAYS);
System.out.println("Stack processing finished:" + b);
if (resultVector.get(0) instanceof PlanarImage) TankJ.addNewItem
(resultVector ); //The list of PlanarImages is set to the display
}