From 5d883649085fae19f70d2e2cadbd79b3ba276b9a Mon Sep 17 00:00:00 2001 From: kronbichler Date: Mon, 30 Dec 2013 16:37:35 +0000 Subject: [PATCH] Cleanup some code git-svn-id: https://svn.dealii.org/trunk@32130 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/deal.II/matrix_free/matrix_free.h | 172 +++++++++--------- 1 file changed, 84 insertions(+), 88 deletions(-) diff --git a/deal.II/include/deal.II/matrix_free/matrix_free.h b/deal.II/include/deal.II/matrix_free/matrix_free.h index ffc29f351e..5df978520e 100644 --- a/deal.II/include/deal.II/matrix_free/matrix_free.h +++ b/deal.II/include/deal.II/matrix_free/matrix_free.h @@ -1980,17 +1980,19 @@ namespace internal namespace partition { - template + template class CellWork : public tbb::task { public: CellWork (const Worker &worker_in, const unsigned int partition_in, - const internal::MatrixFreeFunctions::TaskInfo &task_info_in) + const internal::MatrixFreeFunctions::TaskInfo &task_info_in, + const bool is_blocked_in) : worker (worker_in), partition (partition_in), - task_info (task_info_in) + task_info (task_info_in), + is_blocked (is_blocked_in) {}; tbb::task *execute () { @@ -1998,7 +2000,7 @@ namespace internal (task_info.partition_color_blocks_data[partition], task_info.partition_color_blocks_data[partition+1]); worker(cell_range); - if (blocked==true) + if (is_blocked==true) dummy->spawn (*dummy); return NULL; } @@ -2009,92 +2011,82 @@ namespace internal const Worker &worker; const unsigned int partition; const internal::MatrixFreeFunctions::TaskInfo &task_info; + const bool is_blocked; }; - template + template class PartitionWork : public tbb::task { public: PartitionWork (const Worker &function_in, const unsigned int partition_in, - const internal::MatrixFreeFunctions::TaskInfo &task_info_in) + const internal::MatrixFreeFunctions::TaskInfo &task_info_in, + const bool is_blocked_in = false) : function (function_in), partition (partition_in), - task_info (task_info_in) + task_info (task_info_in), + is_blocked (is_blocked_in) {}; tbb::task *execute () { - if (false) - { - std::pair cell_range - (task_info.partition_color_blocks_data - [task_info.partition_color_blocks_row_index[partition]], - task_info.partition_color_blocks_data - [task_info.partition_color_blocks_row_index[partition+1]]); - function(cell_range); - } - else + tbb::empty_task *root = new( tbb::task::allocate_root() ) + tbb::empty_task; + unsigned int evens = task_info.partition_evens[partition]; + unsigned int odds = task_info.partition_odds[partition]; + unsigned int n_blocked_workers = + task_info.partition_n_blocked_workers[partition]; + unsigned int n_workers = task_info.partition_n_workers[partition]; + std::vector*> worker(n_workers); + std::vector*> blocked_worker(n_blocked_workers); + + root->set_ref_count(evens+1); + for (unsigned int j=0; j*> worker(n_workers); - std::vector*> blocked_worker(n_blocked_workers); - - root->set_ref_count(evens+1); - for (unsigned int j=0; jallocate_child()) + CellWork(function, task_info. + partition_color_blocks_row_index[partition]+2*j, + task_info, false); + if (j>0) { - worker[j] = new(root->allocate_child()) - CellWork(function,task_info. - partition_color_blocks_row_index - [partition] + 2*j, task_info); - if (j>0) - { - worker[j]->set_ref_count(2); - blocked_worker[j-1]->dummy = new(worker[j]->allocate_child()) - tbb::empty_task; - worker[j-1]->spawn(*blocked_worker[j-1]); - } - else - worker[j]->set_ref_count(1); - if (jset_ref_count(2); + blocked_worker[j-1]->dummy = new(worker[j]->allocate_child()) + tbb::empty_task; + worker[j-1]->spawn(*blocked_worker[j-1]); + } + else + worker[j]->set_ref_count(1); + if (jallocate_child()) + CellWork(function, task_info. + partition_color_blocks_row_index + [partition] + 2*j+1, task_info, true); + } + else + { + if (odds==evens) { - blocked_worker[j] = new(worker[j]->allocate_child()) - CellWork(function,task_info. - partition_color_blocks_row_index - [partition] + 2*j+1, task_info); + worker[evens] = new(worker[j]->allocate_child()) + CellWork(function, task_info. + partition_color_blocks_row_index[partition]+2*j+1, + task_info, false); + worker[j]->spawn(*worker[evens]); } else { - if (odds==evens) - { - worker[evens] = new(worker[j]->allocate_child()) - CellWork(function, - task_info. - partition_color_blocks_row_index - [partition]+2*j+1,task_info); - worker[j]->spawn(*worker[evens]); - } - else - { - tbb::empty_task *child = new(worker[j]->allocate_child()) - tbb::empty_task(); - worker[j]->spawn(*child); - } + tbb::empty_task *child = new(worker[j]->allocate_child()) + tbb::empty_task(); + worker[j]->spawn(*child); } } - - root->wait_for_all(); - root->destroy(*root); } - if (blocked==true) + + root->wait_for_all(); + root->destroy(*root); + if (is_blocked==true) dummy->spawn (*dummy); return NULL; } @@ -2105,6 +2097,7 @@ namespace internal const Worker &function; const unsigned int partition; const internal::MatrixFreeFunctions::TaskInfo &task_info; + const bool is_blocked; }; } // end of namespace partition @@ -2150,17 +2143,19 @@ namespace internal }; - template + template class PartitionWork : public tbb::task { public: PartitionWork (const Worker &worker_in, const unsigned int partition_in, - const internal::MatrixFreeFunctions::TaskInfo &task_info_in) + const internal::MatrixFreeFunctions::TaskInfo &task_info_in, + const bool is_blocked_in) : worker (worker_in), partition (partition_in), - task_info (task_info_in) + task_info (task_info_in), + is_blocked (is_blocked_in) {}; tbb::task *execute () { @@ -2168,7 +2163,7 @@ namespace internal upper = task_info.partition_color_blocks_data[partition+1]; parallel_for(tbb::blocked_range(lower,upper,1), CellWork (worker,task_info)); - if (blocked==true) + if (is_blocked==true) dummy->spawn (*dummy); return NULL; } @@ -2179,6 +2174,7 @@ namespace internal const Worker &worker; const unsigned int partition; const internal::MatrixFreeFunctions::TaskInfo &task_info; + const bool is_blocked; }; } // end of namespace color @@ -2273,9 +2269,9 @@ MatrixFree::cell_loop root->set_ref_count(evens+1); unsigned int n_blocked_workers = task_info.n_blocked_workers; unsigned int n_workers = task_info.n_workers; - std::vector*> + std::vector*> worker(n_workers); - std::vector*> + std::vector*> blocked_worker(n_blocked_workers); internal::MPIComCompress *worker_compr = new(root->allocate_child()) @@ -2286,8 +2282,8 @@ MatrixFree::cell_loop if (j>0) { worker[j] = new(root->allocate_child()) - internal::partition::PartitionWork - (func,2*j,task_info); + internal::partition::PartitionWork + (func,2*j,task_info,false); worker[j]->set_ref_count(2); blocked_worker[j-1]->dummy = new(worker[j]->allocate_child()) tbb::empty_task; @@ -2299,8 +2295,8 @@ MatrixFree::cell_loop else { worker[j] = new(worker_compr->allocate_child()) - internal::partition::PartitionWork - (func,2*j,task_info); + internal::partition::PartitionWork + (func,2*j,task_info,false); worker[j]->set_ref_count(2); internal::MPIComDistribute *worker_dist = new (worker[j]->allocate_child()) @@ -2310,16 +2306,16 @@ MatrixFree::cell_loop if (jallocate_child()) - internal::partition::PartitionWork - (func,2*j+1,task_info); + internal::partition::PartitionWork + (func,2*j+1,task_info,true); } else { if (odds==evens) { worker[evens] = new(worker[j]->allocate_child()) - internal::partition::PartitionWork - (func,2*j+1,task_info); + internal::partition::PartitionWork + (func,2*j+1,task_info,false); worker[j]->spawn(*worker[evens]); } else @@ -2348,8 +2344,8 @@ MatrixFree::cell_loop unsigned int n_blocked_workers = odds-(odds+evens+1)%2; unsigned int n_workers = task_info.partition_color_blocks_data.size()-1- n_blocked_workers; - std::vector*> worker(n_workers); - std::vector*> blocked_worker(n_blocked_workers); + std::vector*> worker(n_workers); + std::vector*> blocked_worker(n_blocked_workers); unsigned int worker_index = 0, slice_index = 0; unsigned int spawn_index = 0, spawn_index_new = 0; int spawn_index_child = -2; @@ -2362,10 +2358,10 @@ MatrixFree::cell_loop spawn_index_new = worker_index; if (part == 0) worker[worker_index] = new(worker_compr->allocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,false); else worker[worker_index] = new(root->allocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,false); slice_index++; for (; slice_index::cell_loop worker[worker_index]->set_ref_count(1); worker_index++; worker[worker_index] = new (worker[worker_index-1]->allocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,false); } worker[worker_index]->set_ref_count(2); if (part>0) @@ -2402,14 +2398,14 @@ MatrixFree::cell_loop if (partallocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,true); slice_index++; if (slice_index< task_info.partition_color_blocks_row_index[part+1]) { blocked_worker[part/2]->set_ref_count(1); worker[worker_index] = new(blocked_worker[part/2]->allocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,false); slice_index++; } else @@ -2428,7 +2424,7 @@ MatrixFree::cell_loop worker_index++; } worker[worker_index] = new (worker[worker_index-1]->allocate_child()) - internal::color::PartitionWork(func,slice_index,task_info); + internal::color::PartitionWork(func,slice_index,task_info,false); } spawn_index_child = worker_index; worker_index++; -- 2.39.5