//claimed function for calling the program, only due to the assignment tasks static void matrixmult(const int M, const int N, const int K, double * A, const int lda, double * B, int ldb, double * C, int ldc) { Matrix MatrixA(M,K,A,lda); Matrix MatrixB(K,N,B,ldb); Matrix MatrixC(M,N); //for matrices with dimensions to the power of two strassen is used if(Matrix::checkIfPowerOfTwo(M,K)) { if(Matrix::checkIfPowerOfTwo(K,N)) { Matrix::matmult(MatrixA,MatrixB,MatrixC); } } else { //otherwise native matrix multiplication MatrixC = MatrixA*MatrixB; } for(size_t i = 0; i< MatrixC.getMdim() ; ++i) { for(size_t j = 0; j<MatrixC.getNdim() ; ++j) { C[i*ldc + j] = MatrixC.getValueAt(i,j); } } }
int main() { long start_time; //Used for execution time (Start of execution) long stop_time; //Used for execution end time (End of execution) Matrix MatrixA("DataMatrixA.txt");//Input File data goes to Matrix A Matrix MatrixB("DataMatrixB.txt");// Input File data goes to Matrix B Matrix MatrixC(MatrixA.getRow(),MatrixB.getColumn());//Matrix C result gets rows of A and columns of B start_time=clock();//Starts timer HorizontalMultiply(MatrixA, MatrixB,MatrixC);//Computing Multiplication stop_time=clock();//End timer double Horizontal_Time= (stop_time-start_time)/(double)(CLOCKS_PER_SEC); //Execution time MatrixC.print(); //Print result of Matrix C cout << endl; cout << "________________________________________________________________ " << endl; cout << "Divide Horizontal Time: (Core Count in System): " << Horizontal_Time << " seconds" << endl; cout << "________________________________________________________________ " << endl; long start_time2; //Timer for twice the core count long stop_time2;//End timer for twice the core count Matrix MatrixC2(MatrixA.getRow(),MatrixB.getColumn()); //MatrixC2 gets A rows and B cols start_time2= clock();//Start timer for function for twice core count HorizontalMultiply2(MatrixA, MatrixB, MatrixC2);//Twice core count multipling stop_time2 = clock();//End timer for function for twice core count double Horizontal_Time2 = (stop_time2-start_time2)/(double)(CLOCKS_PER_SEC); //Total execution time of twice core count Multiply MatrixC2.print();//Print Matrix C cout << endl; cout << "_______________________________________________________________"<< endl; cout << "Divide Horizontal Time: (Twice amount of Cores in a system): " << Horizontal_Time2 << " seconds " << endl; cout << "_______________________________________________________________" << endl; return 0; }