Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MapReduce's QWaitCondition: Destroyed while threads are still waiting
QtWS25 Last Chance

MapReduce's QWaitCondition: Destroyed while threads are still waiting

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 5.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dmsm
    wrote on last edited by
    #1

    @#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]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dmsm
        wrote on last edited by
        #3

        @ 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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @ watcher.QFutureWatcher::waitForFinished();@

          should be just

          @watcher.waitForFinished();@

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dmsm
            wrote on last edited by
            #5

            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.)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dmsm
              wrote on last edited by
              #6
              1. reduceResult.append(part);

              I think this may be the problem, because I am creating a vector of vectors, but I haven't seen anyone use mapreduce in such a way.

              I am trying to do matrix addition.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dmsm
                wrote on last edited by
                #7

                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...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  I didn't realize the cout issue... AFAIK cout is not thread safe. You should protect your access to it with a mutex

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved