-
Notifications
You must be signed in to change notification settings - Fork 407
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
Kokkos::complex<T> behaves slightly differently from std::complex<T> #1011
Comments
Hi @bjoo ! Would you like to submit a pull request (against Kokkos' develop branch) in order to fix this? Also, is the requested feature standard with C++11? Does it work with GCC 4.8.4? |
Here is a relevant page of C++ documentation with annotations about how things change over standards. |
Just added these functions, tested them, and got them approved into Kokkos develop. Record time! |
Thank you very much Dan. I will change my code to use these new versions. As I mentioned, to
be honest, I preferred the existing Kokkos::complex<> implementation. Writing
f.real() += y.imag();
seems more natural to me than the new std::complex way of :
f.real( f.real() + y.imag() );
which looses the feeling of ‘+=‘-ness.
Regarding your earlier other point: I do currently rely on having real and imaginary part be contiguous
especially in the case of arrays, e.g. for the following:
Kokkos::complex<T> array[N];
const T* storage = reinterpret_cast<const T*>(&array[0]); // ‘storage’ should be 2*N values of T
Right now this appears to work (at least with Kokkos::complex<>) and this is
useful at least on CPUs with vectors, since it turns out that the compilers I’ve had experiences with
are not super great at vectorizing over complex numbers and very simple (but nonportable) intrinsics
specializations can help here (3-4x speed improvement and not a lot of extra work, so worth not
leaving on the table — tho it is nonportable).
Ultimately I will need Kokkos::complex<> also for GPUs. The only reason I wanted to swap in std::complex
was to see if the compiler recognized it and did a better job vectorizing it than it did with Kokkos::complex.
(BTW: It didn’t, the code with Kokkos::complex<> was actually a little faster)
Thanks again and best wishes,
B
… On Aug 2, 2017, at 7:58 AM, Dan Ibanez ***@***.***> wrote:
Just added these functions, tested them, and got them approved into Kokkos develop. Record time!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
--------------------------------------------------------------------------------------
Dr Balint Joo High Performance Computational Scientist
Jefferson Lab
12000 Jefferson Ave, Suite 3, MS 12B2, Room F217,
Newport News, VA 23606, USA
Tel: +1-757-269-5339, Fax: +1-757-269-5427
email: bjoo@jlab.org
-------------------------------------------------------------------------------------
|
@bjoo If you're worried about vectorization on CPUs, you might like to try the built-in C99 types |
Just came accross this issue today. In some cases I want to set the real and imaginary parts of a Kokkos::complex separately. This works in the intuitive way e.g.
Kokkos::complex f;
f.real() = 3.0;
f.imag() = 4.0;
However, when I tried to switch over to std::complex this no longer worked. Apparently
now the only way to do this is:
std::complex f;
f.real(3.0);
f.imag(4.0);
When I tried this with Kokkos::complex it didn't work:
(here MG::MyComplex is aliased to Kokkos::Complex using using)
Ultimately this may not matter as folks should use Kokkos::complex, but it may trip up users migrating form std::complex . For what its worth, I prefer the Kokkos version as I can do things like
The text was updated successfully, but these errors were encountered: