MapReduce's QWaitCondition: Destroyed while threads are still waiting
-
@#include <vector>
#include <iostream>
#include <QList>
#include <QMap>
#include <QTextStream>
#include <QString>
#include <QStringList>
#include <QDir>
#include <QTime>
#include <QApplication>
#include <QDebug>
#include <QVector>#include <qtconcurrentmap.h>
using namespace std;
using namespace QtConcurrent;
typedef QPair<int, QVector<int> > FileEntry;
void printQVec(QVector< QVector< int> > vec)
{
for(int i = 0; i < vec.size(); ++i)
{
for(int j = 0; j < (vec.at(i)).size(); ++j)
{
cout << ((vec.at(i)).at(j)) << endl;
}
}
}QVector<int> mapping(const FileEntry &entry)
{
//int index = entry.first;cout << "index " << entry.first << endl; QVector<int> row1; for(int i = 0; i != (entry.second).size(); ++i) { row1.append(((entry).second).at(i)); } QVector<int> row; for(int i = 0; i != row1.size(); ++i) { row.append( row1.at(i) + row1.at(i) ); cout << row.at(i) << " "; } cout << endl; return row;
}
void reduce(QVector< QVector<int> > & reduceResult, const QVector<int> part )
{reduceResult.append(part); //reduceResult += part; cout << "running reduce" << endl;
}
int main()
{
vector< vector<int> > vec;
vector<int> temp;for(int i = 0; i != 9; ++i ) { for(int i = 0; i != 9; ++i) { temp.push_back(i); } vec.push_back(temp); } vector< vector<int> >::iterator r; vector<int>::iterator c; QVector< QVector<int> > qmat; for (r = vec.begin(); r != vec.end(); r++) { QVector<int> qtemp; for (c = r->begin(); c != r->end(); c++) { qtemp.append(*c); } qmat.append(qtemp); } printQVec(qmat); QList<FileEntry> fileEntries; fileEntries.reserve(9); for(int i = 0; i < qmat.size(); ++i) { fileEntries << qMakePair(i, qmat.at(i)); } QVector< QVector <int> > final; final = mappedReduced(fileEntries, mapping, reduce, SequentialReduce); printQVec(final);
}
@
I am seriously trying to figure out what's wrong with my code. Does it have anything to do with the reduce function?[edit: added coding tags SGaist]
-
Hi and welcome to devnet,
No, it's the fact that you don't wait for the mappedReduced to end before stopping your application.
You might be interested by "this":http://qt-project.org/doc/qt-5/qfuturewatcher.html#waitForFinished
Hope it helps
-
@ QFuture< QVector< QVector <int> > > final;
final = mappedReduced(fileEntries, mapping, reduce, SequentialReduce); //final.QFuture::waitForFinished(); QFutureWatcher< QVector< QVector <int> > > watcher; watcher.setFuture(final); watcher.QFutureWatcher::waitForFinished();@
Thanks for replying.
I added the above, but it still doesn't work. Do you know what I am doing wrong?
-
@ watcher.QFutureWatcher::waitForFinished();@
should be just
@watcher.waitForFinished();@
-
still, doesn't work...
is it possible that you can't output something like a vector of vector using mapreduce?
Debugging starts
(Internal error: pc 0x0 in read in psymtab, but not in symtab.)
(Internal error: pc 0x0 in read in psymtab, but not in symtab.)
(Internal error: pc 0x0 in read in psymtab, but not in symtab.)
(Internal error: pc 0x0 in read in psymtab, but not in symtab.)
(Internal error: pc 0x0 in read in psymtab, but not in symtab.) -
hmm, actually, after running it 4 times I end up getting the same result:
index index 0index 3
0 2 4 6 index 2
8 10 12 14 16 0 2 4 1
0 2 4 6 8 10 12 0 6 014 16 0 2 4 82 4 6 2 6 8 10 12 148 16 0 2 4 6 8 10 12 14
16 10 10 4 6 12 0 12 8 14 2 14 10 16 0 12 4 16 2 14 16 4 6
8 6 8 index 4
10
12 14 10 12 16 0 index 5
0 22 40 4 14 2 6 16 4 6 8
10 8 10 12 6 index 6
14 8 12 14 10 16 0 16 12
14 0 2index 7
4 2 40 16 6 2 0 6 8 4 2 8 10 6 4 10 12 8 6 12 14 10 8 14 16 12 10 16 0 14 12 0
2 16 14 2 4 0 16 4 6 2 0 6 8 10 8 4 2 12 10 6 4 14 12 8 6 16 14 10 8 0 16 12 10
2 0 14 12 4 2 16 14 6 4 0 16 8 6 2 0 10 8 4 2 12 10 6 4 14 12 8 6 16 14 10 8 0
16 12 10 2 0 14 16 2 12 4 0 4 14 6 2 6 16 8 4 8 0 10 6 10 2 12 8 12 4 14 10 14 1
6
16index 8
12 14 16 0 2 0 6 0 2 8 4 2 4 10 6 4 6 8 12 8 10 14 16 10 12 6 0 12 14 8 2 14 16
10 4 16 0 12 6 0 2 14 8 2 4 16 10 4 6 12 6 0 8 14 8 2 10 16 10 4 12
12 14 6 14 16 8 16 0 10 0 2 12 2 4 14 4 6 16 6 8 0 8 10 2 10 12 4 12 14 6 14 16
8 16 0 10
12 14 16 2 0 4 2 6 4 8 6 10 8 12 10 14 12 16 14
16 0 2 4 6 8 10 12 14 16 0 2 4 6 8 10 12 14 16 0 2 4 6 8 10 12 14 16 0 2 4 6 8 1
0 12 14 16 0 2 4 6 8 10 12 14 16
running reduce
running reduce
running reduce
running reduce
running reduce
running reduce
running reduce
running reduce
running reduce
QWaitCondition: Destroyed while threads are still waiting
Press <RETURN> to close this window... -
I didn't realize the cout issue... AFAIK cout is not thread safe. You should protect your access to it with a mutex