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

parallelized collapse function with openmp in StateVectorLQubit.hpp #986

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### New features since last release

* Add OpenMP support to `collapse` method in the `lightning.qubit` backend.
[(#986)](https://github.com/PennyLaneAI/pennylane-lightning/pull/986)

* Add native N-controlled gates support to `lightning.gpu`'s single-GPU backend.
[(#938)](https://github.com/PennyLaneAI/pennylane-lightning/pull/938)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.40.0-dev4"
__version__ = "0.40.0-dev5"
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,12 @@ class StateVectorLQubit : public StateVectorBase<PrecisionT, Derived> {
// **__**__ for stride 2
// ****____ for stride 4
const std::size_t k = branch ? 0 : 1;
#if defined(_OPENMP)
#pragma omp parallel for collapse(2) default(none) shared(arr, half_section_size, stride, k)
#endif
for (std::size_t idx = 0; idx < half_section_size; idx++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xiaohanzai .
Could you try to fuse these two loops into one to see if the performance can be improved, especially for the stride=1 case?

const std::size_t offset = stride * (k + 2 * idx);
for (std::size_t ids = 0; ids < stride; ids++) {
const std::size_t offset = stride * (k + 2 * idx);
arr[offset + ids] = {0., 0.};
}
}
Expand All @@ -716,6 +719,9 @@ class StateVectorLQubit : public StateVectorBase<PrecisionT, Derived> {
"vector has norm close to zero and can't be normalized");

ComplexT inv_norm = 1. / norm;
#if defined(_OPENMP)
#pragma omp parallel for default(none) shared(arr, inv_norm)
#endif
for (std::size_t k = 0; k < BaseType::getLength(); k++) {
arr[k] *= inv_norm;
}
Expand Down