I would like to multithread a for loop but I have some variable inside my loop what need to know the previous state. Well it's not quite easy to explain.
Here is an exemple :
double mu1 = 0, q1 = 0;
double max_sigma = 0, max_val = 0;
for( i = 0; i < N; i++ )
{
double p_i, q2, mu2, sigma;
p_i = h[i]*scale;
mu1 *= q1;
q1 += p_i;
q2 = 1. - q1;
if(std::min(q1,q2) < FLT_EPSILON || std::max(q1,q2) > 1. -FLT_EPSILON )
continue;
mu1 = (mu1 + i*p_i)/q1;
mu2 = (mu - q1*mu1)/q2;
sigma = q1*q2*(mu1 - mu2)*(mu1 - mu2);
if( sigma > max_sigma )
{
max_sigma = sigma;
max_val = i;
}
}
scale
is a double
scalar value.
h
is a std::vector<std::uint64_t>
If I split the range in sevral part for process any sub I can locally (in each thread) compute first p_i
.
But I don't see how I could determine the value mu1
.
So my question is : Is there any way to determine mu1
at the begining of a thread for a range B without prior of the result of mu1
what have been processed in a thread for a range A? If yes, how?
Aucun commentaire:
Enregistrer un commentaire