Coder Social home page Coder Social logo

chrismahlke / strassen-algorithm Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 9 KB

The program provides functionalities to represent and operate on square matrices, supporting addition, subtraction, multiplication, and submatrix extraction, with a focus on matrices of sizes that are powers of 2.

License: Apache License 2.0

C++ 100.00%
strassen-algorithm matrix-multiplication cpp

strassen-algorithm's Introduction

Matrix Operations

This program provides a way to represent square matrices and perform basic matrix operations. The primary operations supported are addition, subtraction, multiplication, and submatrix extraction.

Code Structure

  1. Header File (matrix.h):

    • Defines the Matrix class that holds the details and operations of the square matrices.
    • Member functions include:
      • Basic constructors and destructors.
      • Overloaded operators for input/output.
      • Arithmetic operations such as addition, subtraction, and multiplication.
      • Submatrix extraction.
    • Note: Matrix dimensions are assumed to be powers of 2 for simplicity.
  2. Implementation File 1 (matrix.cpp):

    • Implements all the member functions and constructors defined in the Matrix class.
    • This file also provides utility functions, for example, ceilLogAndCompute, to ensure matrix sizes are powers of 2.
  3. Implementation File 2 (main.cpp):

    • Contains a simple matrix multiplication benchmark (matmultNaive) which multiplies two square matrices using a direct O(n^3) method.
    • Also uses an IPM_timer to measure the performance of this naive matrix multiplication.
    • Main function (main) reads the size of the matrix from command line arguments and then multiplies two matrices of the given size.

How to Run

  1. Compilation: Ensure you have all required dependencies, especially the ipm-2.0a/IPM_timer.h header. Once done, you can compile the project with:

    g++ matrix.cpp main.cpp -o matrix_operations
    

    This will create an executable named matrix_operations.

  2. Usage: Run the executable with the size of the matrix (a power of 2) as an argument. For example:

    ./matrix_operations 4
    

    This command will multiply two 4x4 matrices and display the results along with the time taken.

Notes

  • All matrices are assumed to be square.
  • The size of the matrix is expected to be a power of 2 due to certain optimization techniques applied in the Matrix class.
  • Matrix multiplication uses the conventional O(n^3) approach.
  • Ensure proper error handling when reading input from files or the command line.

Example

Running:

./matrix_operations 2

Will yield something like:

*************
* Matrix 1  *
*************
1.0 1.99
1.0 1.99

*************
* Matrix 2  *
*************
1.0 1.99
1.0 1.99

************
* Product: *
************
2.99 5.9601
2.99 5.9601

Elapsed time to compute: [Some value]u
MFlops: [Some value]

This README provides a comprehensive understanding of the code and its execution. Make sure to adjust paths and filenames accordingly if any changes are made to the codebase.

strassen-algorithm's People

Contributors

chrismahlke avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.