diff --git a/task1/CMakeLists.txt b/task1/CMakeLists.txt index 7541291..d44b35a 100644 --- a/task1/CMakeLists.txt +++ b/task1/CMakeLists.txt @@ -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 diff --git a/task1/src/task1-randgen.cpp b/task1/src/task1-randgen.cpp index 3f7fc20..410da5f 100644 --- a/task1/src/task1-randgen.cpp +++ b/task1/src/task1-randgen.cpp @@ -5,10 +5,7 @@ #include #include -#include -#include #include -#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(); diff --git a/task1/src/task1-sorter.cpp b/task1/src/task1-sorter.cpp new file mode 100644 index 0000000..1e6099a --- /dev/null +++ b/task1/src/task1-sorter.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +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; +} \ No newline at end of file