// psimeq.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(A[][],Y[],X[]); or psimeq(n,A[][],Y[],X[]); or // psimeq(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 // for threads on a shared memory architecture { int NP; // number of processors, modify to suit int n; // number of equations int m; // number of equations plus 1, RHS 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_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 barrierst; CyclicBarrier barrierp1; CyclicBarrier barrierp2; CyclicBarrier barrierp4; MyThread sthread[]; // = new MyThread[NP]; // allocate all threads psimeq(int NP, final double A[][], final double Y[], double X[]) { this.NP = NP; n=A.length; m=n+1; srow = new int[NP+1]; // starting row for each thread smax_pivot = new double[NP]; // max pivot each thread spivot = new int[NP]; // row for max pivot each thread sthread = new MyThread[NP]; // allocate all threads 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(int NP, int nn, final double A[][], final double Y[], double X[]) { this.NP = NP; n=nn; m=n+1; srow = new int[NP+1]; // starting row for each thread smax_pivot = new double[NP]; // max pivot each thread spivot = new int[NP]; // row for max pivot each thread sthread = new MyThread[NP]; // allocate all threads B=new double[n][m]; // working matrix solve(A, Y, X); } psimeq(int NP, int nn, final double AA[], final double Y[], double X[]) { this.NP = NP; n=nn; m=n+1; srow = new int[NP+1]; // starting row for each thread smax_pivot = new double[NP]; // max pivot each thread spivot = new int[NP]; // row for max pivot each thread sthread = new MyThread[NP]; // allocate all threads double A[][]=new double[n][n]; // reformat for(int i=0; i smax_pivot[myid]) { spivot[myid] = i; pivot = B[i][k_col]; smax_pivot[myid] = Math.abs(pivot); } } barrierp1.await(); // p1 barrierp2.await(); // p2 update between these two // reduce local rows // from srow[myid] to < srow[myid+1] // using k_row, k_col // inner reduction loop for(int i=srow[myid]; iabs_pivot) { I_pivot = spivot[i]; abs_pivot = smax_pivot[i]; } } // have pivot, interchange row indicies k_row = I_pivot; prow[k_col] = k_row; frow[k_row] = 1; // check for near singular if(abs_pivot < 1.0E-10) { for(int j=k_col+1; j