0

I wrote my own merge sort, that works fine in one thread, but when I try to run it as parallel I get an error.

void GameModel::mergesort_mt3(QVector<QPair<int,Matrix>>::iterator begin, 
                          QVector<QPair<int,Matrix>>::iterator end,
               unsigned int N)
{
auto len = std::distance(begin, end);
if (len <= 1024 || N < 2)
{
    std::sort(begin,end);
    return;
}
QVector<QPair<int,Matrix>>::iterator mid = std::next(begin, len/2);
//auto fn = QtConcurrent::run(mergesort_mt3, begin, mid, N-2 );
mergesort_mt3(begin, mid, N-2);
mergesort_mt3(mid, end, N-2);
//fn.waitForFinished();
std::inplace_merge(begin, mid, end);
}

When I use the commented code I get this error:

error: no matching function for call to 'run(<unresolved overloaded function 
type>, QPair<int, QPair<QVector<QVector<int> >, int> >*&, QPair<int, 
QPair<QVector<QVector<int> >, int> >*&, unsigned int)'
 auto fn = QtConcurrent::run(mergesort_mt3, begin, mid, N-2 );
                                                            ^
In file included from 
C:/Qt/5.9.1/mingw53_32/include/QtConcurrent/QtConcurrent:14:0,
             from ..\Game15\model.cpp:2:
note: 
candidate: template<class T> QFuture<T> QtConcurrent::run(T (*)())
QFuture<T> run(T (*functionPointer)())

Any idea, what I did wrong?

1 Answer 1

1

That should be something like

auto fn = QtConcurrent::run(this, GameModel::mergesort_mt3, begin, mid, N-2 );

See Qt member function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.