Re: [eigen] STL Vectors and Alignment
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] STL Vectors and Alignment
• From: Gabriel <gnuetzi@xxxxxxxxx>
• Date: Wed, 26 Nov 2014 17:39:02 +0100
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=oiCYWVi32WhjzhhkvHiDGG9Z14Pb1D9ohcBnAPWHNUI=; b=Hak60CFDmVEpulW4hj5KRQW30JyQOe5yo5o67ykjdS43K9wMWWAy6DKN+cD4m35hqv /vVQAdoSijIN/t33i6GVWfEax5TwfiVQjLYrJbYOuyczuCjcbh1cuhQqr2fMK53PDggf +IPBvPJKQ4GTjOMPE6Wm92S4K338k+k6TLHhym9vD5UIdMlJW+zqXENNG/qV2EYA3A8M ygXaNoylM4ihfkr13NVgMINqqy1/RC731sezQ2eAJKMXXrAl6rTNUyCkp7HEnKrZiuWe c28LFMk1iDnfaEXEA0Mz6fvhB0OjPH846gq/WE/gqT5apjLkSIvNhoMx3UX9Rn4+TXC9 IwwA==

 Thanks for the answer! Sorry again for my unclear phrasing! Just to be absolutely sure: Lets say we have:     struct A{          Eigen::Vector2d t;     }; If we use A locally:     A a;     a.t   is a.t  aligned on the Stack, (how does alignment work on the stack) If we use A on the heap:     A * a = new A; then as "a" is not aligned , also a.t is not aligned If we use EIGEN_MAKE_ALLOCATOR_NEW inside A , then "a" is aligned , and BUT what happens in this example:     struct B{          A a;     };     struct C{          B b;     };     std::vector<   C  ,   Eigen::aligned_allocator  > vec(1); Is      vec[0].b.a.t      now  aligned in memory? which does NOT result in a segfault if Eigen uses SIMD internally? If we use locally lets say:     C c;      c.b.a.t  do something with t is c.b.a.t  aligned on the Stack? Or on the heap:     C * c = new C; c might not be aligned => c.b  might not be aligned  => c.b.a => might not bealigned  => c.b.a.t might not be aligned  => SEGFAULT for usage of c.b.a.t How do I need to correct the above example such that in the cases above, vector A::t is always aligned to 16bytes? Thanks for the help! Gabriel On 11/26/2014 04:40 PM, Christoph Hertzberg wrote: On 26.11.2014 16:17, Gabriel wrote: So that means if we have a class S with a hierarchy of classes composed By hierarchy of classes, I usually assume inheritance, not composed ones. in each other and the last one uses a fixed-size vectorizable type, for example In your example, I would call `A` the first class/struct (or inner-most to be more specific). Your code would not compile as it is, because `C` needs to know `B` and `B` needs to know `A`. struct C{      B a; }; struct B{      EIGEN_MAKE_ALIGNED_OPERATOR_NEW  // <  IS THIS NEEDED? not really      A a; }; struct A{      EIGEN_MAKE_ALIGNED_OPERATOR_NEW      Eigen::Vector2d a; }; You need the EIGEN_MAKE_ALIGNED_OPERATOR_NEW only in classes which you intend to allocate using new. It will not really hurt, adding it to all other classes as well (only some code is generated, which should be removed during linkage if it is not used). Inheritance will propagate AlignedNew, but composing classes will not. and we want to use S in an std::vector We need  : #include std::vector >; Yes, if S requires alignment, this is what you need to write (for C++03). C++11 makes the #include redundant. Is that correct? Isnt that really cumbersome? hm.... Mostly, that is the fault of C++, because it does not automatically propagate alignment requirements to new and std::allocator. This does not properly work in C++11 yet, either (not sure if by design, or because compilers aren't ready yet). Also cf this bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900 Actually, for many 64bit systems many things work out of the box, because allocation methods align to 16byte by default (again, I'm not entirely sure if that is mandatory, or system specific). Christoph

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