Alaios
2012-Feb-07 08:29 UTC
[R] using mclapply (multi core apply) to do matrix multiplication
Dear all, I am trying to multiply three different matrices and each matrice is of size 16384,16384 the normal %*% multiplciation operator has not finished one day now. As I am running a system with many cores (and it seems that R is using only one of those) I would like to write fast a brief function that converts the typical for loops of a matrix multiplication to a set of lapply sets (mclapply uses the lapply syntax but it applies the work to many cores). If my thinking is correct , in the sense that this will speed up things a lot, I want you to help me covert the first matrix in rows the second in columns and convert those in a format that lapply would like to work with. I would like to thank you in advance for your help Regards Alex [[alternative HTML version deleted]]
Ernest Adrogué
2012-Feb-07 10:02 UTC
[R] using mclapply (multi core apply) to do matrix multiplication
7-02-2012, 00:29 (-0800); Alaios escriu:> Dear all, I am trying to multiply three different matrices and each > matrice is of size 16384,16384 the normal %*% multiplciation > operator has not finished one day now. As I am running a system with > many cores (and it seems that R is using only one of those) I would > like to write fast a brief function that converts the typical for > loops of a matrix multiplication to a set of lapply sets (mclapply > uses the lapply syntax but it applies the work to many cores). > > If my thinking is correct , in the sense that this will speed up > things a lot, I want you to help me covert the first matrix in rows > the second in columns and convert those in? a format that lapply > would like to work with.If I understand correctly, R uses a specialized library called BLAS to do matrix multiplications. I doubt re-implementing the matrix multiplication code at R-level would be any faster. What you can try is replace BLAS with a multicore version of BLAS although it's not easy if you have to compile it yourself. Also, you may try to re-think the problem you're trying to solve. Maybe there's a different approach that is less computation-intensive. -- Cheers, Ernest