Programming assignment No'1: Threaded Sparse Matrix Multiplication - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Programming assignment No'1: Threaded Sparse Matrix Multiplication

Description:

Experience with practical issues in the steps for parallelization, in ... for (k=0; k A- col; k ) tmp = smGet(A, I, k) * smGet(B, k, j); smSet(C, I, j, tmp) ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 12
Provided by: xiny2
Category:

less

Transcript and Presenter's Notes

Title: Programming assignment No'1: Threaded Sparse Matrix Multiplication


1
Programming assignment No.1 Threaded Sparse
Matrix Multiplication
2
Objective
  • Practice programming with threads
  • Experience with practical issues in the steps for
    parallelization, in particular, load balancing.
  • Write a parallel code that beats the state of the
    art production quality sequential code.

3
Sparse matrix
  • A matrix with a lot of zeros.
  • Would work with dense matrix, but will be less
    efficient.

4
Sparse matrix representation
  • To get efficiency, one should only store and
    process non-zeros.
  • Common Compressed Sparse Column (CSC) format and
    common Compressed Sparse Row (CSR) format.
  • nonzero for data
  • jc for row indices
  • ir for the starting index
  • of each column (CRC).

5
CSC example
  • How to find out the number of non-zeros in the
    matrix?
  • SMGet(A, I, j)?
  • SMPut(C, I, j, value)?

6
The routine to be implemented
  • A driver program will be provided so that you do
    not have to worry about I/O (main.c).
  • But you will still need to learn the driver
    program.
  • Internal array representations do not have to be
    CSC or CSR.
  • E.g. a meshed linked lists (linked lists in two
    dimensions)

7
A simple sparse matrix multiply algorithm
  • void sparsemm (A, B, C)
  • int I, j, k
  • double tmp
  • for (i0 ilta-gtrow i)
  • for (j0 jltB-gtcol j)
  • tmp 0.0
  • for (k0 kltA-gtcol k)
  • tmp smGet(A, I, k) smGet(B, k,
    j)
  • smSet(C, I, j, tmp)

What is wrong with this? O(N4) algorithm for
Multiplying NxN matrices!
8
A better algorithm
  • sparsemm(A,B, C)
  • int I, j
  • double tmp
  • triplet_item rowp, colp
  • make AA, BB the meshed linked list
    representation for A and B
  • for (i0 iltA-gtrow i)
  • for(j0 jltB-gtcol j)
  • rowp A-gtrowsi colp B-gtcolsj
  • tmp 0
  • while ((rowp!NULL) (colp !
    NULL))
  • if (rowp-gtindex colp-gtindex)
  • tmp rowp-gtvalue
    colp-gtvalue
  • rowp rowp-gtnext colp
    colp-gtnext
  • else if (rowp-gtindex lt
    colp-gtindex) rowp rowp-gtnext
  • else colp colp-gtnext
  • smset(CC, I, j, tmp)
  • convert CC to C

This is a better algorithm. See the data
structures.
9
For more information
For parallel sparse matrix multiply
For sequential sparse matrix multiply
10
Grading
  • Correctness and performance
  • All program must be correct to get any points (a
    driver program is given so that you do not need
    to do I/O, just make sure your mm routines yields
    correct output format).
  • 40 points for correct sequential code
  • 20 points for 1.5x speedup compared to your own
    code for three large matrices on linprog
  • 35 points for 1.5x speedup compared to the sample
    executable on linprog.
  • Same code is based on the SMMP package from
    http//www.mgnet.org/douglas/ccd-free-software.ht
    ml
  • 5 points for demo.

11
Due dates
  • Sept. 16, 1100am for sequential code
  • Sept. 23, 1100am for threaded code
  • Tar your project and send me the tar file (with
    makefile, README, and source code only).
Write a Comment
User Comments (0)
About PowerShow.com