Add data loader

This commit is contained in:
Robin Dietzel 2023-11-09 20:46:19 +01:00
parent a818b9af66
commit c6cdc7ea6e
3 changed files with 67 additions and 7 deletions

View File

@ -38,7 +38,13 @@ add_executable(task1-randgen)
target_sources(task1-randgen PRIVATE
src/task1-randgen.cpp)
target_link_libraries(task1-randgen PRIVATE
fmt::fmt
Qt6::Core)
# Add task1 target with an C++ written QT-based mergesort
add_executable(task1-sorter)
target_sources(task1-sorter PRIVATE
src/task1-sorter.cpp)
target_link_libraries(task1-sorter PRIVATE
Qt6::Core)
# Define install options

View File

@ -5,10 +5,7 @@
#include <QFileInfo>
#include <cmath>
#include <random>
#include <fstream>
#include <ranges>
#include "fmt/format.h"
int main(int argc, char *argv[]) {
@ -26,14 +23,14 @@ int main(int argc, char *argv[]) {
const QStringList args = parser.positionalArguments();
if(args.length() != 2) {
if (args.length() != 2) {
parser.showHelp(-1);
}
const QString dest = args.at(0);
bool convOK;
const int pow_value = args.at(1).toInt(&convOK);
if(!convOK) {
if (!convOK) {
parser.showHelp(-1);
}
@ -57,7 +54,8 @@ int main(int argc, char *argv[]) {
file.flush();
QFileInfo finfo(file);
print << "Wrote " << num_values << " to " << dest << " with resulting size of " << (finfo.size()/1000000) << " mb" << Qt::endl;
print << "Wrote " << num_values << " to " << dest << " with resulting size of " << (finfo.size() / 1000000) << " mb"
<< Qt::endl;
file.close();

View File

@ -0,0 +1,56 @@
#include <QRandomGenerator>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QFile>
#include <QFileInfo>
#include <cmath>
#include <thread>
#include <ranges>
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("Multi purpose mergesort application");
QCoreApplication::setApplicationVersion("1.0.42");
QTextStream print(stdout);
QCommandLineParser parser;
parser.setApplicationDescription("Used to run either sequential or parallel mergesort on a texfile containing ascii encoded int32s");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption sequential("S", "Run sequential sort on dataset");
QCommandLineOption parallel("P", "Run parallel sort on dataset");
QCommandLineOption nthreads(QStringList() << "d" << "depth", "Recursion depth of parallel part", "nthreads");
QCommandLineOption output(QStringList() << "o", "output", "File to write the sorted dataset to");
parser.addOption(sequential);
parser.addOption(parallel);
parser.addOption(nthreads);
parser.addPositionalArgument("dataset", "Filename where to load the data from");
parser.process(app);
const int threads = std::thread::hardware_concurrency();
int max_depth = std::sqrt(threads);
print << "Hardware concurrency of " << threads << " detected" << Qt::endl;
if(parser.isSet(nthreads)) {
bool ok;
max_depth = parser.value(nthreads).toInt(&ok);
if(!ok) {
parser.showHelp(-1);
}
print << "Overwriting maximum parallelized recursion depth with " << max_depth << Qt::endl;
} else {
print << "Assuming default parallelized recursion depth via sqrt(nthreads) of " << max_depth << Qt::endl;
}
app.exit(0);
return 0;
}