mercredi 25 février 2015

asynchronous function producing inconsistent results

I have this function that is supposed to break up the first layer in matrix determinant calculations performing it asynchronously. Unfortunately, it only spits out the correct answer on occasion. The values represented by futures[i].get() change each time I run the code. I'm new to multithreading.



double async_determinant() const {

vector<future<double>> futures;

double val = 0;
for (int i = 0; i < rows; i++) {
futures.push_back(std::async(std::launch::async, [&] {return minor(i,0).determinant();}) );
}
for (int i = 0; i < rows; i++) {
val += (i % 2 ? -1 : 1)
* data[i][0]
* futures[i].get();
}
return val;
}

Aucun commentaire:

Enregistrer un commentaire