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

Function validateAndCreateCustomFullStateDiagMatr

quest/src/api/matrices.cpp:277–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275
276
277FullStateDiagMatr validateAndCreateCustomFullStateDiagMatr(int numQubits, int useDistrib, int useGpuAccel, int useMultithread, const char* caller) {
278 validate_envIsInit(caller);
279 QuESTEnv env = getQuESTEnv();
280
281 // validate parameters before passing them to autodeployer
282 validate_newFullStateDiagMatrParams(numQubits, useDistrib, useGpuAccel, useMultithread, caller);
283
284 // overwrite all args left as AUTO_FLAG
285 autodep_chooseFullStateDiagMatrDeployment(numQubits, useDistrib, useGpuAccel, useMultithread, env);
286
287 // validation ensures this never overflows
288 qindex numElems = powerOf2(numQubits);
289 qindex numElemsPerNode = numElems / (useDistrib? env.numNodes : 1); // divides evenly
290
291 // prepare output FullStateDiagMatr (avoiding C++20 designated initialiser)
292 FullStateDiagMatr out;
293 out.numQubits = numQubits;
294 out.numElems = numElems;
295
296 // bind deployments, disabling distribution if using a single MPI node
297 out.isGpuAccelerated = useGpuAccel;
298 out.isMultithreaded = useMultithread;
299 out.isDistributed = useDistrib && (env.numNodes > 1);
300 out.numElemsPerNode = numElemsPerNode;
301
302 // allocate (unitialised) flags in the heap so that struct copies are mutable
303 out.isApproxUnitary = util_allocEpsilonSensitiveHeapFlag(); // nullptr if failed
304 out.isApproxHermitian = util_allocEpsilonSensitiveHeapFlag();
305 out.isApproxNonZero = util_allocEpsilonSensitiveHeapFlag();
306 out.isStrictlyNonNegative = cpu_allocHeapFlag(); // nullptr if failed
307 out.wasGpuSynced = cpu_allocHeapFlag();
308
309 // allocate 1D memory (nullptr if failed or not allocated)
310 out.cpuElems = cpu_allocArray(numElemsPerNode);
311 out.gpuElems = (useGpuAccel)? gpu_allocArray(numElemsPerNode) : nullptr;
312
313 validateMatrixAllocs(out, __func__);
314 setInitialHeapFlags(out);
315 return out;
316}
317
318extern "C" FullStateDiagMatr createCustomFullStateDiagMatr(int numQubits, int useDistrib, int useGpuAccel, int useMultithread) {
319

Callers 2

createFullStateDiagMatrFunction · 0.85

Calls 11

validate_envIsInitFunction · 0.85
getQuESTEnvFunction · 0.85
powerOf2Function · 0.85
cpu_allocHeapFlagFunction · 0.85
cpu_allocArrayFunction · 0.85
gpu_allocArrayFunction · 0.85
validateMatrixAllocsFunction · 0.85
setInitialHeapFlagsFunction · 0.85

Tested by

no test coverage detected