http://imagej.273.s1.nabble.com/Using-multiprocessors-tp3697558p3697561.html
> Jon,
>
> Here is the approach I've taken. My codes run 4 times as fast on my
> 4-processor Mac now:
>
> int nThreads = Runtime.getRuntime().availableProcessors();
> ...
> Step1Thread[] s1t = new Step1Thread[nThreads];
> for(int thread = 0; thread < nThreads; thread++){
> s1t[thread] = new Step1Thread(thread,nThreads,w,h,d,s,data);
> s1t[thread].start();
> }
> try{
> for(int thread = 0; thread< nThreads; thread++){
> s1t[thread].join();
> }
> }catch(InterruptedException ie){
> IJ.error("A thread was interrupted in step 1 .");
> }
>
> Here Step1Thread is a class that has a run method that does part of
> the work. In this case, it operates on a subset of the slices in a
> stack, but there are many ways to break up a problem. It figures
> out what part of the work to do based on its thread number and
> nThreads. The .join operation causes the main code to wait until
> everybody is done.
>
> Here is the example Step1Thread. I removed some of the variables and
> arguments of the constructor to simplify it. In practice, more
> parameters concerning the particular task are necessary for the run
> method to do its job.
>
> class Step1Thread extends Thread{
> int thread,nThreads,w,h,d;
> float[][] s;
> byte[][] data;
> public Step1Thread(int thread, int nThreads, int w, int h, int d,
> float[][] s, byte[][] data){
> this.thread = thread;
> this.nThreads = nThreads;
> this.w = w;
> this.h = h;
> this.d = d;
> this.data = data;
> this.s = s;
> }
> public void run(){
> float[] sk;
> byte[] dk;
> for(int k = thread; k < d; k+=nThreads){
> sk = s[k]; //Slice k of output
> dk = data[k]; //Slice k of input
> for(int j = 0; j < h; j++){
> sk[i+w*j] =something computed from dk;
> }
> }
> }
> }
>
>
>
> Bob
>
>
>
>
> On Jan 16, 2008, at 10:48 AM, Jon Harman wrote:
>
> > Hi,
> >
> > I am not a sophisticated programmer and need some advice on how (if
> > possible) to speed up my plugin on multiprocessor machines.
> >
> > Context: I just got a quad core machine.
> >
> > The main routine in my plugin goes through an image pixel by pixel
> > and transforms each pixel. The result for each pixel is
> > independent of the other pixels. So is there a way I can split the
> > image into pieces and use a separate processor on each piece?
> >
> > Jon
> >
>
> Robert Dougherty, Ph.D.
> President, OptiNav, Inc.
> 10900 NE 8th St, Suite 900
> Bellevue, WA 98004
> Tel. (425)990-5912
> FAX (425)467-1119
> www.optinav.com
>
[hidden email]
>