Question about padding

Issue #63 wontfix
Former user created an issue

Hi,

I'm not sure I understand how padding works for matrices. For vector, it's really simple, there are just a few elements in the end of the vector to make sure it's a multiple of the vector register size.

But for matrices, does that mean that the second dimension is padded ? If it's the case, there are empty elements on every row of the matrix right ?

Thanks

Baptiste

Comments (3)

  1. Klaus Iglberger

    Hi Baptiste!

    Your assumption is correct. In case of a row-major matrix, each row of the matrix contains several additional elements, which guarantee that the beginning of each row is correctly aligned. In case of column-major matrices, each column contains additional elements.

    The downside of this approach is that you cannot expect that elements of two rows lie consecutively in memory. This is why matrices don't have begin() and end() functions, but only begin(size_t) and end(size_t) functions. However, the upside is a significantly increased performance for the majority of algorithms since you can always work with properly aligned memory. Note that there is no compatibility issue with BLAS or LAPACK libraries, since these libraries also expect a parameter for the total number of elements in each row/column (see also the answer to issue #62).

    You can disable padding via the usePadding switch in the <blaze/config/Optimizations.h> header. Then all matrix elements are guaranteed to be contiguous. However, since this has a significant negative performance impact on Blaze this approach is not recommended.

    Since padding is not a bug, but a feature, the ticket is closed as "Won't fix".

    Best regards,

    Klaus!

  2. Former user Account Deleted reporter

    Hi,

    Thank you very much for your prompt answer. This is very clear now.

    Best regards, Baptiste Wicht

  3. Log in to comment