-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
99 lines (83 loc) · 2.4 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
cpuProcessor(NULL),
gpuProcessor(NULL),
timeCurve("Processing time"),
prevTime(QTime::currentTime())
{
ui->setupUi(this);
timeCurve.setPen(QPen(Qt::red));
timeCurve.setRenderHint(QwtPlotItem::RenderAntialiased);
timeCurve.attach(ui->plot);
ui->plot->setAxisTitle(QwtPlot::yLeft, "processing time -->");
ui->plot->insertLegend(new QwtLegend(), QwtPlot::TopLegend);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_startCPUButton_clicked()
{
unsigned int dataSize = ui->dataSizeEdit->text().toInt();
unsigned int threadsCount = ui->threadsCountEdit->text().toInt();
unsigned int dataPerThread = dataSize / threadsCount;
ui->dataPerThread->setText(QString::number(dataPerThread));
xs.clear();
ys.clear();
cpuProcessor = new CPUProcessor(dataPerThread, threadsCount);
connect(cpuProcessor, SIGNAL(dataProcessed()), this, SLOT(updateStats()));
cpuProcessor->start();
}
void MainWindow::updateStats()
{
QTime curTime = QTime::currentTime();
double diff = curTime.msec() - prevTime.msec();
if (diff > 0)
{
xs.push_back(xs.size());
if (xs.size() < 2)
{
ys.push_back(0);
}
else
{
ys.push_back(curTime.msec() - prevTime.msec());
}
timeCurve.setData(&xs[0], &ys[0], xs.size());
ui->plot->replot();
}
prevTime = curTime;
}
void MainWindow::on_stopButton_clicked()
{
if (cpuProcessor)
{
cpuProcessor->quit();
cpuProcessor->wait();
delete cpuProcessor;
cpuProcessor = NULL;
}
if (gpuProcessor)
{
gpuProcessor->quit();
gpuProcessor->wait();
delete gpuProcessor;
gpuProcessor = NULL;
}
}
void MainWindow::on_startGPUButton_clicked()
{
unsigned int dataSize = ui->dataSizeEdit->text().toInt();
unsigned int threadsCount = ui->threadsCountEdit->text().toInt();
unsigned int dataPerThread = dataSize / threadsCount;
ui->dataPerThread->setText(QString::number(dataPerThread));
xs.clear();
ys.clear();
gpuProcessor = new GPUProcessor(dataPerThread, threadsCount);
connect(gpuProcessor, SIGNAL(dataProcessed()), this, SLOT(updateStats()));
gpuProcessor->start();
}