0

I have sequential code for sparse matrix multiplication. How to write the same code for parallel processing of sparse matrix?

%%sequential%%

A=[ 0 2 3;0 1 0;0 0 3 ];
[row col v] = find(A);
S(:,1)=row; S(:,2)=col; S(:,3)=v;
S_A = S; clear S;

B=[ 0 0 7;0 8 0;0 9 6 ];
[row col v] = find(B);
S(:,1)=row; S(:,2)=col; S(:,3)=v;
S_B = S;
a = sparse(A);
b = sparse(B);

k3=1;
tic
for i=1:size(S_A,1)
    for j=1:size(S_B,1)
        if S_A(i,2)== S_B(j,1)
            S_ans(k3,3) = S_A(i,3)*S_B(j,3);
            S_ans(k3,1)=S_A(i,1); S_ans(k3,2)=S_B(j,2);
             k3=k3+1; 
        end;
    end;
end;
time1=toc

I want to run the code for matrix multiplication in parallel in Matlab. I have written the sequential code for it. My aim is to reduce the execution time by running the code in parallelhow do i do it? Thank You

Jommy
  • 1,020
  • 1
  • 7
  • 14
  • 2
    Matlab automatically parallelizes this, at least for full matrices. See http://stackoverflow.com/questions/8321851/parallel-matrix-multiplication-in-matlab – Luis Mendo Jul 28 '14 at 11:22
  • 1
    Why are you writing your own sparse matrix multiplication, even in serial? Matlab has perfectly good [sparse matrix operations](http://www.mathworks.com/help/matlab/math/sparse-matrix-operations.html) which are almost certainly much faster than writing your own loops in matlab, and as @LuisMendo points out it will generally call threaded routines where available. – Jonathan Dursi Jul 28 '14 at 14:03

0 Answers0