Difference between revisions of "MatrixMultiply"

From CSE231 Wiki
Jump to navigation Jump to search
Line 74: Line 74:
 
{{Parallel|public double[][] multiply(double[][] a, double[][] b)}}
 
{{Parallel|public double[][] multiply(double[][] a, double[][] b)}}
  
 +
[https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/spring22/apidocs/fj/FJ.html#join_void_fork_loop_2d_auto_coarsen(int,int,int,int,fj.api.TaskBiIntConsumer) join_void_fork_loop_2d_auto_coarsen]
 
<!--
 
<!--
 
In this implementation, we will add a minor performance boost to the process by using the forall-chunked construct. Although similar to the traditional forall loop, it increases performance using iteration grouping/chunking. This topic is discussed in detail in this [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/6349730bb2a149a0b33fa23db7afddee/?activate_block_id=i4x%3A%2F%2FRiceX%2FCOMP322%2Fsequential%2F6349730bb2a149a0b33fa23db7afddee Rice video] and explained in the [[Reference_Page#Parallel_Loops|V5 documentation]]. There is no need to specify anything, allow the runtime to determine the chunking.
 
In this implementation, we will add a minor performance boost to the process by using the forall-chunked construct. Although similar to the traditional forall loop, it increases performance using iteration grouping/chunking. This topic is discussed in detail in this [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/6349730bb2a149a0b33fa23db7afddee/?activate_block_id=i4x%3A%2F%2FRiceX%2FCOMP322%2Fsequential%2F6349730bb2a149a0b33fa23db7afddee Rice video] and explained in the [[Reference_Page#Parallel_Loops|V5 documentation]]. There is no need to specify anything, allow the runtime to determine the chunking.

Revision as of 23:21, 1 February 2022

Motivation

We gain experience using the parallel for loop constructs.

Background

Matrix multiplication is a simple mathematical operation which we will replicate in this studio. For our purposes, we will only deal with square matrices (same number of rows and columns). However, we will approach this problem with several different parallel constructs and approaches.

For those unfamiliar on how to multiply two matrices, take a look at these overviews:

If is an matrix and is an matrix

for each i=[0..n) and for each j=[0..p)

source: Matrix Multiplication on Wikipedia

Code To Investigate

Demo Video

SequentialMatrixMultiplier

class: SequentialMatrixMultiplier.java DEMO: Java.png
methods: multiply
package: matrixmultiply.demo
source folder: src//java

SequentialMatrixMultiplierClient

class: SequentialMatrixMultiplierClient.java DEMO: Java.png
methods: main
package: matrixmultiply.client
source folder: src//java

MatrixMultiplyApp

class: MatrixMultiplyApp.java VIZ
package: main
source folder: student/src/matrixmultiply.viz/java

Martix multiply app 3x5 X 5x4.png

The Core Questions

  • What are the tasks?
  • What is the data?
  • Is the data mutable?
  • If so, how is it shared?

Code To Implement

There are three methods you will need to implement, all of which are different ways to use parallel for loops to solve the problem. To assist you, the sequential implementation has already been completed for you. We recommend starting from the top and working your way down. There is also an optional recursive implementation and a manual grouping implementation which has been done for you (this is just to demonstrate how chunking works behind the scenes).

LoopLoopMatrixMultiplier

class: LoopLoopMatrixMultiplier.java Java.png
methods: multiply
package: matrixmultiply.exercise
source folder: student/src/main/java

method: public double[][] multiply(double[][] a, double[][] b) Parallel.svg (parallel implementation required)

In this implementation, you will simply convert the sequential solution into a parallel one using two nested parallel fork loops.

Loop2dMatrixMultiplier

class: Loop2dMatrixMultiplier.java Java.png
methods: multiply
package: matrixmultiply.exercise
source folder: student/src/main/java

method: public double[][] multiply(double[][] a, double[][] b) Parallel.svg (parallel implementation required)


join_void_fork_loop_2d

Loop2dAutoCoarsenMatrixMultiplier

class: Loop2dAutoCoarsenMatrixMultiplier.java Java.png
methods: multiply
package: matrixmultiply.exercise
source folder: student/src/main/java

method: public double[][] multiply(double[][] a, double[][] b) Parallel.svg (parallel implementation required)

join_void_fork_loop_2d_auto_coarsen

Extra Credit Challege Divide and Conquer

Divide and Conquer Matrix Multiplication

Testing Your Solution

Correctness

class: __MatrixMultiplyTestSuite.java Junit.png
package: matrixmultiply.studio
source folder: testing/src/test/java

Performance

class: MatrixMultiplicationTiming.java Noun Project stopwatch icon 386232 cc.svg
package: matrixmultiply.performance
source folder: src/main/java

Investigate the performance difference for your different implementations. When you run MatrixMultiplicationTiming it will put a CSV of the timings into your copy buffer. You can then paste them into a spreadsheet and chart the performance. Feel free to tune the parameters of the test to see the impacts of, for example, different matrix sizes.

Matrix multiply performance.png