Hello Ted,
the variable index contains other values now. In the sequential version
you set it to zero before you loop over the intervals, but in the
parallel version you set it to zero at the beginning of every chunk of
intervals.
Best Regards,
Markus
Am 17.12.10 16:45, schrieb Ted Kord:
Hi
I have a loop like so:
<Original>
int index = 0;
for(int step = 0; iteration_time <= 0.5*time; ++step) {
iteration_time += some_step;
for (std::vector<some_object> p = test.begin(); p !=
test.end(); ++p) {
do some stuff
old_solution_u(index) = do_some_calculation();
++index;
}
}
</Original>
'old_solution_u' is a vector of solution values. The loop writes
values into it in exactly the same order as the support points.
I'd like to use multithreading, so I converted it, following 'step 9'
like so:
template <int dim>
void TestEquation<dim>::iterate()
{
const unsigned int n_threads = multithread_info.n_default_threads;
Threads::ThreadGroup<> threads;
std::vector<std::pair<TestIterator, TestIterator> >
thread_ranges = Threads::split_range<TestIterator>( test.begin(),
test.end(),
n_threads );
for ( unsigned int thread = 0; thread < n_threads; ++thread )
threads += Threads::new_thread
(&TestEquation<dim>::test_iteration_interval,
*this,
time,
thread_ranges[thread].first,
thread_ranges[thread].second);
threads.join_all();
}
template <int dim>
void TestEquation<dim>::test_iteration_interval(double time,
TestIterator &begin, TestIterator &end) {
TestIterator p;
for(int step = 0, index = 0; iteration_time <= 0.5*time; ++step,
++index) {
iteration_time += some_step;
for (p = begin; p != end; ++p) {
do some stuff
write_lock.acquire();
old_solution_u(index) = do_some_calculation();
write_lock.release();
}
}
}
The multithreading works brilliantly but the results are incorrect.
Are there errors in how I've done it above?
--
Many thanks,
Ted
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii