Topic: Idea about cache optimization with Multi-Vector?


Author: Martin <martinkile86@gmail.com>
Date: Thu, 23 Feb 2017 05:42:57 -0800 (PST)
Raw View
------=_Part_2165_669043193.1487857377885
Content-Type: multipart/alternative;
 boundary="----=_Part_2166_797301510.1487857377886"

------=_Part_2166_797301510.1487857377886
Content-Type: text/plain; charset=UTF-8

Hello, I am new here and this is my first post.

I have an idea about expanding the std::vector<Type> with the feature of
having multiple types, std::vector<Types...>. I might not the first one to
think of this but so please let me know if that is the case.

// Data to be contained
union myUnion
{
struct
{
int x[3];
float y[3];
};
struct
{
int x0, x1, x2;
float y0, y1, y2;
};
};

// Single Vector
std::vector<myUnion> myVector;
myVector.push_back({0, 1, 2, 3.0f, 4.0f, 5.0f });
myVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });
// ... myVector gets populated with many more elements
// Memory layout:
// int[3] | 0, 1, 2
// float[3] | 3.0f, 4.0f, 5.0f
// int[3] | 4, 5, 6
// float[3] | 7.0f, 8.0f, 9.0f
// ...

// Cache lines are both written with x[] and y[] when only X is needed, 50%
waste
for (auto& i : myVector)
i.x = fooGetX(3);

// Cache lines are both written with x[] and y[] when only Y is needed, 50%
waste
for (auto& i : myVector)
i.y = fooGetY(3);

for (auto& i : myVector)
{
i.x0 *= i.y0;
i.x1 *= i.y1;
i.x2 *= i.y2;
}

// Multi-Vector
std::vector<int, int, int, float, float float> myMultiVector;
myMultiVector.push_back({ 0, 1, 2, 3.0f, 4.0f, 5.0f });
myMultiVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });
// ... myMultiVector gets populated with many more elements
// Memory layout:
// int[3] | 0, 1, 2
// int[3] | 4, 5, 6
// float[3] | 3.0f, 4.0f, 5.0f
// float[3] | 7.0f, 8.0f, 9.0f
// ...

// Cache lines written with only x[]
for (auto& [x0<0>, x1<1>, x2<2>] : myMultiVector)
{
x0 = fooGetX(0);
x1 = fooGetX(1);
x2 = fooGetX(2);
}
// Cache lines written with only y[]
for (auto& [y0<3>, y1<4>, y2<5>] : myMultiVector)
{
y0 = fooGetX(0);
y1 = fooGetX(1);
y2 = fooGetX(2);
}

for (auto& [x0<0>, x1<1>, x2<2>, y0<3>, y1<4>, y2<5>] : myMultiVector)
{
x0 *= y0;
x1 *= y1;
x2 *= y2;
}


I was thinking this type of container could be useful in regards to cache
optimization. Please let me know if this horse has been beaten before in
some form or another.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7321f2f1-6d4d-40cf-a767-ba1d170842e0%40isocpp.org.

------=_Part_2166_797301510.1487857377886
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello, I am new here and this is my first post.<div><br></=
div><div>I have an idea about expanding the std::vector&lt;Type&gt; with th=
e feature of having multiple types, std::vector&lt;Types...&gt;. I might no=
t the first one to think of this but so please let me know if that is the c=
ase.</div><div><br></div><div><div><span class=3D"Apple-tab-span" style=3D"=
white-space:pre">  </span>// Data to be contained</div><div><span class=3D"=
Apple-tab-span" style=3D"white-space:pre">  </span>union myUnion</div><div>=
<span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>{</div><d=
iv><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>struc=
t</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </s=
pan>{</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">  =
  </span>int x[3];</div><div><span class=3D"Apple-tab-span" style=3D"white-=
space:pre">    </span>float y[3];</div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">   </span>};</div><div><span class=3D"Apple-tab-s=
pan" style=3D"white-space:pre">   </span>struct</div><div><span class=3D"Ap=
ple-tab-span" style=3D"white-space:pre">   </span>{</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">    </span>int x0, x1, x2;</d=
iv><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">    </span=
>float y0, y1, y2;</div><div><span class=3D"Apple-tab-span" style=3D"white-=
space:pre">   </span>};</div><div><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre">  </span>};</div><div><br></div><div><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre">  </span>// Single Vector</div><div><spa=
n class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>std::vector&l=
t;myUnion&gt; myVector;</div><div><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre">  </span>myVector.push_back({0, 1, 2, 3.0f, 4.0f, 5.0f });<=
/div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span=
>myVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// ... myVector gets=
 populated with many more elements</div><div><span class=3D"Apple-tab-span"=
 style=3D"white-space:pre">  </span>// Memory layout:</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// int[3] | 0, 1, 2<=
/div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span=
>// float[3] | 3.0f, 4.0f, 5.0f</div><div><span class=3D"Apple-tab-span" st=
yle=3D"white-space:pre">  </span>// int[3] | 4, 5, 6</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// float[3] | 7.0f, =
8.0f, 9.0f</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e">  </span>// ...</div><div><br></div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">  </span>// Cache lines are both written with x[]=
 and y[] when only X is needed, 50% waste</div><div><span class=3D"Apple-ta=
b-span" style=3D"white-space:pre">  </span>for (auto&amp; i : myVector)</di=
v><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>i=
..x =3D fooGetX(3);</div><div><br></div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">  </span>// Cache lines are both written with x[]=
 and y[] when only Y is needed, 50% waste</div><div><span class=3D"Apple-ta=
b-span" style=3D"white-space:pre">  </span>for (auto&amp; i : myVector)</di=
v><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>i=
..y =3D fooGetY(3);</div><div><br></div><div><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">  </span>for (auto&amp; i : myVector)</div><div><=
span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>{</div><di=
v><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>i.x0 *=
=3D i.y0;</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre=
">   </span>i.x1 *=3D i.y1;</div><div><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">   </span>i.x2 *=3D i.y2;</div><div><span class=3D"App=
le-tab-span" style=3D"white-space:pre">  </span>}</div><div><br></div><div>=
<span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// Multi-=
Vector</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> =
 </span>std::vector&lt;int, int, int, float, float float&gt; myMultiVector;=
</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </spa=
n>myMultiVector.push_back({ 0, 1, 2, 3.0f, 4.0f, 5.0f });</div><div><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre">  </span>myMultiVector.pu=
sh_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });</div><div><span class=3D"Apple-tab-=
span" style=3D"white-space:pre">  </span>// ... myMultiVector gets populate=
d with many more elements</div><div><span class=3D"Apple-tab-span" style=3D=
"white-space:pre">  </span>// Memory layout:</div><div><span class=3D"Apple=
-tab-span" style=3D"white-space:pre">  </span>// int[3] | 0, 1, 2</div><div=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// int[3=
] | 4, 5, 6</div><div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re">  </span>// float[3] | 3.0f, 4.0f, 5.0f</div><div><span class=3D"Apple-=
tab-span" style=3D"white-space:pre">  </span>// float[3] | 7.0f, 8.0f, 9.0f=
</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </spa=
n>// ...</div><div><br></div><div><span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre">  </span>// Cache lines written with only x[]</div><div><sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>for (auto&am=
p; [x0&lt;0&gt;, x1&lt;1&gt;, x2&lt;2&gt;] : myMultiVector)</div><div><span=
 class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>{</div><div><s=
pan class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>x0 =3D foo=
GetX(0);</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"=
>   </span>x1 =3D fooGetX(1);</div><div><span class=3D"Apple-tab-span" styl=
e=3D"white-space:pre">   </span>x2 =3D fooGetX(2);</div><div><span class=3D=
"Apple-tab-span" style=3D"white-space:pre">  </span>}</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">   </span></div><div><span cl=
ass=3D"Apple-tab-span" style=3D"white-space:pre">  </span>// Cache lines wr=
itten with only y[]</div><div><span class=3D"Apple-tab-span" style=3D"white=
-space:pre">  </span>for (auto&amp; [y0&lt;3&gt;, y1&lt;4&gt;, y2&lt;5&gt;]=
 : myMultiVector)</div><div><span class=3D"Apple-tab-span" style=3D"white-s=
pace:pre">  </span>{</div><div><span class=3D"Apple-tab-span" style=3D"whit=
e-space:pre">   </span>y0 =3D fooGetX(0);</div><div><span class=3D"Apple-ta=
b-span" style=3D"white-space:pre">   </span>y1 =3D fooGetX(1);</div><div><s=
pan class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>y2 =3D foo=
GetX(2);</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"=
>  </span>}</div><div><br></div><div><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">  </span>for (auto&amp; [x0&lt;0&gt;, x1&lt;1&gt;, x2&=
lt;2&gt;, y0&lt;3&gt;, y1&lt;4&gt;, y2&lt;5&gt;] : myMultiVector)</div><div=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">  </span>{</div><=
div><span class=3D"Apple-tab-span" style=3D"white-space:pre">   </span>x0 *=
=3D y0;</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
   </span>x1 *=3D y1;</div><div><span class=3D"Apple-tab-span" style=3D"whi=
te-space:pre">   </span>x2 *=3D y2;</div><div><span class=3D"Apple-tab-span=
" style=3D"white-space:pre">  </span>}</div></div><div><br></div><div><br><=
/div><div>I was thinking this type of container could be useful in regards =
to cache optimization. Please let me know if this horse has been beaten bef=
ore in some form or another.</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7321f2f1-6d4d-40cf-a767-ba1d170842e0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7321f2f1-6d4d-40cf-a767-ba1d170842e0=
%40isocpp.org</a>.<br />

------=_Part_2166_797301510.1487857377886--

------=_Part_2165_669043193.1487857377885--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Thu, 23 Feb 2017 10:01:26 -0800
Raw View
On quinta-feira, 23 de fevereiro de 2017 05:42:57 PST Martin wrote:
> Hello, I am new here and this is my first post.
>
> I have an idea about expanding the std::vector<Type> with the feature of
> having multiple types, std::vector<Types...>. I might not the first one to
> think of this but so please let me know if that is the case.

No go. std::vector already has a meaning for the second parameter (the
allocator).

You need to propose a different container.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1682271.KRNrqhjUmh%40tjmaciei-mobl1.

.


Author: Martin <martinkile86@gmail.com>
Date: Thu, 23 Feb 2017 11:55:43 -0800 (PST)
Raw View
------=_Part_544_410127369.1487879744069
Content-Type: multipart/alternative;
 boundary="----=_Part_545_885982591.1487879744069"

------=_Part_545_885982591.1487879744069
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Sure, but that would only apply when the second template parameter is=20
a std::pmr::polymorphic_allocator right?
So in order to use std::vector<> for this purpose a special case when the=
=20
second parameter is std::pmr::polymorphic_allocator it shall be treated as=
=20
before, else it is a multivector when declared with multiple parameters.

Otherwise the name *std::multivector<Types...>* could be taken.

> A multivector is a container using Column Major access, whereas a normal=
=20
> vector is Row Major access.
> A multivector is an array of vectors where all internal vectors have the=
=20
> same size and capacity, but can be of different types and are separately=
=20
> allocated.
> Each call to a multivector member function such as push_back and pop_back=
=20
> will be translated to every private vector for each type.
> A multivector allow a Range-based for loop to specify access on a=20
> selective templated parameter basis


Other than naming, is what I presented interesting or new?


torsdag 23. februar 2017 19.01.37 UTC+1 skrev Thiago Macieira f=C3=B8lgende=
:
>
> On quinta-feira, 23 de fevereiro de 2017 05:42:57 PST Martin wrote:=20
> > Hello, I am new here and this is my first post.=20
> >=20
> > I have an idea about expanding the std::vector<Type> with the feature o=
f=20
> > having multiple types, std::vector<Types...>. I might not the first one=
=20
> to=20
> > think of this but so please let me know if that is the case.=20
>
> No go. std::vector already has a meaning for the second parameter (the=20
> allocator).=20
>
> You need to propose a different container.=20
>
> --=20
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org=20
>    Software Architect - Intel Open Source Technology Center=20
>
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/a29fec7b-2cb0-4d76-816f-ddaa38b2fb6b%40isocpp.or=
g.

------=_Part_545_885982591.1487879744069
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sure, but that would only apply when the second template p=
arameter is a=C2=A0std::pmr::polymorphic_allocator right?<div>So in order t=
o use std::vector&lt;&gt; for this purpose a special case when the second p=
arameter is std::pmr::polymorphic_allocator it shall be treated as before, =
else it is a multivector when declared with multiple parameters.</div><div>=
<br></div><div>Otherwise the name <i>std::multivector&lt;Types...&gt;</i> c=
ould be taken.</div><blockquote class=3D"gmail_quote" style=3D"margin: 0px =
0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex=
;">A multivector is a container using Column Major access, whereas a normal=
 vector is Row Major access.<br>A multivector is an array of vectors where =
all internal vectors have the same size and capacity, but can be of differe=
nt types and are separately allocated.<br>Each call to a multivector member=
 function such as push_back and pop_back will be translated to every privat=
e vector for each type.<br>A multivector allow a Range-based for loop to sp=
ecify access on a selective templated parameter basis</blockquote><div><br>=
</div><div>Other than naming, is what I presented interesting or new?</div>=
<div><br><br>torsdag 23. februar 2017 19.01.37 UTC+1 skrev Thiago Macieira =
f=C3=B8lgende:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On quinta-feira,=
 23 de fevereiro de 2017 05:42:57 PST Martin wrote:
<br>&gt; Hello, I am new here and this is my first post.
<br>&gt;=20
<br>&gt; I have an idea about expanding the std::vector&lt;Type&gt; with th=
e feature of
<br>&gt; having multiple types, std::vector&lt;Types...&gt;. I might not th=
e first one to
<br>&gt; think of this but so please let me know if that is the case.
<br>
<br>No go. std::vector already has a meaning for the second parameter (the=
=20
<br>allocator).=20
<br>
<br>You need to propose a different container.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a29fec7b-2cb0-4d76-816f-ddaa38b2fb6b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a29fec7b-2cb0-4d76-816f-ddaa38b2fb6b=
%40isocpp.org</a>.<br />

------=_Part_545_885982591.1487879744069--

------=_Part_544_410127369.1487879744069--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 23 Feb 2017 22:12:34 +0200
Raw View
On 23 February 2017 at 21:55, Martin <martinkile86@gmail.com> wrote:
> Sure, but that would only apply when the second template parameter is a
> std::pmr::polymorphic_allocator right?

No, that's not right.

> So in order to use std::vector<> for this purpose a special case when the
> second parameter is std::pmr::polymorphic_allocator it shall be treated as
> before, else it is a multivector when declared with multiple parameters.

That breaks a fair amount of existing code, and is thus a non-starter.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUbY9uGJa%3DLdEDSRGyicndxobW1x-8yMDcPyPk3xPvWZiQ%40mail.gmail.com.

.


Author: Martin <martinkile86@gmail.com>
Date: Thu, 23 Feb 2017 12:23:08 -0800 (PST)
Raw View
------=_Part_2469_306819051.1487881388689
Content-Type: multipart/alternative;
 boundary="----=_Part_2470_2035160580.1487881388690"

------=_Part_2470_2035160580.1487881388690
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I see, what if the first parameter is a typelist and the second paramter is=
=20
a allocatorlist?=20
std:vector<<int, int, int, float, float,=20
float>,<allocator0,allocator1,allocator2,allocator3,allocator4,allocator5>>=
,
or possibly std:vector<[int, int, int, float, float,=20
float],[allocator0,allocator1,allocator2,allocator3,allocator4,allocator5]>=
,=20
would that work?



torsdag 23. februar 2017 21.12.36 UTC+1 skrev Ville Voutilainen f=C3=B8lgen=
de:
>
> On 23 February 2017 at 21:55, Martin <martin...@gmail.com <javascript:>>=
=20
> wrote:=20
> > Sure, but that would only apply when the second template parameter is a=
=20
> > std::pmr::polymorphic_allocator right?=20
>
> No, that's not right.=20
>
> > So in order to use std::vector<> for this purpose a special case when=
=20
> the=20
> > second parameter is std::pmr::polymorphic_allocator it shall be treated=
=20
> as=20
> > before, else it is a multivector when declared with multiple parameters=
..=20
>
> That breaks a fair amount of existing code, and is thus a non-starter.=20
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/fddc665b-fb8b-46bf-85d9-659f3b274dda%40isocpp.or=
g.

------=_Part_2470_2035160580.1487881388690
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I see, what if the first parameter is a typelist and the s=
econd paramter is a allocatorlist?=C2=A0<div>std:vector&lt;&lt;int, int, in=
t, float, float, float&gt;,&lt;allocator0,allocator1,allocator2,allocator3,=
allocator4,allocator5&gt;&gt;,</div><div>or possibly std:vector&lt;[int, in=
t, int, float, float, float],[allocator0,allocator1,allocator2,allocator3,a=
llocator4,allocator5]&gt;, would that work?</div><div><br></div><div><br><b=
r>torsdag 23. februar 2017 21.12.36 UTC+1 skrev Ville Voutilainen f=C3=B8lg=
ende:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;">On 23 February 2017 at 21=
:55, Martin &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-ma=
ilto=3D"5_9KF0jNAQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;java=
script:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;ret=
urn true;">martin...@gmail.com</a>&gt; wrote:
<br>&gt; Sure, but that would only apply when the second template parameter=
 is a
<br>&gt; std::pmr::polymorphic_<wbr>allocator right?
<br>
<br>No, that&#39;s not right.
<br>
<br>&gt; So in order to use std::vector&lt;&gt; for this purpose a special =
case when the
<br>&gt; second parameter is std::pmr::polymorphic_<wbr>allocator it shall =
be treated as
<br>&gt; before, else it is a multivector when declared with multiple param=
eters.
<br>
<br>That breaks a fair amount of existing code, and is thus a non-starter.
<br></blockquote></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/fddc665b-fb8b-46bf-85d9-659f3b274dda%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fddc665b-fb8b-46bf-85d9-659f3b274dda=
%40isocpp.org</a>.<br />

------=_Part_2470_2035160580.1487881388690--

------=_Part_2469_306819051.1487881388689--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 23 Feb 2017 22:25:53 +0200
Raw View
On 23 February 2017 at 22:23, Martin <martinkile86@gmail.com> wrote:
> I see, what if the first parameter is a typelist and the second paramter is
> a allocatorlist?
> std:vector<<int, int, int, float, float,
> float>,<allocator0,allocator1,allocator2,allocator3,allocator4,allocator5>>,
> or possibly std:vector<[int, int, int, float, float,
> float],[allocator0,allocator1,allocator2,allocator3,allocator4,allocator5]>,
> would that work?

Then we get to the problem that it changes the meaning of vector. You
need a new container.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUb8yW8j0k-CVGEZX61CAqZLc2oV55aJu5uiiV0Wn0V_8A%40mail.gmail.com.

.


Author: Martin <martinkile86@gmail.com>
Date: Fri, 24 Feb 2017 02:40:16 -0800 (PST)
Raw View
------=_Part_130_268340698.1487932816595
Content-Type: multipart/alternative;
 boundary="----=_Part_131_862772918.1487932816595"

------=_Part_131_862772918.1487932816595
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I wrote an incomplete simple implementation, unfortunately my template=20
programming skills are lacking:

template<typename First, typename... Rest>
class multivector
{
public:
multivector() {}
~multivector() {}

template<typename Arg, typename... Args>
void push_back(Arg&& arg, Args&&... args)
{
std::get<sizeof...(Rest)-sizeof...(Args)>(m_tuple).push_back(arg);
push_back(args...);
}
private:
void push_back(){}
std::tuple<std::vector<First>, std::vector<Rest>...> m_tuple;
};


torsdag 23. februar 2017 14.42.58 UTC+1 skrev Martin f=C3=B8lgende:
>
> Hello, I am new here and this is my first post.
>
> I have an idea about expanding the std::vector<Type> with the feature of=
=20
> having multiple types, std::vector<Types...>. I might not the first one t=
o=20
> think of this but so please let me know if that is the case.
>
> // Data to be contained
> union myUnion
> {
> struct
> {
> int x[3];
> float y[3];
> };
> struct
> {
> int x0, x1, x2;
> float y0, y1, y2;
> };
> };
>
> // Single Vector
> std::vector<myUnion> myVector;
> myVector.push_back({0, 1, 2, 3.0f, 4.0f, 5.0f });
> myVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });
> // ... myVector gets populated with many more elements
> // Memory layout:
> // int[3] | 0, 1, 2
> // float[3] | 3.0f, 4.0f, 5.0f
> // int[3] | 4, 5, 6
> // float[3] | 7.0f, 8.0f, 9.0f
> // ...
>
> // Cache lines are both written with x[] and y[] when only X is needed,=
=20
> 50% waste
> for (auto& i : myVector)
> i.x =3D fooGetX(3);
>
> // Cache lines are both written with x[] and y[] when only Y is needed,=
=20
> 50% waste
> for (auto& i : myVector)
> i.y =3D fooGetY(3);
>
> for (auto& i : myVector)
> {
> i.x0 *=3D i.y0;
> i.x1 *=3D i.y1;
> i.x2 *=3D i.y2;
> }
>
> // Multi-Vector
> std::vector<int, int, int, float, float float> myMultiVector;
> myMultiVector.push_back({ 0, 1, 2, 3.0f, 4.0f, 5.0f });
> myMultiVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });
> // ... myMultiVector gets populated with many more elements
> // Memory layout:
> // int[3] | 0, 1, 2
> // int[3] | 4, 5, 6
> // float[3] | 3.0f, 4.0f, 5.0f
> // float[3] | 7.0f, 8.0f, 9.0f
> // ...
>
> // Cache lines written with only x[]
> for (auto& [x0<0>, x1<1>, x2<2>] : myMultiVector)
> {
> x0 =3D fooGetX(0);
> x1 =3D fooGetX(1);
> x2 =3D fooGetX(2);
> }
> // Cache lines written with only y[]
> for (auto& [y0<3>, y1<4>, y2<5>] : myMultiVector)
> {
> y0 =3D fooGetX(0);
> y1 =3D fooGetX(1);
> y2 =3D fooGetX(2);
> }
>
> for (auto& [x0<0>, x1<1>, x2<2>, y0<3>, y1<4>, y2<5>] : myMultiVector)
> {
> x0 *=3D y0;
> x1 *=3D y1;
> x2 *=3D y2;
> }
>
>
> I was thinking this type of container could be useful in regards to cache=
=20
> optimization. Please let me know if this horse has been beaten before in=
=20
> some form or another.
>

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/4a104ee0-adb0-414a-bde6-f19399dcfe83%40isocpp.or=
g.

------=_Part_131_862772918.1487932816595
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I wrote an incomplete simple implementation, unfortunately=
 my template programming skills are lacking:<div><br></div><div><div>templa=
te&lt;typename First, typename... Rest&gt;</div><div>class multivector</div=
><div>{</div><div>public:</div><div><span class=3D"Apple-tab-span" style=3D=
"white-space:pre"> </span>multivector() {}</div><div><span class=3D"Apple-t=
ab-span" style=3D"white-space:pre"> </span>~multivector() {}</div><div><br>=
</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span=
>template&lt;typename Arg, typename... Args&gt;</div><div><span class=3D"Ap=
ple-tab-span" style=3D"white-space:pre"> </span>void push_back(Arg&amp;&amp=
; arg, Args&amp;&amp;... args)</div><div><span class=3D"Apple-tab-span" sty=
le=3D"white-space:pre"> </span>{</div><div><span class=3D"Apple-tab-span" s=
tyle=3D"white-space:pre">  </span>std::get&lt;sizeof...(Rest)-sizeof...(Arg=
s)&gt;(m_tuple).push_back(arg);</div><div><span class=3D"Apple-tab-span" st=
yle=3D"white-space:pre">  </span>push_back(args...);</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre"> </span>}</div><div>private:<=
/div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre"> </span>=
void push_back(){}</div><div><span class=3D"Apple-tab-span" style=3D"white-=
space:pre"> </span>std::tuple&lt;std::vector&lt;First&gt;, std::vector&lt;R=
est&gt;...&gt; m_tuple;</div><div>};</div></div><div><br><br>torsdag 23. fe=
bruar 2017 14.42.58 UTC+1 skrev Martin f=C3=B8lgende:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;"><div dir=3D"ltr">Hello, I am new here and this is my=
 first post.<div><br></div><div>I have an idea about expanding the std::vec=
tor&lt;Type&gt; with the feature of having multiple types, std::vector&lt;T=
ypes...&gt;. I might not the first one to think of this but so please let m=
e know if that is the case.</div><div><br></div><div><div><span style=3D"wh=
ite-space:pre">  </span>// Data to be contained</div><div><span style=3D"wh=
ite-space:pre">  </span>union myUnion</div><div><span style=3D"white-space:=
pre">  </span>{</div><div><span style=3D"white-space:pre">   </span>struct<=
/div><div><span style=3D"white-space:pre">   </span>{</div><div><span style=
=3D"white-space:pre">    </span>int x[3];</div><div><span style=3D"white-sp=
ace:pre">    </span>float y[3];</div><div><span style=3D"white-space:pre"> =
  </span>};</div><div><span style=3D"white-space:pre">   </span>struct</div=
><div><span style=3D"white-space:pre">   </span>{</div><div><span style=3D"=
white-space:pre">    </span>int x0, x1, x2;</div><div><span style=3D"white-=
space:pre">    </span>float y0, y1, y2;</div><div><span style=3D"white-spac=
e:pre">   </span>};</div><div><span style=3D"white-space:pre">  </span>};</=
div><div><br></div><div><span style=3D"white-space:pre">  </span>// Single =
Vector</div><div><span style=3D"white-space:pre">  </span>std::vector&lt;my=
Union&gt; myVector;</div><div><span style=3D"white-space:pre">  </span>myVe=
ctor.push_back({0, 1, 2, 3.0f, 4.0f, 5.0f });</div><div><span style=3D"whit=
e-space:pre">  </span>myVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.0f });</d=
iv><div><span style=3D"white-space:pre">  </span>// ... myVector gets popul=
ated with many more elements</div><div><span style=3D"white-space:pre">  </=
span>// Memory layout:</div><div><span style=3D"white-space:pre">  </span>/=
/ int[3] | 0, 1, 2</div><div><span style=3D"white-space:pre">  </span>// fl=
oat[3] | 3.0f, 4.0f, 5.0f</div><div><span style=3D"white-space:pre">  </spa=
n>// int[3] | 4, 5, 6</div><div><span style=3D"white-space:pre">  </span>//=
 float[3] | 7.0f, 8.0f, 9.0f</div><div><span style=3D"white-space:pre">  </=
span>// ...</div><div><br></div><div><span style=3D"white-space:pre">  </sp=
an>// Cache lines are both written with x[] and y[] when only X is needed, =
50% waste</div><div><span style=3D"white-space:pre">  </span>for (auto&amp;=
 i : myVector)</div><div><span style=3D"white-space:pre">   </span>i.x =3D =
fooGetX(3);</div><div><br></div><div><span style=3D"white-space:pre">  </sp=
an>// Cache lines are both written with x[] and y[] when only Y is needed, =
50% waste</div><div><span style=3D"white-space:pre">  </span>for (auto&amp;=
 i : myVector)</div><div><span style=3D"white-space:pre">   </span>i.y =3D =
fooGetY(3);</div><div><br></div><div><span style=3D"white-space:pre">  </sp=
an>for (auto&amp; i : myVector)</div><div><span style=3D"white-space:pre"> =
 </span>{</div><div><span style=3D"white-space:pre">   </span>i.x0 *=3D i.y=
0;</div><div><span style=3D"white-space:pre">   </span>i.x1 *=3D i.y1;</div=
><div><span style=3D"white-space:pre">   </span>i.x2 *=3D i.y2;</div><div><=
span style=3D"white-space:pre">  </span>}</div><div><br></div><div><span st=
yle=3D"white-space:pre">  </span>// Multi-Vector</div><div><span style=3D"w=
hite-space:pre">  </span>std::vector&lt;int, int, int, float, float float&g=
t; myMultiVector;</div><div><span style=3D"white-space:pre">  </span>myMult=
iVector.push_back({ 0, 1, 2, 3.0f, 4.0f, 5.0f });</div><div><span style=3D"=
white-space:pre">  </span>myMultiVector.push_back({ 4, 5, 6, 7.0f, 8.0f, 9.=
0f });</div><div><span style=3D"white-space:pre">  </span>// ... myMultiVec=
tor gets populated with many more elements</div><div><span style=3D"white-s=
pace:pre">  </span>// Memory layout:</div><div><span style=3D"white-space:p=
re">  </span>// int[3] | 0, 1, 2</div><div><span style=3D"white-space:pre">=
  </span>// int[3] | 4, 5, 6</div><div><span style=3D"white-space:pre">  </=
span>// float[3] | 3.0f, 4.0f, 5.0f</div><div><span style=3D"white-space:pr=
e">  </span>// float[3] | 7.0f, 8.0f, 9.0f</div><div><span style=3D"white-s=
pace:pre">  </span>// ...</div><div><br></div><div><span style=3D"white-spa=
ce:pre">  </span>// Cache lines written with only x[]</div><div><span style=
=3D"white-space:pre">  </span>for (auto&amp; [x0&lt;0&gt;, x1&lt;1&gt;, x2&=
lt;2&gt;] : myMultiVector)</div><div><span style=3D"white-space:pre">  </sp=
an>{</div><div><span style=3D"white-space:pre">   </span>x0 =3D fooGetX(0);=
</div><div><span style=3D"white-space:pre">   </span>x1 =3D fooGetX(1);</di=
v><div><span style=3D"white-space:pre">   </span>x2 =3D fooGetX(2);</div><d=
iv><span style=3D"white-space:pre">  </span>}</div><div><span style=3D"whit=
e-space:pre">   </span></div><div><span style=3D"white-space:pre">  </span>=
// Cache lines written with only y[]</div><div><span style=3D"white-space:p=
re">  </span>for (auto&amp; [y0&lt;3&gt;, y1&lt;4&gt;, y2&lt;5&gt;] : myMul=
tiVector)</div><div><span style=3D"white-space:pre">  </span>{</div><div><s=
pan style=3D"white-space:pre">   </span>y0 =3D fooGetX(0);</div><div><span =
style=3D"white-space:pre">   </span>y1 =3D fooGetX(1);</div><div><span styl=
e=3D"white-space:pre">   </span>y2 =3D fooGetX(2);</div><div><span style=3D=
"white-space:pre">  </span>}</div><div><br></div><div><span style=3D"white-=
space:pre">  </span>for (auto&amp; [x0&lt;0&gt;, x1&lt;1&gt;, x2&lt;2&gt;, =
y0&lt;3&gt;, y1&lt;4&gt;, y2&lt;5&gt;] : myMultiVector)</div><div><span sty=
le=3D"white-space:pre">  </span>{</div><div><span style=3D"white-space:pre"=
>   </span>x0 *=3D y0;</div><div><span style=3D"white-space:pre">   </span>=
x1 *=3D y1;</div><div><span style=3D"white-space:pre">   </span>x2 *=3D y2;=
</div><div><span style=3D"white-space:pre">  </span>}</div></div><div><br><=
/div><div><br></div><div>I was thinking this type of container could be use=
ful in regards to cache optimization. Please let me know if this horse has =
been beaten before in some form or another.</div></div></blockquote></div><=
/div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4a104ee0-adb0-414a-bde6-f19399dcfe83%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4a104ee0-adb0-414a-bde6-f19399dcfe83=
%40isocpp.org</a>.<br />

------=_Part_131_862772918.1487932816595--

------=_Part_130_268340698.1487932816595--

.