![]() Registered Member ![]()
|
Hi everyone,
I've just heard about Eigen recently and it looks really promising,therefore I decided to used it for our program (a bioinformatics tool) by transforming the performance-critical codes (our program could need a week to compute some datasets) into Eigen's notations. I've spent sometimes thinking about an elegant solution but still cannot come up with any reasonable idea, probably due to lacking of experience with Eigen and linear algebra in general. Here is a snippet of the code inside a function (which is called 10000s times):
The code is relatively straightforward : I have some big arrays, which were already initialized beforehand (in the first for loop). The performance-critical code is the second loop for (ptn = 0; ptn < aln->size(); ptn++), the loop size could be 10000s, depend on the dataset. Inside this loop there is a second innerloop for (cat = 0; cat < ncat; cat++), ncat is usually 4. Until now I am only able to convert code inside this innerloop into Eigen's matrix operations,which is kind of obvious(using 4x4 or 20x20 matrices since nstates is either 4 or 20) I want to also convert the 2 outerloops ( for (cat..) and for(ptn...) ) into Eigen, but still have no clue ! I would be very nice if someone can help me out Thanks |
![]() Registered Member ![]()
|
The code probably looks scary at first, but only the loop for (ptn = 0; ptn < aln->size(); ptn++) is relevant, and what I want to compute in each loop is the value store in the variable lh_ptn and after this loop ends, the values of lh_ptn are summed up in tree_lh.
If you have time, please spend 5 minutes looking through that loop and tell me what options in Eigen do I have ? Thanks |
![]() Registered Member ![]()
|
This is a computation for a maximum likelihood method, right?
I'd say pull the if's out of the loops and you have two loops left, one matrix/matrix (reduced) and one matrix/vector.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
![]() Registered Member ![]()
|
Yes, it is exactly the computation for maximum likelihood. You meant the if (dad_state < nstates) statement right ? I already noticed that it is inefficient and pulled it out in the current code, I didnt want to post the new code here because it is longer, so just ignore the if, just consider the else branch, which is:
I had no problem converting the above code into Eigen matrixs. But this code is inside 2 for loops, which simply kind of sum up all the results computed in the code above. This 2 loops have altogether the size of cat*aln->size(), which is pretty big, cat is usually 4, but aln->size() can be 1000s. What I wanted to ask is, whether it is possible or meaningful if I try to convert these 2 loops into Eigen Matrixs so that they can be vectorize, loop unrolled, etc... or just let it be I hope the compiler is smart enough to vectorize the code ? Thanks |
![]() Registered Member ![]()
|
I'm not sure (you should just try it out), but I feel like it won't buy you much to transform the outer-most loop into matrix operations. As the code is already out of date, I can't tell you specific things, but as I said the code you posted first has a lot of opportunity for classic optimisation.
'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett
'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger |
![]() Registered Member ![]()
|
I think I have managed to come up with a reasonable solution/optimization.
@Andre: What do you mean by classic optimization ? |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]