Java Matrix Multiply matrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight, int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C)

Here you can find the source of matrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight, int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C)

Description

matrix Multiply With Thread Offset

License

Apache License

Declaration

public static void matrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight,
            int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static void matrixMultiplyWithThreadOffset(double[] A, double[] Adiag, double[] B, int aHeight,
            int bWidth, int comm, int bz, int threadRowOffset, int rowOffset, double[] C) {

        int aHeightBlocks = aHeight / bz; // size = Height of A
        int aLastBlockHeight = aHeight - (aHeightBlocks * bz);
        if (aLastBlockHeight > 0) {
            aHeightBlocks++;/*w  ww. j a  v a2  s  .c o  m*/
        }

        int bWidthBlocks = bWidth / bz; // size = Width of B
        int bLastBlockWidth = bWidth - (bWidthBlocks * bz);
        if (bLastBlockWidth > 0) {
            bWidthBlocks++;
        }

        int commnBlocks = comm / bz; // size = Width of A or Height of B
        int commLastBlockWidth = comm - (commnBlocks * bz);
        if (commLastBlockWidth > 0) {
            commnBlocks++;
        }

        int aBlockHeight = bz;
        int bBlockWidth = bz;
        int commBlockWidth = bz;

        double kTmp;
        double kiAdiag;
        int iOffset;
        for (int ib = 0; ib < aHeightBlocks; ib++) {
            if (aLastBlockHeight > 0 && ib == (aHeightBlocks - 1)) {
                aBlockHeight = aLastBlockHeight;
            }
            bBlockWidth = bz;
            commBlockWidth = bz;
            for (int jb = 0; jb < bWidthBlocks; jb++) {
                if (bLastBlockWidth > 0 && jb == (bWidthBlocks - 1)) {
                    bBlockWidth = bLastBlockWidth;
                }
                commBlockWidth = bz;
                for (int kb = 0; kb < commnBlocks; kb++) {
                    if (commLastBlockWidth > 0 && kb == (commnBlocks - 1)) {
                        commBlockWidth = commLastBlockWidth;
                    }

                    for (int i = ib * bz; i < (ib * bz) + aBlockHeight; i++) {
                        iOffset = i * bWidth;
                        for (int j = jb * bz; j < (jb * bz) + bBlockWidth; j++) {
                            for (int k = kb * bz; k < (kb * bz) + commBlockWidth; k++) {
                                kiAdiag = 0;
                                if (i + rowOffset == k) {
                                    kiAdiag = Adiag[i];
                                } else {
                                    //reverse the value from weight
                                    kiAdiag = -(A[(i + threadRowOffset) * comm + k]);
                                }

                                kTmp = B[k * bWidth + j];
                                if (kiAdiag != 0 && kTmp != 0) {
                                    C[iOffset + j] += kiAdiag * kTmp;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Related

  1. matrixMultiply(double[][] A, double[][] B, int n)
  2. matrixMultiply(double[][] M, float[] V)
  3. matrixMultiply(double[][] M1, double[][] M2)
  4. matrixmultiply(final double[][] A, final double[] b)
  5. matrixMultiplyTwo(final double[][] first, final double[][] second)
  6. matrixScalarMultiplication(double[][] w, double v)
  7. multiply(boolean[][] m1, boolean[][] m2)
  8. multiply(boolean[][] matrix, boolean[] vector)
  9. multiply(double[][] a, double[][] b)