examples/omp/benchmarks/kastors-1.1/strassen/src/strassen.c
static void FastNaiveMatrixMultiply(REAL *C, REAL *A, REAL *B, unsigned MatrixSize,
     unsigned RowWidthC, unsigned RowWidthA, unsigned RowWidthB)
{
  /* Assumes size of real is 8 bytes */
  PTR RowWidthBInBytes = RowWidthB  << 3;
  PTR RowWidthAInBytes = RowWidthA << 3;
  PTR MatrixWidthInBytes = MatrixSize << 3;
  PTR RowIncrementC = ( RowWidthC - MatrixSize) << 3;
  unsigned Horizontal, Vertical;

  REAL *ARowStart = A;
  for (Vertical = 0; Vertical < MatrixSize; Vertical++) {
    for (Horizontal = 0; Horizontal < MatrixSize; Horizontal += 8) {
      REAL *BColumnStart = B + Horizontal;
      REAL FirstARowValue = *ARowStart++;

      REAL Sum0 = FirstARowValue * (*BColumnStart);
      REAL Sum1 = FirstARowValue * (*(BColumnStart+1));
      REAL Sum2 = FirstARowValue * (*(BColumnStart+2));
      REAL Sum3 = FirstARowValue * (*(BColumnStart+3));
      REAL Sum4 = FirstARowValue * (*(BColumnStart+4));
      REAL Sum5 = FirstARowValue * (*(BColumnStart+5));
      REAL Sum6 = FirstARowValue * (*(BColumnStart+6));
      REAL Sum7 = FirstARowValue * (*(BColumnStart+7));

      unsigned Products;
      for (Products = 1; Products < MatrixSize; Products++) {
	REAL ARowValue = *ARowStart++;
	BColumnStart = (REAL*) (((PTR) BColumnStart) + RowWidthBInBytes);
	Sum0 += ARowValue * (*BColumnStart);
	Sum1 += ARowValue * (*(BColumnStart+1));
	Sum2 += ARowValue * (*(BColumnStart+2));
	Sum3 += ARowValue * (*(BColumnStart+3));
	Sum4 += ARowValue * (*(BColumnStart+4));
	Sum5 += ARowValue * (*(BColumnStart+5));
	Sum6 += ARowValue * (*(BColumnStart+6));
	Sum7 += ARowValue * (*(BColumnStart+7));
      }
      ARowStart = (REAL*) ( ((PTR) ARowStart) - MatrixWidthInBytes);

      *(C) = Sum0;
      *(C+1) = Sum1;
      *(C+2) = Sum2;
      *(C+3) = Sum3;
      *(C+4) = Sum4;
      *(C+5) = Sum5;
      *(C+6) = Sum6;
      *(C+7) = Sum7;
      C+=8;
    }
    ARowStart = (REAL*) ( ((PTR) ARowStart) + RowWidthAInBytes );
    C = (REAL*) ( ((PTR) C) + RowIncrementC );
  }
}
/*****************************************************************************
**
** FastNaiveMatrixMultiply
**
** For small to medium sized matrices A, B, and C of size
** MatrixSize * MatrixSize this function performs the operation
** C = A x B efficiently.
**
** Note MatrixSize must be divisible by 8.
**
** INPUT:
**    C = (*C WRITE) Address of top left element of matrix C.
**    A = (*A IS READ ONLY) Address of top left element of matrix A.
**    B = (*B IS READ ONLY) Address of top left element of matrix B.
**    MatrixSize = Size of matrices (for n*n matrix, MatrixSize = n)
**    RowWidthA = Number of elements in memory between A[x,y] and A[x,y+1]
**    RowWidthB = Number of elements in memory between B[x,y] and B[x,y+1]
**    RowWidthC = Number of elements in memory between C[x,y] and C[x,y+1]
**
** OUTPUT:
**    C = (*C WRITE) Matrix C contains A x B. (Initial value of *C undefined.)
**
*****************************************************************************/
FastNaiveMatrixMultiply
For small to medium sized matrices A, B, and C of size
MatrixSize * MatrixSize this function performs the operation
C = A x B efficiently.

Note MatrixSize must be divisible by 8.

C = (*C WRITE) Address of top left element of matrix C.
A = (*A IS READ ONLY) Address of top left element of matrix A.
B = (*B IS READ ONLY) Address of top left element of matrix B.


FastNaiveMatrixMultiply For small to medium sized matrices A B and C of size MatrixSize * MatrixSize this function performs the operation C = A x B efficiently . Note MatrixSize must be divisible by 8 . C = ( * C WRITE ) Address of top left element of matrix C . A = ( * A IS READ ONLY ) Address of top left element of matrix A . B = ( * B IS READ ONLY ) Address of top left element of matrix B .
static void FastNaiveMatrixMultiply(REAL *C, REAL *A, REAL *B, unsigned MatrixSize,
     unsigned RowWidthC, unsigned RowWidthA, unsigned RowWidthB)
{
  PTR RowWidthBInBytes = RowWidthB  << 3;
  PTR RowWidthAInBytes = RowWidthA << 3;
  PTR MatrixWidthInBytes = MatrixSize << 3;
  PTR RowIncrementC = ( RowWidthC - MatrixSize) << 3;
  unsigned Horizontal, Vertical;
  REAL *ARowStart = A;
  for (Vertical = 0; Vertical < MatrixSize; Vertical++) {
    for (Horizontal = 0; Horizontal < MatrixSize; Horizontal += 8) {
      REAL *BColumnStart = B + Horizontal;
      REAL FirstARowValue = *ARowStart++;
      REAL Sum0 = FirstARowValue * (*BColumnStart);
      REAL Sum1 = FirstARowValue * (*(BColumnStart+1));
      REAL Sum2 = FirstARowValue * (*(BColumnStart+2));
      REAL Sum3 = FirstARowValue * (*(BColumnStart+3));
      REAL Sum4 = FirstARowValue * (*(BColumnStart+4));
      REAL Sum5 = FirstARowValue * (*(BColumnStart+5));
      REAL Sum6 = FirstARowValue * (*(BColumnStart+6));
      REAL Sum7 = FirstARowValue * (*(BColumnStart+7));
      unsigned Products;
      for (Products = 1; Products < MatrixSize; Products++) {
	REAL ARowValue = *ARowStart++;
	BColumnStart = (REAL*) (((PTR) BColumnStart) + RowWidthBInBytes);
	Sum0 += ARowValue * (*BColumnStart);
	Sum1 += ARowValue * (*(BColumnStart+1));
	Sum2 += ARowValue * (*(BColumnStart+2));
	Sum3 += ARowValue * (*(BColumnStart+3));
	Sum4 += ARowValue * (*(BColumnStart+4));
	Sum5 += ARowValue * (*(BColumnStart+5));
	Sum6 += ARowValue * (*(BColumnStart+6));
	Sum7 += ARowValue * (*(BColumnStart+7));
      }
      ARowStart = (REAL*) ( ((PTR) ARowStart) - MatrixWidthInBytes);
      *(C) = Sum0;
      *(C+1) = Sum1;
      *(C+2) = Sum2;
      *(C+3) = Sum3;
      *(C+4) = Sum4;
      *(C+5) = Sum5;
      *(C+6) = Sum6;
      *(C+7) = Sum7;
      C+=8;
    }
    ARowStart = (REAL*) ( ((PTR) ARowStart) + RowWidthAInBytes );
    C = (REAL*) ( ((PTR) C) + RowIncrementC );
  }
}
static void FastNaiveMatrixMultiply ( REAL * C , REAL * A , REAL * B , unsigned MatrixSize , unsigned RowWidthC , unsigned RowWidthA , unsigned RowWidthB ) { PTR RowWidthBInBytes = RowWidthB << 3 ; PTR RowWidthAInBytes = RowWidthA << 3 ; PTR MatrixWidthInBytes = MatrixSize << 3 ; PTR RowIncrementC = ( RowWidthC - MatrixSize ) << 3 ; unsigned Horizontal , Vertical ; REAL * ARowStart = A ; for ( Vertical = 0 ; Vertical < MatrixSize ; Vertical ++ ) { for ( Horizontal = 0 ; Horizontal < MatrixSize ; Horizontal += 8 ) { REAL * BColumnStart = B + Horizontal ; REAL FirstARowValue = * ARowStart ++ ; REAL Sum0 = FirstARowValue * ( * BColumnStart ) ; REAL Sum1 = FirstARowValue * ( * ( BColumnStart + 1 ) ) ; REAL Sum2 = FirstARowValue * ( * ( BColumnStart + 2 ) ) ; REAL Sum3 = FirstARowValue * ( * ( BColumnStart + 3 ) ) ; REAL Sum4 = FirstARowValue * ( * ( BColumnStart + 4 ) ) ; REAL Sum5 = FirstARowValue * ( * ( BColumnStart + 5 ) ) ; REAL Sum6 = FirstARowValue * ( * ( BColumnStart + 6 ) ) ; REAL Sum7 = FirstARowValue * ( * ( BColumnStart + 7 ) ) ; unsigned Products ; for ( Products = 1 ; Products < MatrixSize ; Products ++ ) { REAL ARowValue = * ARowStart ++ ; BColumnStart = ( REAL * ) ( ( ( PTR ) BColumnStart ) + RowWidthBInBytes ) ; Sum0 += ARowValue * ( * BColumnStart ) ; Sum1 += ARowValue * ( * ( BColumnStart + 1 ) ) ; Sum2 += ARowValue * ( * ( BColumnStart + 2 ) ) ; Sum3 += ARowValue * ( * ( BColumnStart + 3 ) ) ; Sum4 += ARowValue * ( * ( BColumnStart + 4 ) ) ; Sum5 += ARowValue * ( * ( BColumnStart + 5 ) ) ; Sum6 += ARowValue * ( * ( BColumnStart + 6 ) ) ; Sum7 += ARowValue * ( * ( BColumnStart + 7 ) ) ; } ARowStart = ( REAL * ) ( ( ( PTR ) ARowStart ) - MatrixWidthInBytes ) ; * ( C ) = Sum0 ; * ( C + 1 ) = Sum1 ; * ( C + 2 ) = Sum2 ; * ( C + 3 ) = Sum3 ; * ( C + 4 ) = Sum4 ; * ( C + 5 ) = Sum5 ; * ( C + 6 ) = Sum6 ; * ( C + 7 ) = Sum7 ; C += 8 ; } ARowStart = ( REAL * ) ( ( ( PTR ) ARowStart ) + RowWidthAInBytes ) ; C = ( REAL * ) ( ( ( PTR ) C ) + RowIncrementC ) ; } }
FastNaiveMatrixMultiply
For small to medium sized matrices A, B, and C of size
MatrixSize * MatrixSize this function performs the operation
C = A x B efficiently.
FastNaiveMatrixMultiply For small to medium sized matrices A B and C of size MatrixSize * MatrixSize this function performs the operation C = A x B efficiently .
/* Assumes size of real is 8 bytes */