Skip to content

Commit eee1a1e

Browse files
committed
avoid readRepresentativesLookupVectorFromFiles_par() container realloc
1 parent 88aafac commit eee1a1e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

nortmann/DlProofEnumerator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool DlProofEnumerator::readRepresentativesLookupVectorFromFiles_seq(vector<vect
9797
return true;
9898
}
9999

100-
bool DlProofEnumerator::readRepresentativesLookupVectorFromFiles_par(vector<vector<string>>& allRepresentativesLookup, vector<vector<string>>* optOut_allConclusionsLookup, bool debug, unsigned concurrencyCount, const string& filePrefix, const string& filePostfix, bool initFresh) {
100+
bool DlProofEnumerator::readRepresentativesLookupVectorFromFiles_par(vector<vector<string>>& allRepresentativesLookup, vector<vector<string>>* optOut_allConclusionsLookup, bool debug, unsigned concurrencyCount, const string& filePrefix, const string& filePostfix, bool initFresh, size_t containerReserve) {
101101
if (concurrencyCount < 2)
102102
return readRepresentativesLookupVectorFromFiles_seq(allRepresentativesLookup, optOut_allConclusionsLookup, debug, filePrefix, filePostfix, initFresh); // system cannot execute threads concurrently
103103
chrono::time_point<chrono::steady_clock> startTime;
@@ -116,6 +116,9 @@ bool DlProofEnumerator::readRepresentativesLookupVectorFromFiles_par(vector<vect
116116
vector<thread> threads;
117117
unsigned t = 0;
118118
bool abortAll = false;
119+
allRepresentativesLookup.reserve(containerReserve); // ensure that no container reallocations happen during concurrent access, since they would result in data races
120+
if (optOut_allConclusionsLookup)
121+
optOut_allConclusionsLookup->reserve(containerReserve);
119122
for (uint32_t wordLengthLimit = allRepresentativesLookup.size() + 1; true; wordLengthLimit += 2) { // look for files containing D-proofs, starting from built-in limit + 2
120123
const string file = filePrefix + to_string(wordLengthLimit) + filePostfix;
121124
if (filesystem::exists(file)) { // load

nortmann/DlProofEnumerator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct DlProofEnumerator {
3030
static const std::vector<const std::vector<std::string>*>& builtinConclusions();
3131
static std::vector<std::vector<std::string>> composeToLookupVector(const std::vector<const std::vector<std::string>*>& all);
3232
static bool readRepresentativesLookupVectorFromFiles_seq(std::vector<std::vector<std::string>>& allRepresentativesLookup, std::vector<std::vector<std::string>>* optOut_allConclusionsLookup, bool debug = false, const std::string& filePrefix = "data/dProofs", const std::string& filePostfix = ".txt", bool initFresh = true);
33-
static bool readRepresentativesLookupVectorFromFiles_par(std::vector<std::vector<std::string>>& allRepresentativesLookup, std::vector<std::vector<std::string>>* optOut_allConclusionsLookup, bool debug = false, unsigned concurrencyCount = std::thread::hardware_concurrency(), const std::string& filePrefix = "data/dProofs", const std::string& filePostfix = ".txt", bool initFresh = true);
33+
static bool readRepresentativesLookupVectorFromFiles_par(std::vector<std::vector<std::string>>& allRepresentativesLookup, std::vector<std::vector<std::string>>* optOut_allConclusionsLookup, bool debug = false, unsigned concurrencyCount = std::thread::hardware_concurrency(), const std::string& filePrefix = "data/dProofs", const std::string& filePostfix = ".txt", bool initFresh = true, std::size_t containerReserve = 100);
3434
static std::vector<std::pair<std::array<std::uint32_t, 2>, unsigned>> proofLengthCombinations(std::uint32_t knownLimit);
3535

3636
// Data generation

0 commit comments

Comments
 (0)