// psimeq_dbg.java solve simultaneous equations AX=Y // solve real linear equations for X where Y = A * X // method: Gauss-Jordan elimination using maximum pivot // usage: psimeq_dbg(A[][],Y[],X[]); or psimeq_dbg(n,A[][],Y[],X[]); or // psimeq_dbg(n,A[],Y[],X[]); // Translated to java by : Jon Squire , 26 March 2003 // First written by Jon Squire December 1959 for IBM 650, translated to // other languages e.g. Fortran converted to Ada converted to C // then converted to java, then made parallel October 2008 import java.util.concurrent.*; // uses barrier.await() and others public class psimeq_dbg // for threads on a shared memory architecture { final int NP=4; // number of processors, modify to suit int n; // number of equations int m; // number of equations plus 1 double B[][]; // working array, various processors on various parts int prow[]; // pivot row if not -1, variable number int frow[]; // finished row if not 0 int k_col=0; // column being reduced, initial zero for "start" int k_row=0; // pivot row int srow[] = new int[NP+1]; // starting row for each thread double smax_pivot[] = new double[NP]; // max pivot each thread int spivot[] = new int[NP]; // row for max pivot each thread CyclicBarrier barrier; long t_start = System.currentTimeMillis(); double t_end; MyThread sthread[] = new MyThread[NP]; // allocate all threads psimeq_dbg(final double A[][], final double Y[], double X[]) { n=A.length; m=n+1; B=new double[n][m]; // working matrix if(A[0].length!=n || Y.length!=n || X.length!=n) { System.out.println("Error in Matrix.solve, inconsistent array sizes."); } solve(A, Y, X); } psimeq_dbg(int nn, final double A[][], final double Y[], double X[]) { n=nn; m=n+1; B=new double[n][m]; // working matrix solve(A, Y, X); } psimeq_dbg(int nn, final double AA[], final double Y[], double X[]) { n=nn; m=n+1; double A[][]=new double[n][n]; // reformat for(int i=0; i=n-1) break; barrier = new CyclicBarrier(NP+1); // p2 System.out.println("master at p2 barrier.await(), k_col="+k_col); barrier.await(); // p2 System.out.println("master passed p2, k_col="+k_col); System.out.println("looping to next k_col"); } // finished solve } catch(InterruptedException e) { System.out.println("InterruptedException in master"); } catch(BrokenBarrierException e) { System.out.println("BrokenBarrierException in master"); } System.out.println("master waiting for join"); try { for(int i=0; i smax_pivot[myid]) { spivot[myid] = i; pivot = B[i][k_col]; smax_pivot[myid] = Math.abs(pivot); } } System.out.println(myid+" spivot="+spivot[myid]+", smax="+ smax_pivot[myid]); System.out.println(myid+" at p1 pivot barrier.await()"); barrier.await(); // p1 sleep(10); System.out.println(myid+" passed p1 pivot barrier"); // reduce local rows // from srow[myid] to < srow[myid+1] // using k_row, k_col // inner reduction loop for(int i=srow[myid]; i=n-1) break; // this task may terminate barrier.await(); // p2 sleep(10); System.out.println(myid+" looping to find max for pivot"); } // do next column } // end try catch(InterruptedException e) { System.out.println(myid+" InterruptedException"); } catch(BrokenBarrierException e) { System.out.println(myid+" BrokenBarrierException"); } th_end = (double)(System.currentTimeMillis()-t_start)/1000.0; System.out.println(myid+" thread ends at "+th_end); } // end Run } // end class MyThread void update_row() // unify max pivots, update row[], { int I_pivot, hold; double abs_pivot; System.out.println(" "); System.out.println("in update_row for k_col="+k_col); // find max of threads abs_pivot = smax_pivot[0]; I_pivot = spivot[0]; for(int i=1; iabs_pivot) { I_pivot = spivot[i]; abs_pivot = smax_pivot[i]; } } System.out.println("update_row I_pivot="+I_pivot+", abs_pivot="+abs_pivot); // have pivot, interchange row indicies k_row = I_pivot; prow[k_col] = k_row; frow[k_row] = 1; System.out.println("update prow["+k_col+"]="+k_row); // check for near singular if(abs_pivot < 1.0E-10) { for(int j=k_col+1; j