/*
 *  Copyright Oct 24, 2009 OpenSourceStewardshipFoundation.org
 *  Licensed under GNU General Public License version 2
 */

#ifndef MATRIX_MULT_H_
#define MATRIX_MULT_H_

#include <stdio.h>
#include <unistd.h>
#include <malloc.h>

#include "VMS_impl/VMS_primitive_data_types.h"
#include "ParamHelper/Param.h"

//==============================  Structures  ==============================

typedef struct
 { int32 numRows;
   int32 numCols;
   float32 *array;  //2D, but dynamically sized, so use addr arith
 }
Matrix;

/* This is the "appSpecificPiece" that is carried inside a DKUPiece.
 *  In the DKUPiece data struc it is declared to be of type "void *".  This
 *  allows the application to define any data structure it wants and put it
 *  into a DKUPiece.
 * When the app specific info is used, it is in app code, so it is cast to
 *  the correct type to tell the compiler how to access fields.
 * This keeps all app-specific things out of the DKU directory, as per the
 *  DKU standard. */
typedef struct
 { 
      // pointers to shared data..  the result matrix must be created when the
      //  left and right matrices are put into the root ancestor DKUPiece.
   Matrix * leftMatrix;
   Matrix * rightMatrix;
   Matrix * resultMatrix;

      // define the starting and ending boundaries for this piece of the
      //  result matrix.  These are derivable from the left and right
      //  matrices, but included them for readability of code.
   int prodStartRow, prodEndRow;
   int prodStartCol, prodEndCol;
      // Start and end of the portion of the left matrix that contributes to
      //  this piece of the product
   int leftStartRow, leftEndRow;
   int leftStartCol, leftEndCol;
      // Start and end of the portion of the right matrix that contributes to
      //  this piece of the product
   int rightStartRow, rightEndRow;
   int rightStartCol, rightEndCol;
 }
MatrixProdPiece;

//==============================  Functions  ================================
void readFile();

Matrix *makeMatrix( int32 numRows, int32 numCols );
Matrix *makeMatrix_Flat( int32 numRows, int32 numCols );
Matrix *makeMatrix_WithResMat( int32 numRows, int32 numCols );
void    freeMatrix_Flat( Matrix * matrix );
void    freeMatrix( Matrix * matrix );
void    printMatrix( Matrix *matrix );

void read_Matrix_From_File( Matrix *matrixStruc, char *matrixFileName );

void
initialize_Input_Matrices_Via( Matrix  **leftMatrix, Matrix **rightMatrix,
                              ParamBag *paramBag );

//===========================================================================

#endif /*MATRIX_MULT_H_*/
