2023-10-31 13:48:54 +00:00
|
|
|
|
#include <fmt/format.h>
|
|
|
|
|
#include <vector>
|
2023-11-01 09:00:36 +00:00
|
|
|
|
#include <fstream>
|
2023-10-31 20:11:31 +00:00
|
|
|
|
|
|
|
|
|
#include <mergesort.h>
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Create a simple sorting application that uses the mergesort algorithm to sort a
|
|
|
|
|
large collection (e.g., 10^7 ) of 32-bit integers. The input data and output results
|
|
|
|
|
should be stored in files, and the I/O operations should be considered a
|
|
|
|
|
sequential part of the application. Mergesort is an algorithm that is considered
|
|
|
|
|
appropriate for parallel execution, although it cannot be equally divided between
|
|
|
|
|
an arbitrary number of processors, as Amdahl’s and Gustafson-Barsis’ laws
|
|
|
|
|
require.
|
|
|
|
|
Assuming that this equal division is possible, estimate α, i.e., the part of the
|
|
|
|
|
program that can be parallelized, by using a profiler like gprof or valgrind to
|
|
|
|
|
measure the duration of mergesort’s execution relative to the overall execution
|
|
|
|
|
time. Use this number to estimate the predicted speedup for your program.
|
|
|
|
|
Does α depend on the size of the input? If it does, how should you modify
|
|
|
|
|
your predictions and their graphical illustration?
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2023-11-01 09:00:36 +00:00
|
|
|
|
try {
|
|
|
|
|
std::ifstream file("dataset.dat", std::ios_base::in);
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
fmt::print("Opened file {} sucessfully!\n", "dummy");
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
std::vector<int32_t> dataset{10, 3, 244, 23, 293, 2393, 302};
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
// std::vector<int32_t> dataset;
|
|
|
|
|
// int counter = 0;
|
|
|
|
|
//
|
|
|
|
|
// while(!file.eof()) {
|
|
|
|
|
// int32_t buf;
|
|
|
|
|
// file >> buf;
|
|
|
|
|
// dataset.emplace_back(buf);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// fmt::print("Read {} values from {}\n", dataset.size(), "dummy");
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
algo::mergesort(dataset.begin(), dataset.end(), [](int32_t a, int32_t b) {
|
|
|
|
|
return (a>b);
|
|
|
|
|
});
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
fmt::print("sorted");
|
2023-10-31 13:48:54 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
// QFile outfile("dataset-sorted.dat");
|
|
|
|
|
// if(!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
|
|
|
// fmt::print("Error! Could not create output file");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// for(auto &val : dataset) {
|
|
|
|
|
// outfile.write(fmt::format("{}\n", val).c_str());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// file.close();
|
|
|
|
|
// outfile.flush();
|
|
|
|
|
// outfile.close();
|
2023-10-31 20:11:31 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
return 0;
|
2023-10-31 20:11:31 +00:00
|
|
|
|
|
2023-11-01 09:00:36 +00:00
|
|
|
|
} catch (std::exception e) {
|
|
|
|
|
fmt::print("Could not open file");
|
|
|
|
|
return -1;
|
2023-10-31 20:11:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 13:48:54 +00:00
|
|
|
|
}
|