001    
002    /**
003     * Sequential Matrix Multiplication.
004     * Sequential algorithm, generating product matrix in blocks. 
005     * matrix B transposed.  
006     * @author Heinz Kredel.
007     */
008    
009    public class SeqMultBlockTrans implements MMInf {
010    
011        int blocksize = 1;
012    
013        public SeqMultBlockTrans(int size) {
014             this.blocksize = size; 
015        }
016    
017    
018    /**
019     * Performs the multiplication of two matrices, B transposed.
020     * C = A * trans(B).
021     * @param C result matrix.
022     * @param A matrix.
023     * @param B matrix.
024     */
025        public void multiply(double[][] C, double[][] A, double[][] B) {
026    
027          int na = blocksize;
028          int nb = blocksize;
029          System.out.println("#blocks = " + (A.length/na) + ", na = " + na 
030              + " SeqMultBlockTrans");
031    
032          for (int ii=0; ii < A.length; ii+=na) {
033              for (int jj=0; jj < B.length; jj+=nb) {
034    
035                  for (int i=ii; i < Math.min((ii+na),A.length); i++) {
036                      double[] Ai = A[i];
037                      for (int j=jj; j < Math.min((jj+nb),B.length); j++) {
038                          double[] Bj = B[j];
039                          double c = 0.0;
040                          for (int k=0; k < Bj.length; k++) {
041                              c += Ai[k] * Bj[k];
042                          }
043                          C[i][j] = c;
044                      }
045                  }
046    
047              }
048          }
049    
050        }
051    
052    }