From 4edb3b58429032696d31d2cb12874a8b4e2de42d Mon Sep 17 00:00:00 2001 From: kronbichler Date: Wed, 19 Mar 2014 13:10:36 +0000 Subject: [PATCH] Disable multithreading part in case threads are not used git-svn-id: https://svn.dealii.org/trunk@32667 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/lac/vector.templates.h | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/deal.II/include/deal.II/lac/vector.templates.h b/deal.II/include/deal.II/lac/vector.templates.h index 3f64f3e5ce..881dd58c5c 100644 --- a/deal.II/include/deal.II/lac/vector.templates.h +++ b/deal.II/include/deal.II/lac/vector.templates.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -586,7 +587,8 @@ namespace internal const Number2 *Y, const ResultType power, const size_type vec_size, - ResultType &result) + ResultType &result, + const int depth = -1) { if (vec_size <= 4096) { @@ -672,29 +674,39 @@ namespace internal result = outer_results[0]; } #ifdef DEAL_II_WITH_THREADS - else if (vec_size > 4 * internal::Vector::minimum_parallel_grain_size) + else if (multithread_info.n_threads() > 1 && + vec_size > 4 * internal::Vector::minimum_parallel_grain_size && + depth != 0) { - // split the vector into smaller pieces to be - // worked on recursively and create tasks for - // them. Make pieces divisible by 1024. + // split the vector into smaller pieces to be worked on recursively + // and create tasks for them. Make pieces divisible by 1024. const size_type new_size = (vec_size / 4096) * 1024; ResultType r0, r1, r2, r3; + + // find out how many recursions we should make (avoid too deep + // hierarchies of tasks on large vectors), max use 8 * + // multithread_info.n_threads() + int next_depth = depth; + if (depth == -1) + next_depth = 8 * multithread_info.n_threads(); + next_depth /= 4; + Threads::TaskGroup<> task_group; task_group += Threads::new_task(&accumulate, - op, X, Y, power, new_size, r0); + op, X, Y, power, new_size, r0, next_depth); task_group += Threads::new_task(&accumulate, op, X+new_size, Y+new_size, power, - new_size, r1); + new_size, r1, next_depth); task_group += Threads::new_task(&accumulate, op, X+2*new_size, Y+2*new_size, power, - new_size, r2); + new_size, r2, next_depth); task_group += Threads::new_task(&accumulate, op, X+3*new_size, Y+3*new_size, power, - vec_size-3*new_size, r3); + vec_size-3*new_size, r3, next_depth); task_group.join_all(); r0 += r1; r2 += r3; -- 2.39.5