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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
From: Sebastian Gerke <Sebastian.Gerke@dlr.de>
Date: Mon, 9 Oct 2017 09:33:02 +0000
Subject: parallel comparison
See bugs.debian.org/878060
OpenMP parallelized comparison of two PDFs
* What led up to the situation?
Comparison of two testsuitereports lasts more then a minute
* What exactly did you do
I wrote a patch to minimize the time of comparison
* What was the outcome of this action?
Now it only takes a few seconds to compare two testsuitereports
---
mainwindow.cpp | 87 +++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 55 insertions(+), 32 deletions(-)
diff --git a/mainwindow.cpp b/mainwindow.cpp
index d2113c9..2608253 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -44,6 +44,7 @@
#include <QSettings>
#include <QSpinBox>
#include <QSplitter>
+#include <omp.h>
MainWindow::MainWindow(const Debug debug,
@@ -1415,40 +1416,62 @@ const QPair<int, int> MainWindow::comparePages(const QString &filename1,
QList<int> pages1 = getPageList(1, pdf1);
QList<int> pages2 = getPageList(2, pdf2);
int total = qMin(pages1.count(), pages2.count());
- int number = 0;
+
int index = 0;
- while (!pages1.isEmpty() && !pages2.isEmpty()) {
- int p1 = pages1.takeFirst();
- PdfPage page1(pdf1->page(p1));
- if (!page1) {
- writeError(tr("Failed to read page %1 from '%2'.")
- .arg(p1 + 1).arg(filename1));
- continue;
- }
- int p2 = pages2.takeFirst();
- PdfPage page2(pdf2->page(p2));
- if (!page2) {
- writeError(tr("Failed to read page %1 from '%2'.")
- .arg(p2 + 1).arg(filename2));
- continue;
- }
- writeLine(tr("Comparing: %1 vs. %2.").arg(p1 + 1).arg(p2 + 1));
- QApplication::processEvents();
- if (cancel) {
- writeError(tr("Cancelled."));
- break;
- }
- Difference difference = getTheDifference(page1, page2);
- if (difference != NoDifference) {
- QVariant v;
- v.setValue(PagePair(p1, p2, difference == VisualDifference));
- viewDiffComboBox->addItem(tr("%1 vs. %2 %3 %4")
- .arg(p1 + 1).arg(p2 + 1).arg(QChar(0x2022))
- .arg(++index), v);
- }
- statusLabel->setText(tr("Comparing %1/%2").arg(++number)
- .arg(total));
+ int number = 0;
+ int processed = 0;
+
+ Difference difference[total];
+
+#pragma omp parallel for schedule(dynamic)
+ for (number = 0; number < total; number++) {
+
+ int p1 = pages1[number];
+ int p2 = pages2[number];
+
+#pragma omp critical
+ {
+ processed++;
+ statusLabel->setText(tr("Comparing %1/%2").arg(processed).arg(total));
+ writeLine(tr("Comparing: %1 vs. %2.").arg(p1 + 1).arg(p2 + 1));
+ QApplication::processEvents();
+ }
+
+ if (!cancel) {
+
+ PdfPage page1(pdf1->page(p1));
+ if (!page1) {
+#pragma omp critical
+ writeError(tr("Failed to read page %1 from '%2'.").arg(p1 + 1).arg(filename1));
+ continue;
+ }
+
+ PdfPage page2(pdf2->page(p2));
+ if (!page2) {
+#pragma omp critical
+ writeError(tr("Failed to read page %1 from '%2'.").arg(p2 + 1).arg(filename2));
+ continue;
+ }
+
+ difference[number] = getTheDifference(page1, page2);
+ }
+ }
+
+ if (!cancel) {
+
+ for (number = 0; number < total; number++) {
+
+ int p1 = pages1.takeFirst();
+ int p2 = pages2.takeFirst();
+
+ if (difference[number] != NoDifference) {
+ QVariant v;
+ v.setValue(PagePair(p1, p2, difference[number] == VisualDifference));
+ viewDiffComboBox->addItem(tr("%1 vs. %2 %3 %4").arg(p1 + 1).arg(p2 + 1).arg(QChar(0x2022)).arg(++index), v);
+ }
+ }
}
+
return qMakePair(number, total);
}
|