Completed implementation

This commit is contained in:
Robin Dietzel 2023-11-06 21:51:13 +01:00
parent 7082d548bc
commit ec1d2cdd46

View File

@ -40,17 +40,18 @@ auto parse_file(std::ifstream &stream, std::vector<T> &vec) -> void {
auto main(int argc, char *argv[]) -> int {
try {
std::ifstream file("dataset.dat", std::ios_base::in);
const auto path = "dataset.dat";
std::ifstream file(path, std::ios_base::in);
if (!file.is_open()) {
fmt::print("Error opening file");
fmt::print("\nError opening file");
return -1;
}
fmt::print("Opened file {} sucessfully\n", "dummy");
fmt::print("\nOpened file {} sucessfully", path);
std::vector<int32_t> dataset;
parse_file(file, dataset);
fmt::print("Read {} values from {}\n", dataset.size(), "dummy");
fmt::print("\nRead {} values from {}", dataset.size(), path);
auto dataset_par = dataset;
auto dataset_seq = dataset;
@ -62,7 +63,7 @@ auto main(int argc, char *argv[]) -> int {
auto t2 = std::chrono::high_resolution_clock::now();
auto t_seq = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
fmt::print("Sorted {} entries within {} ms in sequential\n", dataset_seq.size(), t_seq.count());
fmt::print("\nSorted {} entries within {} ms in sequential", dataset_seq.size(), t_seq.count());
const int threads = std::thread::hardware_concurrency();
@ -76,21 +77,21 @@ auto main(int argc, char *argv[]) -> int {
t2 = std::chrono::high_resolution_clock::now();
auto t_par = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
fmt::print("Sorted {} entries within {} ms in parallel using {} threads and a recursion depth of {}\n", dataset_seq.size(), t_par.count(), threads, max_depth);
fmt::print("\nSorted {} entries within {} ms in parallel using {} threads and a recursion depth of {}", dataset_seq.size(), t_par.count(), threads, max_depth);
auto eq = (dataset_seq == dataset_par);
fmt::print("Check whether sorted arrays are equal: {}\n", (eq)? "Equal" : "not equal");
fmt::print("\nCheck whether sorted arrays are equal: {}", (eq)? "Equal" : "not equal");
fmt::print("------------Summary------------");
fmt::print("t_seq = {}", t_seq.count());
fmt::print("t_par = {}", t_par.count());
fmt::print("speedup = {}", (1.0*t_seq/t_par));
fmt::print("t_seq-t_par = {}", (t_seq.count() - t_par.count()));
fmt::print("-------------------------------");
fmt::print("\n\n------------Summary------------");
fmt::print("\nt_seq = {: > 5.2f} ms", static_cast<float>(t_seq.count()));
fmt::print("\nt_par = {: > 5.2f} ms", static_cast<float>(t_par.count()));
fmt::print("\nspeedup = {: > 5.2f}", (1.0*t_seq/t_par));
fmt::print("\nDelta_t = {: > 5.2f} ms", static_cast<float>(t_seq.count() - t_par.count()));
fmt::print("\n-------------------------------");
std::ofstream ofile("dataset.out.dat", std::ios_base::out);
if(!ofile.is_open()) {
fmt::print("Error writing to file");
fmt::print("\nError writing to file");
return -1;
}
@ -102,12 +103,12 @@ auto main(int argc, char *argv[]) -> int {
ofile.flush();
ofile.close();
fmt::print("Written to output file\n");
fmt::print("\nWritten to output file");
return 0;
} catch (std::exception &e) {
fmt::print("Error occured: {}", e.what());
fmt::print("\nError occured: {}", e.what());
return -1;
}