diff --git a/CHANGELOG.md b/CHANGELOG.md index eb2d572061..0b62c1b1d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ Removed Fixed ----- +- Bug in handling parallelization in matrix_product_state.cpp (PR \#292) [0.2.3](https://github.com/Qiskit/qiskit-aer/compare/0.2.2...0.2.3) - 2019-07-11 diff --git a/src/simulators/tensor_network/matrix_product_state.cpp b/src/simulators/tensor_network/matrix_product_state.cpp index 1c5d42018c..dcf9203cf8 100644 --- a/src/simulators/tensor_network/matrix_product_state.cpp +++ b/src/simulators/tensor_network/matrix_product_state.cpp @@ -92,8 +92,14 @@ cmatrix_t mul_matrix_by_lambda(const cmatrix_t &mat, if (lambda == rvector_t {1.0}) return mat; cmatrix_t res_mat(mat); uint_t num_rows = mat.GetRows(), num_cols = mat.GetColumns(); - for(uint_t row = 0; row < num_rows; row++) { - for(uint_t col = 0; col < num_cols; col++) { + + #ifdef _WIN32 + #pragma omp parallel for + #else + #pragma omp parallel for collapse(2) + #endif + for(int_t row = 0; row < num_rows; row++) { + for(int_t col = 0; col < num_cols; col++) { res_mat(row, col) = mat(row, col) * lambda[col]; } } @@ -459,9 +465,10 @@ void MPS::full_state_vector(cvector_t& statevector) const { MPS_Tensor mps_vec = state_vec(0, num_qubits_-1); uint_t length = 1ULL << num_qubits_; // length = pow(2, num_qubits_) + statevector.resize(length); #pragma omp parallel for for (int_t i = 0; i < static_cast(length); i++) { - statevector.push_back(mps_vec.get_data(reverse_bits(i, num_qubits_))(0,0)); + statevector[i] = mps_vec.get_data(reverse_bits(i, num_qubits_))(0,0); } #ifdef DEBUG cout << *this; @@ -473,9 +480,10 @@ void MPS::probabilities_vector(rvector_t& probvector) const MPS_Tensor mps_vec = state_vec(0, num_qubits_-1); uint_t length = 1ULL << num_qubits_; // length = pow(2, num_qubits_) complex_t data = 0; + probvector.resize(length); + #pragma omp parallel for for (int_t i = 0; i < static_cast(length); i++) { - data = mps_vec.get_data(reverse_bits(i, num_qubits_))(0,0); - probvector.push_back(std::norm(data)); + probvector[i] = std::norm(mps_vec.get_data(reverse_bits(i, num_qubits_))(0,0)); } }