Skip to content

Commit 34bd17f

Browse files
committed
join 3a13cb1 (c++11)
1 parent 2660838 commit 34bd17f

File tree

14 files changed

+717
-712
lines changed

14 files changed

+717
-712
lines changed

__dependency_graph.dot

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
digraph {
22
CfgGrammar -> FctHelper [color=blue]
3-
CfgGrammar -> regex [color=blue]
3+
CfgGrammar -> "boost/algorithm/string" [color=blue]
44
CfgGrammar -> IPrintable [color=red]
55
CfgGrammar -> cstdint [color=red]
66
CfgGrammar -> unordered_map [color=red]
@@ -9,17 +9,16 @@ digraph {
99
CfgGrammar
1010
CfgGrammar
1111
}
12+
FctHelper -> "boost/filesystem/operations" [color=blue]
1213
FctHelper -> iostream [color=blue]
1314
FctHelper -> math [color=blue]
1415
FctHelper -> mpi [color=blue]
1516
FctHelper -> algorithm [color=red]
1617
FctHelper -> array [color=red]
17-
FctHelper -> charconv [color=red]
1818
FctHelper -> chrono [color=red]
1919
FctHelper -> cstddef [color=red]
2020
FctHelper -> cstdint [color=red]
2121
FctHelper -> deque [color=red]
22-
FctHelper -> filesystem [color=red]
2322
FctHelper -> fstream [color=red]
2423
FctHelper -> map [color=red]
2524
FctHelper -> set [color=red]
@@ -84,7 +83,6 @@ digraph {
8483
DRuleParser -> map [color=red]
8584
DRuleParser -> memory [color=red]
8685
DRuleParser -> set [color=red]
87-
DRuleParser -> string_view [color=red]
8886
DRuleParser -> string [color=red]
8987
DRuleParser -> tuple [color=red]
9088
DRuleParser -> unordered_map [color=red]
@@ -140,6 +138,7 @@ digraph {
140138
DlProofEnumerator -> DRuleParser [color=blue]
141139
DlProofEnumerator -> DlCore [color=blue]
142140
DlProofEnumerator -> DlFormula [color=blue]
141+
DlProofEnumerator -> "boost/filesystem/operations" [color=blue]
143142
DlProofEnumerator -> concurrent_map [color=blue]
144143
DlProofEnumerator -> concurrent_queue [color=blue]
145144
DlProofEnumerator -> concurrent_unordered_map [color=blue]

grammar/CfgGrammar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "../helper/FctHelper.h"
44

5-
#include <regex>
5+
#include <boost/algorithm/string.hpp>
66

77
using namespace std;
88
using namespace xamid::helper;
@@ -13,7 +13,7 @@ namespace grammar {
1313
CfgGrammar::CfgGrammar(const string& startSymbolString, const string& grammarString) :
1414
_elementCounter(0), _startSymbolString(startSymbolString), _grammarString(grammarString) {
1515
// 1. Replace "\r\n" with "\n" in the grammar string
16-
_grammarString = regex_replace(_grammarString, regex("\\r\\n"), "\n");
16+
boost::replace_all(_grammarString, "\r\n", "\n");
1717

1818
// 2. Build up nonterminals and production rules
1919
istringstream reader1(_grammarString);

helper/FctHelper.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "FctHelper.h"
22

3+
#include <boost/filesystem/operations.hpp>
4+
35
#include <iostream>
46
#include <math.h>
57
#include <mpi.h>
@@ -28,19 +30,19 @@ bool cmpStringGrow::operator()(const string& a, const string& b) const {
2830
}
2931

3032
// Templates for using values, static arrays and dynamic arrays on MPI_Send and MPI_Recv ("block until received", with extra mode "receive only if sent")
31-
template<typename T> void mpi_send(int rank, int count, MPI_Datatype type, const T* val, int dest, int tag, bool debug, auto printer) {
33+
template<typename T, typename Func> void mpi_send(int rank, int count, MPI_Datatype type, const T* val, int dest, int tag, bool debug, Func printer) {
3234
if (debug)
3335
cout << rank << "->" << dest << ": Sending " << printer(val) << "." << endl;
3436
MPI_Send(val, count, type, dest, tag, MPI_COMM_WORLD);
3537
}
36-
template<typename T> T mpi_recvValue(int rank, MPI_Datatype type, int source, int tag, bool debug, auto printer) {
38+
template<typename T, typename Func> T mpi_recvValue(int rank, MPI_Datatype type, int source, int tag, bool debug, Func printer) {
3739
T val;
3840
MPI_Recv(&val, 1, type, source, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
3941
if (debug)
4042
cout << source << "->" << rank << ": Received " << printer(val) << "." << endl;
4143
return val;
4244
}
43-
template<typename T> bool mpi_tryRecvValue(int rank, MPI_Datatype type, int source, int tag, T& result, bool debug, auto printer) {
45+
template<typename T, typename Func> bool mpi_tryRecvValue(int rank, MPI_Datatype type, int source, int tag, T& result, bool debug, Func printer) {
4446
int flag;
4547
MPI_Iprobe(source, tag, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
4648
if (flag) {
@@ -50,14 +52,14 @@ template<typename T> bool mpi_tryRecvValue(int rank, MPI_Datatype type, int sour
5052
}
5153
return flag;
5254
}
53-
template<typename T, size_t N> array<T, N> mpi_recvArray(int rank, MPI_Datatype type, int source, int tag, bool debug, auto printer) {
55+
template<typename T, size_t N, typename Func> array<T, N> mpi_recvArray(int rank, MPI_Datatype type, int source, int tag, bool debug, Func printer) {
5456
array<T, N> arr;
5557
MPI_Recv(arr.data(), N, type, source, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
5658
if (debug)
5759
cout << source << "->" << rank << ": Received " << printer(arr) << "." << endl;
5860
return arr;
5961
}
60-
template<typename T, size_t N> bool mpi_tryRecvArray(int rank, MPI_Datatype type, int source, int tag, array<T, N>& result, bool debug, auto printer) {
62+
template<typename T, size_t N, typename Func> bool mpi_tryRecvArray(int rank, MPI_Datatype type, int source, int tag, array<T, N>& result, bool debug, Func printer) {
6163
int flag;
6264
MPI_Iprobe(source, tag, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE);
6365
if (flag) {
@@ -67,7 +69,7 @@ template<typename T, size_t N> bool mpi_tryRecvArray(int rank, MPI_Datatype type
6769
}
6870
return flag;
6971
}
70-
template<typename T> ManagedArray<T> mpi_recvDynArray(int rank, MPI_Datatype type, int source, int tag, bool debug, auto printer) {
72+
template<typename T, typename Func> ManagedArray<T> mpi_recvDynArray(int rank, MPI_Datatype type, int source, int tag, bool debug, Func printer) {
7173
MPI_Status status_recv;
7274
MPI_Probe(source, tag, MPI_COMM_WORLD, &status_recv);
7375
int size;
@@ -80,7 +82,7 @@ template<typename T> ManagedArray<T> mpi_recvDynArray(int rank, MPI_Datatype typ
8082
cout << source << "->" << rank << ": Received " << printer(arr) << "." << endl;
8183
return arr;
8284
}
83-
template<typename T> bool mpi_tryRecvDynArray(int rank, MPI_Datatype type, int source, int tag, ManagedArray<T>& result, bool debug, auto printer) {
85+
template<typename T, typename Func> bool mpi_tryRecvDynArray(int rank, MPI_Datatype type, int source, int tag, ManagedArray<T>& result, bool debug, Func printer) {
8486
int flag;
8587
MPI_Status status_recv;
8688
MPI_Iprobe(source, tag, MPI_COMM_WORLD, &flag, &status_recv);
@@ -247,10 +249,10 @@ string FctHelper::durationYearsToMs(const chrono::microseconds& dur, bool innerA
247249
// 2^63+1 µs = 292277 yr 0 mo 1 wk 1 d 23 h 52 min 30 s 775.807 ms
248250
// wolframAlphaMode => -2^63 µs = -292471 yr -2 mo -2 wk -1 d -8 h 0 min -54 s -775.808 ms
249251
// 2^63+1 µs = 292471 yr 2 mo 2 wk 1 d 8 h 0 min 54 s 775.807 ms
250-
constexpr intmax_t yearUs = chrono::years::period::num * chrono::microseconds::period::den; // 1 yr = 31556952000000 µs ; NOTE: 31556952 s / yr include leap years, otherwise it would be 60 * 60 * 24 * 365 = 31540000 s / yr.
251-
constexpr intmax_t monthUs = chrono::months::period::num * chrono::microseconds::period::den; // 1 mo = 2629746000000 µs ; 2629746 s / mo include leap years, otherwise it would be 31540000 / 12 = 7885000 / 3 = 2628333.333.. s / mo.
252-
constexpr intmax_t weekUs = chrono::weeks::period::num * chrono::microseconds::period::den; // 1 wk = 604800000000 µs ; 60 * 60 * 24 * 7 = 604800 s / wk, i.e. from here down, the C++ standard's leap years do not influence values.
253-
constexpr intmax_t dayUs = chrono::days::period::num * chrono::microseconds::period::den; // 1 d = 86400000000 µs
252+
constexpr intmax_t yearUs = 31556952 * chrono::microseconds::period::den; // 1 yr = 31556952000000 µs ; NOTE: 31556952 s / yr include leap years, otherwise it would be 60 * 60 * 24 * 365 = 31540000 s / yr.
253+
constexpr intmax_t monthUs = 2629746 * chrono::microseconds::period::den; // 1 mo = 2629746000000 µs ; 2629746 s / mo include leap years, otherwise it would be 31540000 / 12 = 7885000 / 3 = 2628333.333.. s / mo.
254+
constexpr intmax_t weekUs = 604800 * chrono::microseconds::period::den; // 1 wk = 604800000000 µs ; 60 * 60 * 24 * 7 = 604800 s / wk, i.e. from here down, the C++ standard's leap years do not influence values.
255+
constexpr intmax_t dayUs = 86400 * chrono::microseconds::period::den; // 1 d = 86400000000 µs
254256
constexpr intmax_t hourUs = chrono::hours::period::num * chrono::microseconds::period::den; // 1 h = 3600000000 µs
255257
constexpr intmax_t minuteUs = chrono::minutes::period::num * chrono::microseconds::period::den; // 1 min = 60000000 µs
256258
constexpr intmax_t secondUs = chrono::seconds::period::num * chrono::microseconds::period::den; // 1 s = 1000000 µs
@@ -369,10 +371,10 @@ bool FctHelper::ensureDirExists(const string& path) {
369371
string::size_type dirMarkerIndex = path.find_last_of("/\\");
370372
if (dirMarkerIndex != string::npos) { // If there is a path to another directory given, make sure that the directory exists.
371373
string dir = path.substr(0, dirMarkerIndex);
372-
if (!filesystem::is_directory(dir)) { // Need to create that directory, but in order to do so, must first ensure that its parent directory exists.
374+
if (!boost::filesystem::is_directory(dir)) { // Need to create that directory, but in order to do so, must first ensure that its parent directory exists.
373375
if (!ensureDirExists(dir))
374376
return false;
375-
if (!filesystem::create_directories(dir)) {
377+
if (!boost::filesystem::create_directories(dir)) {
376378
cerr << "Failed to create directory \"" << dir << "\"." << endl;
377379
return false;
378380
}
@@ -382,31 +384,23 @@ bool FctHelper::ensureDirExists(const string& path) {
382384
}
383385

384386
bool FctHelper::writeToFile(const string& file, const string& content, fstream::openmode mode) {
385-
return _writeToFile(filesystem::u8path(file), content, mode);
386-
}
387-
388-
bool FctHelper::_writeToFile(const filesystem::path& file, const string& content, fstream::openmode mode) {
389387
// 1. Ensure directory exists
390-
if (!filesystem::exists(file) && !ensureDirExists(file.string()))
388+
if (!boost::filesystem::exists(file) && !ensureDirExists(file))
391389
return false;
392390
// 2. Save file
393391
ofstream fout(file, mode);
394392
if (!fout.is_open()) {
395-
cerr << "Cannot write to file \"" << file.string() << "\"." << endl;
393+
cerr << "Cannot write to file \"" << file << "\"." << endl;
396394
return false;
397395
}
398396
fout << content;
399397
return true;
400398
}
401399

402400
bool FctHelper::readFile(const string& file, string& out_content, fstream::openmode mode) {
403-
return _readFile(filesystem::u8path(file), out_content, mode);
404-
}
405-
406-
bool FctHelper::_readFile(const filesystem::path& file, string& out_content, fstream::openmode mode) {
407401
ifstream fin(file, mode);
408402
if (!fin.is_open()) {
409-
cerr << "Cannot read from file \"" << file.string() << "\"." << endl;
403+
cerr << "Cannot read from file \"" << file << "\"." << endl;
410404
return false;
411405
}
412406
stringstream buffer;

helper/FctHelper.h

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33

44
#include <algorithm>
55
#include <array>
6-
#include <charconv>
76
#include <chrono>
87
#include <cstddef>
98
#include <cstdint>
109
#include <deque>
11-
#include <filesystem>
1210
#include <fstream>
1311
#include <map>
1412
#include <set>
@@ -56,41 +54,52 @@ struct FctHelper {
5654
static std::array<std::uint64_t, 2> mpi_recvUint64Pair(int rank, int source, bool debug = false);
5755
static bool mpi_tryRecvUint64Pair(int rank, int source, std::array<std::uint64_t, 2>& result, bool debug = false);
5856

59-
// from_chars does not work as desired (i.e. accepts invalid inputs), so we use it with some additional argument checks
6057
template<typename T>
61-
static constexpr std::from_chars_result charsToUInt(const char* begin, const char* end, T& value) {
62-
std::from_chars_result result;
63-
if (begin > end) {
64-
result.ec = std::errc::invalid_argument;
65-
return result;
66-
}
67-
if (*begin == '0' && begin + 1 != end) {
68-
result.ec = std::errc::invalid_argument;
69-
return result;
70-
}
71-
for (const char* it = begin; it < end; it++)
72-
switch (*it) {
58+
static bool toUInt(const std::string& str, T& value) {
59+
if (*str.c_str() == '0' && str.length() != 1)
60+
return false;
61+
T num = 0;
62+
for (char c : str) {
63+
T before = num;
64+
switch (c) {
7365
case '0':
66+
num = 10 * num;
67+
break;
7468
case '1':
69+
num = 10 * num + 1;
70+
break;
7571
case '2':
72+
num = 10 * num + 2;
73+
break;
7674
case '3':
75+
num = 10 * num + 3;
76+
break;
7777
case '4':
78+
num = 10 * num + 4;
79+
break;
7880
case '5':
81+
num = 10 * num + 5;
82+
break;
7983
case '6':
84+
num = 10 * num + 6;
85+
break;
8086
case '7':
87+
num = 10 * num + 7;
88+
break;
8189
case '8':
90+
num = 10 * num + 8;
91+
break;
8292
case '9':
93+
num = 10 * num + 9;
8394
break;
8495
default:
85-
result.ec = std::errc::invalid_argument;
86-
return result;
96+
return false;
8797
}
88-
result = std::from_chars(begin, end, value);
89-
return result;
90-
}
91-
template<typename T>
92-
static constexpr std::from_chars_result toUInt(const std::string& str, T& value) {
93-
return charsToUInt(str.c_str(), str.c_str() + str.length(), value);
98+
if (num < before) // overflow
99+
return false;
100+
}
101+
value = num;
102+
return true;
94103
}
95104

96105
// Functions to quickly calculate to_string(n).length()
@@ -112,10 +121,7 @@ struct FctHelper {
112121

113122
static bool writeToFile(const std::string& file, const std::string& content, std::fstream::openmode mode = std::fstream::out | std::fstream::binary);
114123
static bool readFile(const std::string& file, std::string& out_content, std::fstream::openmode mode = std::fstream::in | std::fstream::binary);
115-
private:
116-
static bool _writeToFile(const std::filesystem::path& file, const std::string& content, std::fstream::openmode mode = std::fstream::out | std::fstream::binary);
117-
static bool _readFile(const std::filesystem::path& file, std::string& out_content, std::fstream::openmode mode = std::fstream::in | std::fstream::binary);
118-
public:
124+
119125
static std::wstring utf8toWide(const std::string& in);
120126
static std::wstring utf8toWide(const char* in);
121127
static std::vector<std::string> stringSplit(const std::string& str, const std::string& sep);
@@ -135,8 +141,8 @@ struct FctHelper {
135141
return ss.str();
136142
}
137143

138-
template<typename T, typename U>
139-
static std::string vectorStringF(const std::vector<T, U>& v, const auto& f, const std::string& leftDelimiter = "[", const std::string& rightDelimiter = "]", const std::string& sep = ", ") {
144+
template<typename T, typename U, typename Func>
145+
static std::string vectorStringF(const std::vector<T, U>& v, const Func& f, const std::string& leftDelimiter = "[", const std::string& rightDelimiter = "]", const std::string& sep = ", ") {
140146
std::stringstream ss;
141147
ss << leftDelimiter;
142148
for (std::size_t i = 0; i < v.size(); ++i) {
@@ -161,8 +167,8 @@ struct FctHelper {
161167
return ss.str();
162168
}
163169

164-
template<typename T, typename U, typename V, typename W>
165-
static std::string mapStringF(const std::map<T, U, V, W>& m, const auto& f, const std::string& leftDelimiter = "{", const std::string& rightDelimiter = "}", const std::string& sep = ", ") {
170+
template<typename T, typename U, typename V, typename W, typename Func>
171+
static std::string mapStringF(const std::map<T, U, V, W>& m, const Func& f, const std::string& leftDelimiter = "{", const std::string& rightDelimiter = "}", const std::string& sep = ", ") {
166172
std::stringstream ss;
167173
ss << leftDelimiter;
168174
for (typename std::map<T, U, V, W>::const_iterator it = m.begin(); it != m.end(); ++it) {

helper/FwdTbb.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#ifndef XAMID_HELPER_FWDTBB_H
22
#define XAMID_HELPER_FWDTBB_H
33

4-
#if __has_include(<tbb/version.h>)
4+
//#if __has_include(<tbb/version.h>) // NOTE: Change manually if required. There seems to be no alternative for __has_include in C++11.
55
#include <tbb/version.h>
6-
#else
7-
#include <tbb/tbb_stddef.h>
8-
#endif
6+
//#else
7+
//#include <tbb/tbb_stddef.h>
8+
//#endif
99

1010
#include <functional>
1111
#include <utility>
1212

1313
namespace tbb {
1414
#if TBB_INTERFACE_VERSION >= 12002 // since v2021.1-beta08
15-
namespace detail::d1 { template<typename T> class tbb_allocator; template<typename T> class cache_aligned_allocator; template<typename T, typename Allocator> class concurrent_vector; template<typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator> class concurrent_unordered_map; template<typename Key, typename Hash, typename KeyEqual, typename Allocator> class concurrent_unordered_set; }
15+
namespace detail { namespace d1 { template<typename T> class tbb_allocator; template<typename T> class cache_aligned_allocator; template<typename T, typename Allocator> class concurrent_vector; template<typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator> class concurrent_unordered_map; template<typename Key, typename Hash, typename KeyEqual, typename Allocator> class concurrent_unordered_set; } }
1616
using detail::d1::tbb_allocator;
1717
using detail::d1::cache_aligned_allocator;
1818
using detail::d1::concurrent_vector;
1919
using detail::d1::concurrent_unordered_map;
2020
using detail::d1::concurrent_unordered_set;
2121
#if TBB_INTERFACE_VERSION >= 12040 // since v2021.4.0
22-
namespace detail::d2 { template<typename Key, typename Value, typename Compare, typename Allocator> class concurrent_map; }
22+
namespace detail { namespace d2 { template<typename Key, typename Value, typename Compare, typename Allocator> class concurrent_map; } }
2323
using detail::d2::concurrent_map;
2424
#else
25-
namespace detail::d1 { template<typename Key, typename Value, typename Compare, typename Allocator> class concurrent_map; }
25+
namespace detail { namespace d1 { template<typename Key, typename Value, typename Compare, typename Allocator> class concurrent_map; } }
2626
using detail::d1::concurrent_map;
2727
#endif
2828
#else

helper/ProgressData.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct ProgressData {
1616
bool maximumEstimated = false;
1717
std::chrono::time_point<std::chrono::system_clock> startTime;
1818
std::vector<std::uint64_t> progressSteps;
19-
std::atomic<std::uint64_t> progress = 0;
20-
std::atomic<std::uint64_t> progressState = 0;
19+
std::atomic<std::uint64_t> progress { 0 };
20+
std::atomic<std::uint64_t> progressState { 0 };
2121
ProgressData() = default;
2222
ProgressData(const ProgressData& other) : percentageStepSize(other.percentageStepSize), maximum(other.maximum), maximumEstimated(other.maximumEstimated), progressSteps(other.progressSteps), progress((std::uint64_t) other.progress), progressState((std::uint64_t) other.progressState) { }
2323
ProgressData(unsigned percentageStepSize, std::uint64_t maximum, bool estimated = false);

main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ int main(int argc, char* argv[]) { // argc = 1 + N, argv = { <command>, <arg1>,
230230
else {
231231
string param = string(argv[++i]);
232232
unsigned value;
233-
from_chars_result result = FctHelper::toUInt(param, value);
234-
if (result.ec != errc())
233+
if (!FctHelper::toUInt(param, value))
235234
return printUsage("Invalid parameter \"" + param + "\" for \"-m\".");
236235
tasks.emplace_back(Task::MpiFilter, value, "", "", "", "", true, false, false, false, 0, 0);
237236
mpiArg = "-m";
@@ -321,7 +320,7 @@ int main(int argc, char* argv[]) { // argc = 1 + N, argv = { <command>, <arg1>,
321320
else {
322321
string path = get<3>(t);
323322
FctHelper::ensureDirExists(path);
324-
ofstream fout(filesystem::u8path(path), fstream::out | fstream::binary);
323+
ofstream fout(path, fstream::out | fstream::binary);
325324
if (!fout.is_open())
326325
throw invalid_argument("Cannot write to file \"" + string(path) + "\".");
327326
DlProofEnumerator::printConclusionLengthPlotData(get<7>(t), get<8>(t), get<10>(t), get<11>(t), get<2>(t), &fout, get<6>(t));

0 commit comments

Comments
 (0)