I'm wondering what is the best way of calculating the sum of all elements in a matrix in GSL (Gnu scientific library). I don't see any library functions that do this, so will I just need to sum over all the indices myself?
Asked
Active
Viewed 896 times
0
-
It's O(m x n), no matter how you do it. That's as fast as you can go, unless you can use a thread per row and do a map/reduce solution. That's it. – duffymo Dec 08 '15 at 01:35
-
That solves the question. How do I mark this as answered? – theideasmith Dec 08 '15 at 01:37
-
I don't know. Why not answer it yourself and vote it up? – duffymo Dec 08 '15 at 01:40
1 Answers
0
The fastest a solution can get is O(m*n)
, so a simple summing iteration over the matrix is the best solution.

theideasmith
- 2,835
- 2
- 13
- 20
-
If you access the `data` pointer to the elements it can be faster than accessing with two indices. (Still O(m*n)). – alfC Sep 06 '17 at 20:14