# Inverting many small matrices in parallel

I am trying to find a good way to handle the following problem: Let C be an N by 3 array (corresponding to points in $\mathbb{R}^3$). There is a method I am interested in testing which requires constructing, for i=1....N, a matrix $A_i$ of size $n_i <<N$ and a vector $b_i$ of size $n_i$ using only data from the row i of C. Then, we seek the solution $x_i = A_i^{-1} b_i$.

I currently am running this in MATLAB as a large for loop going from i=1 to i=N, and doing the above operations. For N = 30,000, this takes a while and I was hoping to find some way to speed things up. Since each iteration is independent of the other, I was hoping I could parallelize the for loop. However, I am unfamiliar with parallel programming.

I do not have access to the matlab parallel toolbox, so I cannot simply invoke parfor to parallelize the loop. If it helps, I am familiar with Python+Numpy+Scipy, and also a bit with C/C++ and eager to learn MPI or CUDA or whatever would be useful.

Am I correct in thinking that this for loop could be parallelized for faster performance? Can anyone point me to some resources to get started for a parallel (or, faster) implementation?

Thanks!

• What you need is probably OpenMP with MEX files. Nov 10 '13 at 22:47
• MATLAB is rather slow with small matrices. A simple MEX file (without parallelisation) - Eigen is good for this since it is header only - yields nearly an order of magnitude speed-up in my experience. Nov 11 '13 at 11:51