Class BlockMultiply

  • All Implemented Interfaces:
    java.util.concurrent.Callable<java.lang.Void>

    public class BlockMultiply
    extends java.lang.Object
    implements java.util.concurrent.Callable<java.lang.Void>
    Multiply blocks of A and B in the specified range(fromM->toM, fromN->toN, fromK->toK),
    and add to matrix C.

    C(fromM->toM, fromK->toK) +=
           A(fromM->toM, fromN->toN) x B(fromN->toN, fromK->toK)

    All blocks must be square blocks of the same size, with length of one side = blockStripeSize

    • Field Detail

      • blockStripeSize

        private final int blockStripeSize
        Length of one side of a block of data.
      • fromM

        private final int fromM
        range of data in matrix to be processed by this instance.
      • toM

        private final int toM
        range of data in matrix to be processed by this instance.
      • fromN

        private final int fromN
        range of data in matrix to be processed by this instance.
      • toN

        private final int toN
        range of data in matrix to be processed by this instance.
      • fromK

        private final int fromK
        range of data in matrix to be processed by this instance.
      • toK

        private final int toK
        range of data in matrix to be processed by this instance.
    • Constructor Detail

      • BlockMultiply

        public BlockMultiply​(BlockDenseDoubleMatrix2D a,
                             BlockDenseDoubleMatrix2D b,
                             BlockDenseDoubleMatrix2D c,
                             int fromM,
                             int toM,
                             int fromN,
                             int toN,
                             int fromK,
                             int toK)
        Constructor taking the two matrices being multiplied, the target matrix C and the range of rows and columns to multiply.
        Parameters:
        a - - matrix A, size (M, N)
        b - - matrix B, size (N, K)
        c - - result matrix C, size (M, K)
        fromM - - start row M in matrix A
        toM - - end row M in A
        fromN - - start column N in A (or start row N in B)
        toN - - end row N
        fromK - - start column K in B
        toK - - end column K in B
    • Method Detail

      • call

        public java.lang.Void call()
        Specified by:
        call in interface java.util.concurrent.Callable<java.lang.Void>
      • multiply

        protected final void multiply()
        Multiply blocks of two matrices A,B and add to C.

        Blocks of Matrix B are transformed to column-major layout (if not already) to facilitate multiplication.
        (If matrices have been created optimally, B should already be column-major)

      • multiplyAxB

        private static void multiplyAxB​(double[] aBlock,
                                        double[] bBlock,
                                        double[] cBlock,
                                        int step)
        Multiply row-major block (a) x column-major block (b), and add to block c.
        Parameters:
        a - - block from matrixA
        b - - block from matrixB
        c - - block from result matrix matrixC
      • multiplyRowMajorTimesColumnMajorBlocks

        public void multiplyRowMajorTimesColumnMajorBlocks​(double[] aBlock,
                                                           double[] bBlock,
                                                           double[] cBlock,
                                                           int aRows,
                                                           int bRows,
                                                           int bCols)