MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / cpu_statevec_anyCtrlSwap_subC

Function cpu_statevec_anyCtrlSwap_subC

quest/src/cpu/cpu_subroutines.cpp:346–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344
345template <int NumCtrls>
346void cpu_statevec_anyCtrlSwap_subC(Qureg qureg, vector<int> ctrls, vector<int> ctrlStates, int targ, int targState) {
347
348 assert_numCtrlsMatchesNumCtrlStatesAndTemplateParam(ctrls.size(), ctrlStates.size(), NumCtrls);
349
350 // each control qubit halves the number of iterations, each of which modifies one of the two target qubit states
351 qindex numIts = qureg.numAmpsPerNode / powerOf2(1 + ctrls.size());
352
353 // received amplitudes may begin at an arbitrary offset in the buffer
354 qindex offset = getBufferRecvInd();
355
356 auto sortedQubits = util_getSorted(ctrls, {targ});
357 auto qubitStateMask = util_getBitMask(ctrls, ctrlStates, {targ}, {targState});
358
359 // use template param to compile-time unroll loop in insertBits()
360 SET_VAR_AT_COMPILE_TIME(int, numCtrlBits, NumCtrls, ctrls.size());
361 int numQubitBits = numCtrlBits + 1;
362
363 #pragma omp parallel for if(qureg.isMultithreaded)
364 for (qindex n=0; n<numIts; n++) {
365
366 // i = nth local index where ctrls and targ are in specified states
367 qindex i = insertBitsWithMaskedValues(n, sortedQubits.data(), numQubitBits, qubitStateMask);
368
369 // j = index of nth received amplitude from pair rank in buffer
370 qindex j = n + offset;
371
372 // unpack the continuous sub-buffer among the strided local amplitudes
373 qureg.cpuAmps[i] = qureg.cpuCommBuffer[j];
374 }
375}
376
377
378INSTANTIATE_FUNC_OPTIMISED_FOR_NUM_CTRLS( void, cpu_statevec_anyCtrlSwap_subA, (Qureg qureg, vector<int> ctrls, vector<int> ctrlStates, int targ1, int targ2) )

Callers

nothing calls this directly

Calls 6

powerOf2Function · 0.85
getBufferRecvIndFunction · 0.85
util_getSortedFunction · 0.85
util_getBitMaskFunction · 0.85

Tested by

no test coverage detected