From: Wolfgang Bangerth Date: Fri, 6 Nov 2015 22:13:43 +0000 (-0600) Subject: Improve loop nesting. X-Git-Tag: v8.4.0-rc2~242^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d501b1864a5377d488c1f3bdd385ef471337d8e5;p=dealii.git Improve loop nesting. We had a number of places of the form for (...tight loop...) if (constant condition) data update; The compiler almost certainly can hoist the condition out of the loop, but why make it this complicated for the compiler. I also find the code easier to read because the loop is really only over a counting index and does not carry any particular meaning at a level higher than the if-statement. --- diff --git a/include/deal.II/fe/fe_poly.templates.h b/include/deal.II/fe/fe_poly.templates.h index da43087d1c..cd3e28dbd0 100644 --- a/include/deal.II/fe/fe_poly.templates.h +++ b/include/deal.II/fe/fe_poly.templates.h @@ -249,41 +249,44 @@ fill_fe_values (const Mapping &ma const UpdateFlags flags(fe_data.update_each); - for (unsigned int k=0; kdofs_per_cell; ++k) + if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (fe_data.shape_gradients[k], + mapping_covariant, + mapping_internal, + output_data.shape_gradients[k]); + + if (flags & update_hessians && cell_similarity != CellSimilarity::translation) { - if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + mapping.transform (fe_data.shape_hessians[k], + mapping_covariant_gradient, + mapping_internal, + output_data.shape_hessians[k]); + + for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (fe_data.shape_3rd_derivatives[k], + mapping_covariant_hessian, mapping_internal, - output_data.shape_gradients[k]); - - if (flags & update_hessians && cell_similarity != CellSimilarity::translation) - { - mapping.transform (fe_data.shape_hessians[k], - mapping_covariant_gradient, - mapping_internal, - output_data.shape_hessians[k]); - - for (unsigned int i=0; idofs_per_cell; ++k) + correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); } } @@ -321,45 +324,48 @@ fill_fe_face_values (const Mapping const UpdateFlags flags(fe_data.update_each); - for (unsigned int k=0; kdofs_per_cell; ++k) + if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_gradients[k], offset, quadrature.size()), + mapping_covariant, + mapping_internal, + output_data.shape_gradients[k]); + + if (flags & update_hessians) { - if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_hessians[k], + offset, + quadrature.size()), + mapping_covariant_gradient, + mapping_internal, + output_data.shape_hessians[k]); + + for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_3rd_derivatives[k], + offset, + quadrature.size()), + mapping_covariant_hessian, mapping_internal, - output_data.shape_gradients[k]); - - if (flags & update_hessians) - { - mapping.transform (make_slice(fe_data.shape_hessians[k], - offset, - quadrature.size()), - mapping_covariant_gradient, - mapping_internal, - output_data.shape_hessians[k]); - - for (unsigned int i=0; idofs_per_cell; ++k) + correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); } } @@ -397,48 +403,53 @@ fill_fe_subface_values (const Mapping const UpdateFlags flags(fe_data.update_each); - for (unsigned int k=0; kdofs_per_cell; ++k) + if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_gradients[k], offset, quadrature.size()), + mapping_covariant, + mapping_internal, + output_data.shape_gradients[k]); + + if (flags & update_hessians) { - if (flags & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_hessians[k], + offset, + quadrature.size()), + mapping_covariant_gradient, + mapping_internal, + output_data.shape_hessians[k]); + + for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; idofs_per_cell; ++k) + mapping.transform (make_slice(fe_data.shape_3rd_derivatives[k], + offset, + quadrature.size()), + mapping_covariant_hessian, mapping_internal, - output_data.shape_gradients[k]); - - if (flags & update_hessians) - { - mapping.transform (make_slice(fe_data.shape_hessians[k], - offset, - quadrature.size()), - mapping_covariant_gradient, - mapping_internal, - output_data.shape_hessians[k]); - - for (unsigned int i=0; idofs_per_cell; ++k) + correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); } } + + template inline void FE_Poly:: diff --git a/include/deal.II/fe/fe_poly_face.templates.h b/include/deal.II/fe/fe_poly_face.templates.h index 972118fcd8..2e5a78a164 100644 --- a/include/deal.II/fe/fe_poly_face.templates.h +++ b/include/deal.II/fe/fe_poly_face.templates.h @@ -197,13 +197,14 @@ fill_fe_subface_values (const Mapping &, const unsigned int offset = subface*quadrature.size(); if (fe_data.update_each & update_values) - for (unsigned int i=0; idofs_per_cell; ++k) + { + for (unsigned int k=0; kdofs_per_cell; ++k) + for (unsigned int i=0; i &, values, grads, grad_grads, empty_vector_of_3rd_order_tensors, empty_vector_of_4th_order_tensors); - for (unsigned int k=0; kdofs_per_cell; ++k) - { - if (fe_data.update_each & update_values) - output_data.shape_values[k][i] = values[k]; - if (fe_data.update_each & update_gradients) - output_data.shape_gradients[k][i] = grads[k]; - if (fe_data.update_each & update_hessians) - output_data.shape_hessians[k][i] = grad_grads[k]; - } + + if (fe_data.update_each & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_values[k][i] = values[k]; + + if (fe_data.update_each & update_gradients) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_gradients[k][i] = grads[k]; + + if (fe_data.update_each & update_hessians) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_hessians[k][i] = grad_grads[k]; } } @@ -351,15 +354,18 @@ fill_fe_face_values (const Mapping &, values, grads, grad_grads, empty_vector_of_3rd_order_tensors, empty_vector_of_4th_order_tensors); - for (unsigned int k=0; kdofs_per_cell; ++k) - { - if (fe_data.update_each & update_values) - output_data.shape_values[k][i] = values[k]; - if (fe_data.update_each & update_gradients) - output_data.shape_gradients[k][i] = grads[k]; - if (fe_data.update_each & update_hessians) - output_data.shape_hessians[k][i] = grad_grads[k]; - } + + if (fe_data.update_each & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_values[k][i] = values[k]; + + if (fe_data.update_each & update_gradients) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_gradients[k][i] = grads[k]; + + if (fe_data.update_each & update_hessians) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_hessians[k][i] = grad_grads[k]; } } @@ -395,15 +401,18 @@ fill_fe_subface_values (const Mapping &, values, grads, grad_grads, empty_vector_of_3rd_order_tensors, empty_vector_of_4th_order_tensors); - for (unsigned int k=0; kdofs_per_cell; ++k) - { - if (fe_data.update_each & update_values) - output_data.shape_values[k][i] = values[k]; - if (fe_data.update_each & update_gradients) - output_data.shape_gradients[k][i] = grads[k]; - if (fe_data.update_each & update_hessians) - output_data.shape_hessians[k][i] = grad_grads[k]; - } + + if (fe_data.update_each & update_values) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_values[k][i] = values[k]; + + if (fe_data.update_each & update_gradients) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_gradients[k][i] = grads[k]; + + if (fe_data.update_each & update_hessians) + for (unsigned int k=0; kdofs_per_cell; ++k) + output_data.shape_hessians[k][i] = grad_grads[k]; } }