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

Function getLocalMemoryRequired

quest/src/core/memory.cpp:290–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288
289
290size_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
310size_t mem_getLocalQuregMemoryRequired(int numQubits, bool isDensityMatr, int numNodes) {

Tested by

no test coverage detected