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

Copying array of fixed size vectorizable matrices

Tags: None
(comma "," separated)
jbromley
Registered Member
Posts
4
Karma
0
I have two lists of fixed size vectorizable matrices, that I want to frequently copy back and forth between each other (so I can do calculations on a trial modification, and then either accept [copy back] or reject [recopy original] the trial).

I'm looking at how best to do the copying quickly. My first thought was:

Code: Select all
Matrix<double,16,16> mainSet[40], trialSet[40]
...
memcpy(&trialSet, &mainSet, 40*sizeof(Matrix<double,16,16>))

So my questions are:

1. Can I do this? (Or is there additional data in Matrix<double,16,16> that will not tolerate this kind of bitwise copy?)

2. Should I do this? (Or is there no guarantee that it will continue to work with future versions of Eigen?)

3. Is there a faster way? In particular can I force the compiler to use vectorization since I know the data are all aligned?

With respect to question 3, I'm assuming that while it would make use of vectorization the very naive:
Code: Select all
for (int i = 0; i < 40; ++i)
    trialSet[i] = mainSet[i];

would still be much slower than a memcpy? But if people think maybe not I can try and profile it...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes for 1 and 2. Regarding 3, usually memcpy makes use of vectorization, so I also doubt the for loop will be faster. Both solutions should be equivalent, but the only way to be sure is to benchmark.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]