| 288 | |
| 289 | |
| 290 | size_t getLocalMemoryRequired(int numQubits, int numNodes, bool isDenseMatrix, bool hasBuffers) { |
| 291 | |
| 292 | // assert no-overflow precondition |
| 293 | if (numQubits > getMaxNumQubitsBeforeGlobalMemSizeofOverflow(isDenseMatrix, numNodes, hasBuffers, false)) // isSuperop=false |
| 294 | error_memSizeQueriedButWouldOverflow(); |
| 295 | |
| 296 | // no risk of overflow; we have already validated numAmpsTotal fits in qindex |
| 297 | qindex numAmpsTotal = (isDenseMatrix)? powerOf2(2*numQubits) : powerOf2(numQubits); |
| 298 | qindex numAmpsPerNode = numAmpsTotal / numNodes; // divides evenly |
| 299 | |
| 300 | // communication buffers double costs |
| 301 | if (hasBuffers && numNodes > 1) |
| 302 | numAmpsPerNode *= 2; |
| 303 | |
| 304 | // beware that we must cast to a size_t (which can be greater |
| 305 | // than qindex) BEFORE multiplying, to avoid overflows |
| 306 | return static_cast<size_t>(numAmpsPerNode) * sizeof(qcomp); |
| 307 | } |
| 308 | |
| 309 | |
| 310 | size_t mem_getLocalQuregMemoryRequired(int numQubits, bool isDensityMatr, int numNodes) { |
no test coverage detected