44 lines
1.6 KiB
C++
44 lines
1.6 KiB
C++
#include <fmt/format.h>
|
||
#include <QCoreApplication>
|
||
#include <QFile>
|
||
#include <vector>
|
||
#include <printf.h>
|
||
|
||
/*
|
||
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[]) {
|
||
QFile file("dataset.dat");
|
||
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||
//qDebug() << "Could not open file";
|
||
return 0;
|
||
}
|
||
|
||
fmt::print("Opened file {} sucessfully!\n", file.fileName().toStdString());
|
||
|
||
|
||
std::vector<int32_t> dataset;
|
||
int counter = 0;
|
||
|
||
while(!file.atEnd()) {
|
||
dataset.emplace_back(file.readLine().toInt());
|
||
}
|
||
|
||
fmt::print("Read {} values from {}\n", dataset.size(), file.fileName().toStdString());
|
||
|
||
return 0;
|
||
}
|