diff --git a/src/common/qengine.cl b/src/common/qengine.cl index fef455fd9..1135f0b2e 100644 --- a/src/common/qengine.cl +++ b/src/common/qengine.cl @@ -610,6 +610,10 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap } partStateProb[lcv] = partProb; + const real1 prob = partStateProb[lcv]; + if (prob > REAL1_EPSILON) { + partStateAngle[lcv] /= prob; + } } for (bitCapIntOcl lcv = ID; lcv < remainderPower; lcv += Nthreads) { @@ -618,13 +622,6 @@ void kernel decomposeprob(global cmplx* stateVec, constant bitCapIntOcl4* bitCap remainderStateAngle[lcv] /= prob; } } - - for (bitCapIntOcl lcv = ID; lcv < partPower; lcv += Nthreads) { - const real1 prob = partStateProb[lcv]; - if (prob > REAL1_EPSILON) { - partStateAngle[lcv] /= prob; - } - } } void kernel decomposeamp( diff --git a/src/qengine/state.cpp b/src/qengine/state.cpp index fe154d395..bbca14d7c 100644 --- a/src/qengine/state.cpp +++ b/src/qengine/state.cpp @@ -1200,6 +1200,11 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP partStateProb[lcv] += nrm; remainderStateAngle[k] += arg(amp) * nrm; } + + const real1 prob = partStateProb[lcv]; + if (prob > amplitudeFloor) { + partStateAngle[lcv] /= prob; + } }); par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) { const real1 prob = remainderStateProb[lcv]; @@ -1207,12 +1212,6 @@ void QEngineCPU::DecomposeDispose(bitLenInt start, bitLenInt length, QEngineCPUP remainderStateAngle[lcv] /= prob; } }); - par_for(0U, partPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) { - const real1 prob = partStateProb[lcv]; - if (prob > amplitudeFloor) { - partStateAngle[lcv] /= prob; - } - }); } else { par_for(0U, remainderPower, [&](const bitCapIntOcl& lcv, const unsigned& cpu) { bitCapIntOcl j = lcv & pow2MaskOcl(start);