/* !-------------------------------------------------------------------------! ! ! ! N A S P A R A L L E L B E N C H M A R K S 3.0 ! ! ! ! J A V A V E R S I O N ! ! ! ! C G W o r k e r ! ! ! !-------------------------------------------------------------------------! ! ! ! CGworker implements thread for sparse subroutine of CG benchmark. ! ! ! ! Permission to use, copy, distribute and modify this software ! ! for any purpose with or without fee is hereby granted. We ! ! request, however, that all derived work reference the NAS ! ! Parallel Benchmarks 3.0. This software is provided "as is" ! ! without express or implied warranty. ! ! ! ! Information on NPB 3.0, including the Technical Report NAS-02-008 ! ! "Implementation of the NAS Parallel Benchmarks in Java", ! ! original specifications, source code, results and information ! ! on how to submit new results, is available at: ! ! ! ! http://www.nas.nasa.gov/Software/NPB/ ! ! ! ! Send comments or suggestions to npb@nas.nasa.gov ! ! ! ! NAS Parallel Benchmarks Group ! ! NASA Ames Research Center ! ! Mail Stop: T27A-1 ! ! Moffett Field, CA 94035-1000 ! ! ! ! E-mail: npb@nas.nasa.gov ! ! Fax: (650) 604-3957 ! ! ! !-------------------------------------------------------------------------! ! Translation to Java and to MultiThreaded Code ! ! M. Frumkin ! ! M. Schultz ! !-------------------------------------------------------------------------! */ package NPB_JAV.CGThreads; import NPB_JAV.CG; public class CGWorker extends CGBase{ public boolean done = true; public int id; public int TaskOrder; int start1, end1; public double alpha,beta; public CGWorker(CG cg,int st,int end){ Init(cg); start1=st; end1=end; done = true; setDaemon(true); setPriority(Thread.MAX_PRIORITY); master=cg; } void Init(CG cg){ //initialize shared data dmaster = cg.dmaster; rhomaster = cg.rhomaster; rnormmaster = cg.rnormmaster; colidx = cg.colidx; rowstr = cg.rowstr; a = cg.a; p = cg.p; q = cg.q; r = cg.r; x = cg.x; z = cg.z; } public void run(){ int state=0; for(;;){ synchronized(this){ while(done){ try{ wait(); synchronized(master){ master.notify(); // alpha=master.alpha; // beta=master.beta; } }catch(InterruptedException ie){} } switch(TaskOrder){ case 0: step0(); break; case 1: step1(); break; case 2: step2(); break; case 3: step3(); break; case 4: endWork(); break; } synchronized(master){ done=true;master.notify(); } } } } void step0(){ for(int j=start1;j<=end1;j++){ double sum = 0.0; for(int k=rowstr[j];k