java threading problem... threads only work on 1 processor

I've got a iterative deepening problem that i have to parallelize. As far as i know i did everything correctly however everything seems to be running on 1 processor instead of 2 processors. As far as i know i am using threads (-Xprof either defines them as thread-1 thread-2 or pool1-thread1,depending on the method used for issueing)

the worker thread is:

publicint solutionsT(Board board,int currentDepth){

int temp = 0;

int result = 0;

if (board.distance() == 0){

return 1;

}

if (board.distance() > board.bound()){

return 0;

}

Board[] children = board.makeMoves();

result = 0;

for (int i = 0; i < children.length; i++){

if (children[i] !=null){

temp = solutionsT(children[i], currentDepth + 1);

if(temp != 0){

result += temp;

}

}

}

return result;

}

publicvoid run(){

int temp =0;

int i = 0;

while(true){

while(bag.size() !=0){

bag.putSolution(solutionsT(bag.get(),1));

}

try{

barrier.await();

}catch(Exception e){}

}

}

}

it get's it's input from a bag that is filled before the iteration begins. (once the bag is filled it trips a barrier) this worker thread is a implementation of Runnable

This piece of code is used to make the thread object and to issue it

public SolutionThread(int numberOfThreads){

thread = numberOfThreads;

bag =new bagOfBoards();

barrier =new CyclicBarrier(thread+1);

if(thread > 1){

ExecutorService threadExecutor = Executors.newFixedThreadPool( thread );

solution =new ThreadTest[thread];

bag =new bagOfBoards();

for(int i = 0;i<thread;i++){

solution[i] =new ThreadTest(bag, lock, barrier, i);

threadExecutor.execute(solution[i]);

}

}

}

finally this is the code which is used to acces the bag and get a board.

synchronizedpublic Board get(){

if (size > 0){

size--;

Board result = bag[size];

return result;

}else{

returnnull;

}

}

since this method is synchronized and it always returns something (either null or a board) and the worker tests for this. there is no race condition here.

furter more. the main thread is a loop. It fills te bags with an intial state. then it trips the barrier and waits for the workers to do the work. the workers then process the bag until it hits zero and then trip the barrier so that the main thread can do the next iteration (and fill the bag)

p.s. i know the code is a bit messy, but i want to get the threading to work. As of now i relaly don't understand why the threads are just running on 1 processor instead of 2 processors. not only that. the excecution time is nearly the same as that of a sequential equivalent.

p.s.2 the code is parallisable. and it is run on a smp system.

Message was edited by:

jstrike

[5298 byte] By [jstrikea] at [2007-11-26 17:12:13]
# 1
In principle it's not enough that the Java algoritm is parallelized using threading. This must then be followed through by the JVM/OS combination to the multiple processors.I'm not sure really what's required to make this happen.
jstrikea at 2007-7-8 23:40:06 > top of Java-index,Java Essentials,Java Programming...
# 2
i'm very sure that the jvm and os support smp. the problem really should be in the code. Or did you meant that i have to tell the jvm in the class that there is support for multiple processors
jstrikea at 2007-7-8 23:40:06 > top of Java-index,Java Essentials,Java Programming...
# 3

> i'm very sure that the jvm and os support smp. the

> problem really should be in the code. Or did you

> meant that i have to tell the jvm in the class that

> there is support for multiple processors

I don't know really? I haven't seen any article or other information dealing with this topic. At this point I only know that in principle the concurrency expressed in the Java language must somehow trickle down to the physical multiple processors. But if you know it does than that's not your problem.

jstrikea at 2007-7-8 23:40:06 > top of Java-index,Java Essentials,Java Programming...
# 4

> i'm very sure that the jvm and os support smp. the

> problem really should be in the code.

I don't see how this can be the case. There's nothing in the Java language that deals with how threads are assigned to processors (at least not as far as I know) so there isn't anything you can do in your code to affect that.

> Or did you meant that i have to tell the jvm in the class that

> there is support for multiple processors

That would be the only possibility. I have no idea whether it can be done or not, though.

DrClapa at 2007-7-8 23:40:06 > top of Java-index,Java Essentials,Java Programming...
# 5

the jvm it's running on has been confirmed to run on multiple processors. It's used to do so for a couple of years now, i have no reason to doubt that (in fact i have no option to doubt that because i can't do anything about it)

the threading doens't work all that well so i'll have to look into blocking or stuff like that. :(

jstrikea at 2007-7-8 23:40:06 > top of Java-index,Java Essentials,Java Programming...