Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent CI test failure #58

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
TODO.md
doc/benchmarks/**
docker/dealii-master-focal-root/**
docker/dealii-weak_forms-dev/**
60 changes: 57 additions & 3 deletions cmake/checks/check_02_compiler_features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@
## ---------------------------------------------------------------------


# Save the current flags
SET(CMAKE_REQUIRED_LIBRARIES_SAVED ${CMAKE_REQUIRED_LIBRARIES})
SET(CMAKE_REQUIRED_INCLUDES_SAVED ${CMAKE_REQUIRED_INCLUDES})
SET(CMAKE_REQUIRED_FLAGS_SAVED ${CMAKE_REQUIRED_FLAGS})

# Add deal.II's flags to the current project's
# (which should be empty unless the user specifies otherwise)
LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${DEAL_II_LIBRARIES})
LIST(APPEND CMAKE_REQUIRED_INCLUDES ${DEAL_II_INCLUDE_DIRS})
LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS})

IF("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS_RELEASE})
ELSEIF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
LIST(APPEND CMAKE_REQUIRED_FLAGS ${DEAL_II_CXX_FLAGS_DEBUG})
ELSE()
MESSAGE(FATAL_ERROR "CMAKE_BUILD_TYPE doesn't match either Release or Debug!")
ENDIF()

#
# Check whether division by zero in a vectorized array results in
# a floating point exception.
Expand All @@ -29,6 +44,16 @@ WF_CHECK_CXX_SOURCE_RUNS(
"
#include <deal.II/base/vectorization.h>
using namespace dealii;
class BinaryOp
{
public:
template <typename T>
T
operator()(const T &num, const T &den) const
{
return num/den;
}
};
template <typename Number, std::size_t width>
void
do_test()
Expand All @@ -38,7 +63,8 @@ WF_CHECK_CXX_SOURCE_RUNS(
{
const Vec_t num = 1.0;
const Vec_t den = 0.0;
const auto result = num / den;
auto result = num / den;
result = BinaryOp()(num, den);
(void)result;
}
}
Expand Down Expand Up @@ -73,13 +99,25 @@ WF_CHECK_CXX_SOURCE_RUNS(
# results in a floating point exception.
#
# The test is multiple times to ensure that the failure is not in
# any way sporadic.
# any way sporadic. The tested value 6.916...e-310 comes from some
# backtraced output of a test failure on a Docker image.
#
WF_CHECK_CXX_SOURCE_RUNS(
"
#include <deal.II/base/vectorization.h>
#include <limits>
using namespace dealii;
class UnaryOp
{
public:
template <typename T>
T
operator()(const T &value) const
{
using namespace std;
return sqrt(value);
}
};
template <typename Number, std::size_t width>
void
do_test()
Expand All @@ -90,8 +128,13 @@ WF_CHECK_CXX_SOURCE_RUNS(
{
Vec_t val = 0.0;
auto result = sqrt(val);
result = UnaryOp()(val);
val = std::numeric_limits<Number>::epsilon();
result = sqrt(val);
result = UnaryOp()(val);
val = 6.9161116785120245e-310;
result = sqrt(val);
result = UnaryOp()(val);
(void)result;
}
}
Expand All @@ -111,11 +154,22 @@ WF_CHECK_CXX_SOURCE_RUNS(
do_test<double, 2>();
do_test<float, 4>();
#endif

// All indications are that _mm_sqrt_pd() sporadically segfaults with zero input vector.
#if DEAL_II_VECTORIZATION_WIDTH_IN_BITS == 128
static_assert(false, 'Problematic vectorization width detected.');
#endif

do_test<double, 1>();
do_test<float, 1>();

return 0;
}
"
WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO)
WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO)


# Restore all flags
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVED})
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVED})
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVED})
8 changes: 4 additions & 4 deletions include/weak_forms/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace WeakForms
MeshWorker::assemble_own_cells);

if (mpi_communicator)
dealii::Utilities::MPI::sum(integral, *mpi_communicator);
integral = dealii::Utilities::MPI::sum(integral, *mpi_communicator);

return integral;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ namespace WeakForms
boundary_worker);

if (mpi_communicator)
dealii::Utilities::MPI::sum(integral, *mpi_communicator);
integral = dealii::Utilities::MPI::sum(integral, *mpi_communicator);

return integral;
}
Expand Down Expand Up @@ -869,7 +869,7 @@ namespace WeakForms
MeshWorker::assemble_own_cells);

if (mpi_communicator)
dealii::Utilities::MPI::sum(integral, *mpi_communicator);
integral = dealii::Utilities::MPI::sum(integral, *mpi_communicator);

return integral;
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ namespace WeakForms
boundary_worker);

if (mpi_communicator)
dealii::Utilities::MPI::sum(integral, *mpi_communicator);
integral = dealii::Utilities::MPI::sum(integral, *mpi_communicator);

return integral;
}
Expand Down
24 changes: 9 additions & 15 deletions include/weak_forms/unary_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -1608,25 +1608,19 @@ private: \
using namespace std;

#ifdef WEAK_FORMS_VECTORIZATION_FPE_SQRT_OF_ZERO
// We need to check if the vector is a zero vector. If so, simply
// avoid the operation that would result in an FPE as we know the
// result already.
bool has_non_zero_value = false;
// Avoid calls to _mm_sqrt_pd():
// All indications are that it segfaults, typically with a zero
// input vector.
vectorized_value_type<ScalarType, width> result;

DEAL_II_OPENMP_SIMD_PRAGMA
for (unsigned int v = 0; v < width; v++)
{
if (std::abs(value[v]) >
dealii::internal::NumberType<ScalarType>::value(
10.0 * std::numeric_limits<ScalarType>::epsilon()))
{
has_non_zero_value = true;
}
}
if (!has_non_zero_value)
return vectorized_value_type<ScalarType, width>{};
#endif
result[v] = sqrt(value[v]);

return result;
#else
return sqrt(value);
#endif
}
};

Expand Down
2 changes: 2 additions & 0 deletions tests/weak_forms/prm/parameters-step-curl_curl.prm
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ subsection Nonlinear solver
# Nonlinear solver residual
set Residual = 1e-9

set Min iterations = 3

set Max iterations = 10
end
39 changes: 39 additions & 0 deletions tests/weak_forms/step-transient_curl_curl-variant_02a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,45 @@ namespace StepTransientCurlCurl
this->qf_cell_esp,
update_gradients);

FEFaceValues<dim> fe_face_values_esp(this->mapping,
this->fe_esp,
this->qf_face_esp,
update_gradients | update_normal_vectors | update_JxW_values);

// Compute total current flowing through inlet boundary
double I_total = 0;
{
typename DoFHandler<dim>::active_cell_iterator
cell = this->dof_handler_esp.begin_active(),
endc = this->dof_handler_esp.end();
for (; cell != endc; ++cell)
{
if (cell->is_locally_owned() == false)
continue;
for (const auto &face : cell->face_iterators())
{
if (face->at_boundary() && face->boundary_id() == this->parameters.bid_wire_inlet)
{
fe_face_values_esp.reinit(cell, face);
const std::vector<Tensor<1, dim>> & normals = fe_face_values_esp.get_normal_vectors();
std::vector<Tensor<1, dim>> source_values(fe_face_values_esp.n_quadrature_points);
fe_face_values_esp[this->esp_extractor].get_function_gradients(
this->solution_esp, source_values);

for (const unsigned int q_point : fe_face_values_esp.quadrature_point_indices())
{
source_values[q_point] *= -1.0;
const Tensor<1, dim> &J_f = source_values[q_point];
const Tensor<1, dim> &N = normals[q_point];
I_total += (J_f*N) * fe_face_values_esp.JxW(q_point);
}
}
}
}
}
I_total = dealii::Utilities::MPI::sum(I_total, this->mpi_communicator);
deallog << "I_total: " << I_total << std::endl;

typename DoFHandler<dim>::active_cell_iterator
cell = this->dof_handler_mvp.begin_active(),
endc = this->dof_handler_mvp.end();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,86 @@

DEAL::I_total: -1.98873782
DEAL::I_total: -1.98873782
DEAL::I_total: -1.98873782
DEAL::I_total: -1.98873782
DEAL::Timestep: 0 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 4.61581794e-06 -9.56896981e-06 -2.13298753e-21 ; J_eddy (axial): 236.178640 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.63722304e-06 -6.79177661e-06 -9.29446723e-22 ; J_eddy (axial): 3.14211193e-06 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 4.61581794e-06 -9.56896981e-06 1.16231973e-22 ; J_eddy (axial): 236.178640 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.63722304e-06 -6.79177661e-06 -1.14263864e-22 ; J_eddy (axial): 3.14211189e-06 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 0 ; Cycle: 1
DEAL:: ; Within wire: 1 ; B: 2.53135698e-06 -1.11267136e-05 -1.55306726e-20 ; J_eddy (axial): 237.827569 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.03564110e-06 -9.55446258e-06 6.61313418e-21 ; J_eddy (axial): 3.84595299e-06 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 2.53135698e-06 -1.11267136e-05 -3.15452678e-22 ; J_eddy (axial): 237.827569 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.03564110e-06 -9.55446258e-06 -2.40714949e-22 ; J_eddy (axial): 3.84595100e-06 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 1 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.13416573e-06 -1.37930118e-05 -5.44117145e-21 ; J_eddy (axial): 55.4961666 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.50748484e-06 -1.17820055e-05 1.42871597e-21 ; J_eddy (axial): 8.96208088e-07 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.13416573e-06 -1.37930118e-05 -4.65440152e-22 ; J_eddy (axial): 55.4961666 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.50748484e-06 -1.17820055e-05 -2.23651199e-22 ; J_eddy (axial): 8.96209655e-07 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 2 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.27600221e-06 -1.44207039e-05 -9.62728373e-22 ; J_eddy (axial): 13.0436231 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.61833934e-06 -1.23055350e-05 2.05985495e-22 ; J_eddy (axial): 2.10624092e-07 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.27600221e-06 -1.44207039e-05 -1.44215386e-22 ; J_eddy (axial): 13.0436231 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.61833934e-06 -1.23055350e-05 -1.12869605e-22 ; J_eddy (axial): 2.10625098e-07 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 3 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.30936216e-06 -1.45683440e-05 -4.55362927e-22 ; J_eddy (axial): 3.06743096 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.64440923e-06 -1.24286584e-05 1.88523346e-23 ; J_eddy (axial): 4.95318284e-08 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.30936216e-06 -1.45683440e-05 1.19427432e-22 ; J_eddy (axial): 3.06743096 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.64440923e-06 -1.24286584e-05 3.90628414e-22 ; J_eddy (axial): 4.95312749e-08 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 4 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31720824e-06 -1.46030683e-05 -3.96641182e-22 ; J_eddy (axial): 0.721261992 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65054066e-06 -1.24576161e-05 3.26313768e-23 ; J_eddy (axial): 1.16470979e-08 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31720824e-06 -1.46030683e-05 2.28718671e-23 ; J_eddy (axial): 0.721261992 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65054066e-06 -1.24576161e-05 1.42527483e-22 ; J_eddy (axial): 1.16471478e-08 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 5 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31905359e-06 -1.46112353e-05 -6.48357735e-22 ; J_eddy (axial): 0.169460725 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65198274e-06 -1.24644268e-05 -8.13720193e-23 ; J_eddy (axial): 2.73635533e-09 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31905359e-06 -1.46112353e-05 7.15698638e-22 ; J_eddy (axial): 0.169460725 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65198274e-06 -1.24644268e-05 1.59931874e-22 ; J_eddy (axial): 2.73634142e-09 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 6 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31948760e-06 -1.46131561e-05 1.38743392e-22 ; J_eddy (axial): 0.0396804632 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65232191e-06 -1.24660286e-05 -1.66358956e-22 ; J_eddy (axial): 6.40906458e-10 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31948760e-06 -1.46131561e-05 3.31470012e-22 ; J_eddy (axial): 0.0396804632 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65232191e-06 -1.24660286e-05 -4.49528122e-23 ; J_eddy (axial): 6.40790458e-10 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 7 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31958968e-06 -1.46136078e-05 3.29709022e-22 ; J_eddy (axial): 0.00915692866 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65240168e-06 -1.24664053e-05 6.22040570e-23 ; J_eddy (axial): 1.47915425e-10 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31958968e-06 -1.46136078e-05 4.74045577e-22 ; J_eddy (axial): 0.00915692867 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65240168e-06 -1.24664053e-05 -3.66948419e-23 ; J_eddy (axial): 1.47629544e-10 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 8 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31961369e-06 -1.46137141e-05 -4.10359132e-24 ; J_eddy (axial): 0.00197797717 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242044e-06 -1.24664940e-05 2.74721941e-22 ; J_eddy (axial): 3.18269209e-11 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31961369e-06 -1.46137141e-05 1.07200669e-22 ; J_eddy (axial): 0.00197797717 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242044e-06 -1.24664940e-05 -1.73290472e-22 ; J_eddy (axial): 3.24535248e-11 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 9 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31961934e-06 -1.46137391e-05 4.16130009e-22 ; J_eddy (axial): 0.000289531007 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242485e-06 -1.24665148e-05 -2.21322621e-22 ; J_eddy (axial): 4.81064685e-12 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31961934e-06 -1.46137391e-05 6.16688996e-22 ; J_eddy (axial): 0.000289531007 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242485e-06 -1.24665148e-05 -1.20243444e-22 ; J_eddy (axial): 4.56045290e-12 ; J_free (axial): 0.00000000
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::I_total: -1.98873821
DEAL::Timestep: 10 ; Cycle: 0
DEAL:: ; Within wire: 1 ; B: 3.31962066e-06 -1.46137450e-05 1.08717059e-21 ; J_eddy (axial): -0.000107581363 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242589e-06 -1.24665197e-05 3.40969838e-22 ; J_eddy (axial): -1.68748702e-12 ; J_free (axial): 0.00000000
DEAL:: ; Within wire: 1 ; B: 3.31962066e-06 -1.46137450e-05 4.43843791e-22 ; J_eddy (axial): -0.000107581362 ; J_free (axial): 5092.95818
DEAL:: ; Within wire: 0 ; B: 2.65242589e-06 -1.24665197e-05 -1.84550430e-24 ; J_eddy (axial): -1.50795949e-12 ; J_free (axial): 0.00000000
DEAL::OK
Loading