Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possibility of constructing vectors of matrices with uninitialized dara #73

Open
RiccardoRossi opened this issue Jan 25, 2022 · 1 comment

Comments

@RiccardoRossi
Copy link

RiccardoRossi commented Jan 25, 2022

dear developers,

i skimmed through the tests and i have the impression that vector and matrices are initialized to zero at construction.

in many cases this initialization is unwanted, as assignement will happen at a later stage.

this is crucial for example if one wants to do first touching on the entries of the vector to ensure numa locality (that's one of the reasons for which std::vector cannot be used in HPC code)

is there any way of avoiding it?

@correaa
Copy link

correaa commented May 11, 2022

I agree that zero initialization of arrays is unnecessary in many cases, even if it goes against STL common practice (misguided in my opinion).

This is particularly true for trivially constructible types, doubles, float, ints, and some user defined types.
(std::complex also, except that STL's complex is defective for not being trivially default constructible).

This is very important for performance of numeric software and also to detect use of uninitialized memory with runtime tests (e.g. with Valgrind).

In my library for arrays https://gitlab.com/correaa/boost-multi , which I am currently testing as storage engine for this proposal, zero initialization is optional for trivially constructible types.

If it serves as a example for this proposal, here it is some behavior example

multi::array<double, 2> A({100, 100}); // array of dimension 2 with uninitialized data, this is ok because double is trivial
multi::array<double, 2> B({100, 100}, {}); // array of dimension 2 with initialized data (to zero)
multi::array<double, 2> C({100, 100}, 99.); // array of dimension 2 with initialized data to 99.
multi::array<std::complex<double>, 2> D({100, 100}); // array of dimension 2 with initialized data (to zero) because std::complex is not trivially constructible

Please let me know if I am missing something. I hope this idiom catches on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants