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

Function qureg_populateNonHeapFields

quest/src/api/qureg.cpp:38–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38Qureg qureg_populateNonHeapFields(int numQubits, int isDensMatr, int useDistrib, int useGpuAccel, int useMultithread) {
39
40 QuESTEnv env = getQuESTEnv();
41
42 // pre-prepare some struct fields (to avoid circular initialisation)
43 int logNumNodes = (useDistrib)?
44 logBase2(env.numNodes) : 0;
45 qindex logNumAmpsPerNode = (isDensMatr)?
46 (2*numQubits - logNumNodes) :
47 ( numQubits - logNumNodes);
48
49 // prepare output Qureg (avoiding C++20 designated initialiser)
50 Qureg out;
51
52 // bind deployment info
53 out.isMultithreaded = useMultithread;
54 out.isGpuAccelerated = useGpuAccel;
55 out.isDistributed = useDistrib;
56
57 // optionally bind distributed info, noting that in distributed environments,
58 // the non-distributed quregs are duplicated on each node and each believe
59 // they are the root node, with no other nodes existing; this is essential so
60 // that these quregs can agnostically use distributed routines which consult
61 // the rank, but it will interfere with naive root-only printing logic
62 out.rank = (useDistrib)? env.rank : 0;
63 out.numNodes = (useDistrib)? env.numNodes : 1;
64 out.logNumNodes = (useDistrib)? logBase2(env.numNodes) : 0; // duplicated for clarity
65
66 // bind dimensions
67 out.isDensityMatrix = isDensMatr;
68 out.numQubits = numQubits;
69 out.numAmps = (isDensMatr)? powerOf2(2*numQubits) : powerOf2(numQubits);
70 out.logNumAmps = (isDensMatr)? 2*numQubits : numQubits;
71
72 // bind dimensions per node (even if not distributed)
73 out.numAmpsPerNode = powerOf2(logNumAmpsPerNode);
74 out.logNumAmpsPerNode = logNumAmpsPerNode;
75 out.logNumColsPerNode = (isDensMatr)? numQubits - logNumNodes : 0; // used only by density matrices
76
77 // caller will allocate heap memory as necessary
78 out.cpuAmps = nullptr;
79 out.gpuAmps = nullptr;
80 out.cpuCommBuffer = nullptr;
81 out.gpuCommBuffer = nullptr;
82
83 return out;
84}
85
86
87

Calls 3

getQuESTEnvFunction · 0.85
logBase2Function · 0.85
powerOf2Function · 0.85

Tested by

no test coverage detected