I'm trying to write some code which will split up a vector into two
halves and run a method on the objects in the vector using two seperate
threads. I was hoping to see a near linear speedup on an SMP machine,
but I'm finding that the code below takes almost exactly the same
amount of time as when I iterate through the vector, and don't use any
threads at all (using only one processor). I'm running this on a Dual
Athlon machine under Redhat 9, and when I look at the processors,
they're both maxed out. Thanks in advance for any help.
andy
SMPEvlautionWra pper processor1Threa d; // This Class extends
Thread
SMPEvlautionWra pper processor2Threa d; // and holds some other
vars.
Vector tempEvalPopulat ion1=new Vector();
Vector tempEvalPopulat ion2=new Vector();
for (int j=0;j<tempRetur nVector.size()/2;j++){
tempEvalPopulat ion1.add((Indiv idual)tempRetur nVector.element At(j));
}
for (int
j=tempReturnVec tor.size()/2;j<tempReturnV ector.size();j+ +){
tempEvalPopulat ion2.add((Indiv idual)tempRetur nVector.element At(j));
}
processor1Threa d= new SMPEvlautionWra pper();
processor2Threa d= new SMPEvlautionWra pper();
processor1Threa d.initVars("pro cessor
1",(Vector)temp EvalPopulation1 .clone(),(Evalu ationFunction)t empEval.copy()) ;
processor2Threa d.initVars("pro cessor
2",(Vector)temp EvalPopulation2 .clone(),(Evalu ationFunction)t empEval.copy()) ;
try{
processor1Threa d.start();
processor2Threa d.start();
}catch(Exceptio n ex){
ex.printStackTr ace();
}
while(true){
if
((processor1Thr ead.finished==t rue)&&(processo r2Thread.finish ed==true)){
break;
}
try{
Thread.sleep(10 );
}catch(Exceptio n ex){
ex.printStackTr ace();
}
}