Re: [eigen] Signed or unsigned indexing |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Signed or unsigned indexing*From*: fayard@xxxxxxxxxxxxx*Date*: Sun, 22 Jan 2017 01:01:05 +0100

On 2017-01-21 22:56, Gael Guennebaud wrote:

That's easy to check, I simply measured: EIGEN_DONT_INLINE void foo(MatrixXf &A, MatrixXf &B, Index i, Index j, Index n, Index m) { A.block(i, j, n, m) += B.block(i+1, j+1, n, m); } and got 15% of speed difference between int and ptrdiff_t using either gcc6 or clang3.9.

I have just tested this kind of code on a 32x32 matrix, and the version using 64-bit integers is indeed 25% faster than the version using 32-bit integers with Eigen.

I get exactly the same timings with 32-bit integers and 64-bit integers

integers is 4% faster (see codes below).

compiler optimizations. Therefore, the difference in between 32-bit and 64-bit integers is very Eigen-specific.

in plain C/C++, nobody would index anymore with ints in C.

I measured the conversion of 1000 integers from 'int' or 'unsigned int' to 'long' and observe 25% of speed difference using either clang or gcc (in favour of unsigned int).

might change void f(double* p, long n) { for (int k = 0; k < n; ++k) { p[k] += 1.0; } } to (look at the new type for k) void f(double* p, long n) { for (long k = 0; k < n; ++k) { p[k] += 1.0; } }

inner loop with signed integers.

an array: int index_smallest(float* p, int n) { float small_value = std::numeric_limits<float>::max(); int small_k = -1; for (int k = 0; k < n; ++k) { if (p[k] < small_value) { small_value = p[k]; small_k = k; } } return k; }

use a 64-bit integer :-) Francois PS: Here are the codes used for my benchmark ==== Plain C++ #include <cstddef> //#define INT std::ptrdiff_t #define INT int int main() { const int nb_time = 10000000; const INT n = 32; float* A = new float[n * n]; float* B = new float[n * n]; for (INT j = 0; j < n; ++j) { for (INT i = 0; i < n; ++i) { A[j * n + i] = 0.0f; B[j * n + i] = 0.0f; } } for (int k = 0; k < nb_time; ++k) { for (INT j = 0; j < n; ++j) { for (INT i = 0; i < n; ++i) { A[j * n + i] += B[j * n + i]; } } } return 0; } ==== ==== Eigen //#define EIGEN_DEFAULT_DENSE_INDEX_TYPE std::ptrdiff_t #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int #include <Eigen/Dense> int main() { const int nb_time = 10000000; const int n = 32; Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> A(n, n); Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> B(n, n); for (int j = 0; j < n; ++j) { for (int i = 0; i < n; ++i) { A(i, j) = 0.0f; B(i, j) = 0.0f; } } for (int k = 0; k < nb_time; ++k) { A.block(0, 0, n, n) += B.block(0, 0, n, n); } return 0; } ====

**References**:**[eigen] Signed or unsigned indexing***From:*Henrik Mannerström

**Re: [eigen] Signed or unsigned indexing***From:*Benoit Jacob

**Re: [eigen] Signed or unsigned indexing***From:*Francois Fayard

**Re: [eigen] Signed or unsigned indexing***From:*Mark Borgerding

**Re: [eigen] Signed or unsigned indexing***From:*Martin Beeger

**Re: [eigen] Signed or unsigned indexing***From:*François Fayard

**Re: [eigen] Signed or unsigned indexing***From:*Gael Guennebaud

**Re: [eigen] Signed or unsigned indexing***From:*Francois Fayard

**Re: [eigen] Signed or unsigned indexing***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**[eigen] unsubscribe** - Next by Date:
**[eigen] Head is broken** - Previous by thread:
**Re: [eigen] Signed or unsigned indexing** - Next by thread:
**Re: [eigen] Signed or unsigned indexing**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |