Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 17092ec

Browse files
committed
⚡ improved compute table reset
1 parent df9e633 commit 17092ec

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

include/DDpackage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ namespace dd {
156156
// Three types since different possibilities for complex numbers (caused by caching)
157157
// weights of operands and result are from complex table (e.g., transpose, conjugateTranspose)
158158
std::array<std::array<CTentry1, CTSLOTS>, modeCount> CTable1{};
159+
std::array<std::size_t, modeCount> CT1count{};
159160

160161
// weights of operands are from complex table, weight of result from cache/ZERO (e.g., mult)
161162
std::array<std::array<CTentry2, CTSLOTS>, modeCount> CTable2{};
163+
std::array<std::size_t, modeCount> CT2count{};
162164

163165
// weights of operands and result are from cache/ZERO (e.g., add)
164166
std::array<std::array<CTentry3, CTSLOTS>, modeCount> CTable3{};
167+
std::array<std::size_t, modeCount> CT3count{};
165168

166169
// Toffoli gate table
167170
std::array<TTentry, TTSLOTS> TTable{};

src/DDdebug.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ namespace dd {
218218
<< "\n UniqueTable:"
219219
<< "\n Collisions: " << UTcol
220220
<< "\n Matches: " << UTmatch
221+
<< "\n Looks: " << UTlookups
221222
<< "\n"
222223
<< std::flush;
223224
}

src/DDpackage.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ namespace dd {
673673
table[i].r = r.p;
674674
table[i].rw.r = r.w.r->val;
675675
table[i].rw.i = r.w.i->val;
676+
CT2count.at(mode)++;
676677
} else if (which == ad) {
677678
std::array<CTentry3, CTSLOTS>& table = CTable3.at(mode);
678679
ComplexValue aw{a.w.r->val, a.w.i->val};
@@ -689,7 +690,7 @@ namespace dd {
689690
table[i].rw.r = r.w.r->val;
690691
table[i].rw.i = r.w.i->val;
691692
table[i].which = which;
692-
693+
CT3count.at(mode)++;
693694
} else if (which == conjTransp || which == transp) {
694695
std::array<CTentry1, CTSLOTS>& table = CTable1.at(mode);
695696
const unsigned long i = CThash(a, b, which);
@@ -698,6 +699,7 @@ namespace dd {
698699
table[i].b = b;
699700
table[i].which = which;
700701
table[i].r = r;
702+
CT1count.at(mode)++;
701703
} else {
702704
throw std::runtime_error("Undefined kind in CTinsert: " + std::to_string(which));
703705
}
@@ -1655,22 +1657,27 @@ namespace dd {
16551657
}
16561658

16571659
void Package::clearComputeTables() {
1658-
for (auto& table: CTable1) {
1659-
for (auto& entry: table) {
1660-
entry.r.p = nullptr;
1661-
entry.which = none;
1660+
for (auto i = 0U; i < modeCount; ++i) {
1661+
if (CT1count.at(i) > 0) {
1662+
for (auto& entry: CTable1.at(i)) {
1663+
entry.r.p = nullptr;
1664+
entry.which = none;
1665+
}
1666+
CT1count.at(i) = 0;
16621667
}
1663-
}
1664-
for (auto& table: CTable2) {
1665-
for (auto& entry: table) {
1666-
entry.r = nullptr;
1667-
entry.which = none;
1668+
if (CT2count.at(i) > 0) {
1669+
for (auto& entry: CTable2.at(i)) {
1670+
entry.r = nullptr;
1671+
entry.which = none;
1672+
}
1673+
CT2count.at(i) = 0;
16681674
}
1669-
}
1670-
for (auto& table: CTable3) {
1671-
for (auto& entry: table) {
1672-
entry.r = nullptr;
1673-
entry.which = none;
1675+
if (CT3count.at(i) > 0) {
1676+
for (auto& entry: CTable3.at(i)) {
1677+
entry.r = nullptr;
1678+
entry.which = none;
1679+
}
1680+
CT3count.at(i) = 0;
16741681
}
16751682
}
16761683
}

0 commit comments

Comments
 (0)