| 42 | |
| 43 | |
| 44 | int getMaxNumQubitsWhichCanFitInMemory(bool isDensMatr, int numNodes, bool hasBuffer, bool isSuperOp, qindex memBytesPerNode) { |
| 45 | |
| 46 | // distribution requires communication buffers, doubling costs, halving fittable amps-per-qureg |
| 47 | qindex maxLocalNumAmps = memBytesPerNode / sizeof(qcomp); // floors |
| 48 | if (hasBuffer && numNodes > 1) |
| 49 | maxLocalNumAmps /= 2; // floors |
| 50 | |
| 51 | // density matrices require square more memory, so halve (flooring) the number of qubits |
| 52 | int maxLocalNumQubits = std::floor(std::log2(maxLocalNumAmps)); |
| 53 | if (isDensMatr) |
| 54 | maxLocalNumQubits /= 2; // floors |
| 55 | |
| 56 | // superoperators require square more memory still, so halve (flooring) the number of qubits |
| 57 | if (isSuperOp) |
| 58 | maxLocalNumQubits /= 2; // floors |
| 59 | |
| 60 | // doubling nodes permits 1 additional qubit |
| 61 | int maxGlobalNumQubits = maxLocalNumQubits + logBase2(numNodes); |
| 62 | return maxGlobalNumQubits; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | int mem_getMaxNumQuregQubitsWhichCanFitInMemory(bool isDensityMatrix, int numNodes, qindex memBytesPerNode) { |
no test coverage detected