From: Arne Vagren on
Hello!

Inspired by the submission http://www.mathworks.com/matlabcentral/fileexchange/21233-mex-multithreading
I started to experiment a little with multithreaded mex functions. So far I have been doing only "embarrasingly parallel" stuff, on a dual core CPU, but I would be interested in doing something like FEM matrix assembly, e.g., in pseudocode,

Ke = sparse(n,n);
for e=1:nElements
dofs = getElementDOFs(e);
ke = elementStiffness;
Ke(dofs,dofs) = Ke(dofs,dofs) + ke
end

(I am aware that there are fairly efficient ways to do something like the above in matlab, http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/, but that's not my interest here.)

However, it looks like I might run into trouble if two threads try to write (and read?) to the same "dofs" in the last step of the loop. Is there a good, in the sense of reasonably simple code and noticeable speedup on a dual core, way to do this?

Best regards
Arne