samedi 30 novembre 2019

C++11 sort() in parallel using threads

I am trying to sort an array (1,000,000 elements) in parallel using threads but I am getting the error error: invalid use of void expression. For the sort function I pass where I want it to start, where I want it to end, and my comparator function. Below is example code:

thread th1(sort(array.begin(), array.begin() + 500000, compare));
thread th2(sort(array.begin() + 500001, array.end(), compare));

Note that without threads it works, but I am trying to speed the sorting up:

sort(array.begin(), array.begin() + 500000, compare);

I am new to multithreading, so let me know what you guys suggest.

Aucun commentaire:

Enregistrer un commentaire