This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Problem with Matrix<> and omp threads

Tags: None
(comma "," separated)
noir.sender
Registered Member
Posts
6
Karma
0
The code below does not work with threads. Displaying the matrix results in an out of order position (according to the trhread used). Any ideas why? If i remove the #pragma it works as it should be. Are omp threads supported by Eigen?

Code: Select all
         T op1, op2;
         #pragma omp parallel for
            for (int i = 0; i < x.rows(); ++i)
            {
                op1 = x(i);
                for (int j = 0; j < x.rows(); ++j)
                {
                    op2 = x(j);
                    cov(i, j) = _sf *  exp(-0.5 *
                        (( op1 - op2 )  / _sl) *   (( op1 - op2 )  / _sl));
                }
            }
[/quote]

cheers,

noir.sender
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Eigen is completely state-less, so there is absolutely no issue about using eigen in a multi-threaded setting, as long of course as you don't access the same matrix elements simultaneously in multiple threads.

It looks like your code is using the same variables op1 and op2 for all threads, so this is a good starting point to look for a conflict...


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell