diff --git a/include/sampleflow/producers/differential_evaluation_mh.h b/include/sampleflow/producers/differential_evaluation_mh.h index 11f74e2..a0b28af 100644 --- a/include/sampleflow/producers/differential_evaluation_mh.h +++ b/include/sampleflow/producers/differential_evaluation_mh.h @@ -196,7 +196,7 @@ namespace SampleFlow // "generations" and an inner loop over the individual chains. We // exit from the inner loop when we have reached the desired number of // samples. - for (types::sample_index generation=0; true; ++generation) + for (types::sample_index generation=0; generation * n_chains < n_samples; ++generation) { // A vector that will contain the std::future objects used to // hold results of either synchronous or asynchronous @@ -315,11 +315,10 @@ namespace SampleFlow // guarantees a stable order. for (typename std::vector::size_type chain = 0; chain < n_chains; ++chain) { - // Return if we have already generated the desired number of - // samples. The ScopeExit object above also makes sure that - // we flush the downstream consumers. + // Break the loop if we have already generated the desired number of + // samples: if (generation * n_chains + chain >= n_samples) - return; + break; // Wait for the futures to be ready. Then output the new sample // (which may of course be equal to the old sample).