Skip to content

default TA_ERROR to throw if building unit tests #234

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

Merged
merged 10 commits into from
Dec 22, 2020
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ build:
script:
- mkdir build
- cd build
- cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/gitlab-ci.cmake
- cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/gitlab-ci.cmake
-DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-D${TA_PYTHON}
-D${ENABLE_MKL}
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,15 @@ check_type_size("long long" TILEDARRAY_HAS_LONG_LONG LANGUAGE CXX)
# convert string values of TA_ERROR to numerical values expected by TA_DEFAULT_ERROR
##########################
set (TA_DEFAULT_ERROR 3) # default is to abort so that it works with or without NDEBUG
# assert when CMAKE_BUILD_TYPE is Debug or RelWithDebugUnfo
# assert when CMAKE_BUILD_TYPE is Debug or RelWithDebInfo
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELWITHDEBINFO)$")
set (TA_DEFAULT_ERROR 2)
endif()
# if building unit tests default to throw to be able to test TA_ASSERT statements
if (TA_BUILD_UNITTEST)
set (TA_DEFAULT_ERROR 1)
endif(TA_BUILD_UNITTEST)

if (TA_ERROR STREQUAL none)
set (TA_DEFAULT_ERROR 0)
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ support may be added.
## Expert configure options:

* `TA_EXPERT` -- Set to `ON` to disable automatic installation of prerequisites. Useful for experts, hence the name. [Default=OFF].
* `TA_ERROR` -- Set to `none` to disable `TA_ASSERT` assertions, `throw` to cause `TA_ASSERT` assertions to throw, `abort` to cause `TA_ASSERT` assertions to abort, or `assert` to cause `TA_ASSERT` assertions to use C++ assert.
* `TA_ERROR` -- Set to `none` to disable `TA_ASSERT` assertions, `throw` to cause `TA_ASSERT` assertions to throw, `abort` to cause `TA_ASSERT` assertions to abort, or `assert` to cause `TA_ASSERT` assertions to use C++ assert. The default is `throw` if `TA_BUILD_UNITTEST` is set, else is `assert` if `CMAKE_BUILD_TYPE` is `Debug` or `RelWithDebInfo`, else is `abort`.
* `TA_TRACE_TASKS` -- Set to `ON` to enable tracing of MADNESS tasks using custom task tracer. Note that standard profilers/tracers are generally useless (except in the trivial cases) with MADWorld-based programs since the submission context of tasks is not captured by standard tracing tools; this makes it impossible in a nontrivial program to attribute tasks to source code. WARNING: task tracing his will greatly increase the memory requirements. [Default=OFF].
* `TA_ENABLE_RANGEV3` -- Set to `ON` to find or fetch the Range-V3 library and enable additional tests of TA components with constructs anticipated to be supported in the future. [Default=OFF].
* `TA_SIGNED_1INDEX_TYPE` -- Set to `OFF` to use unsigned 1-index coordinate type (default for TiledArray 1.0.0-alpha.2 and older). The default is `ON`, which enables the use of negative indices in coordinates.
Expand Down
2 changes: 0 additions & 2 deletions bin/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ if [ "$BUILD_TYPE" = "Debug" ]; then
-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DTA_PYTHON="${TA_PYTHON}" \
-DTA_BUILD_UNITTEST=ON \
-DTA_ERROR="throw" \
-DENABLE_SCALAPACK=ON

else
Expand Down Expand Up @@ -128,7 +127,6 @@ else
-DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \
-DTA_PYTHON="${TA_PYTHON}" \
-DTA_BUILD_UNITTEST=ON \
-DTA_ERROR="throw" \
-DENABLE_SCALAPACK=ON

fi
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions src/TiledArray/conversions/btas.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ DistArray_ btas_tensor_to_array(World& world,
bool replicated = false) {
// Test preconditions
const auto rank = trange.tiles_range().rank();
TA_USER_ASSERT(rank == src.range().rank(),
"TiledArray::btas_tensor_to_array(): rank of destination "
"trange does not match the rank of source BTAS tensor.");
TA_ASSERT(rank == src.range().rank() &&
"TiledArray::btas_tensor_to_array(): rank of destination "
"trange does not match the rank of source BTAS tensor.");
auto dst_range_extents = trange.elements_range().extent();
for (std::remove_const_t<decltype(rank)> d = 0; d != rank; ++d) {
TA_USER_ASSERT(dst_range_extents[d] == src.range().extent(d),
"TiledArray::btas_tensor_to_array(): source dimension does "
"not match destination dimension.");
TA_ASSERT(dst_range_extents[d] == src.range().extent(d) &&
"TiledArray::btas_tensor_to_array(): source dimension does "
"not match destination dimension.");
}

using Tensor_ = btas::Tensor<T, Range, Storage>;
Expand All @@ -231,8 +231,8 @@ DistArray_ btas_tensor_to_array(World& world,

// Check that this is not a distributed computing environment
if (!replicated)
TA_USER_ASSERT(
world.size() == 1,
TA_ASSERT(
world.size() == 1 &&
"An array can be created from a btas::Tensor if the number of World "
"ranks is greater than 1 only when replicated=true.");

Expand Down Expand Up @@ -302,8 +302,8 @@ array_to_btas_tensor(const TiledArray::DistArray<Tile, Policy>& src,
int target_rank = -1) {
// Test preconditions
if (target_rank == -1 && !src.pmap()->is_replicated())
TA_USER_ASSERT(
src.world().size() == 1,
TA_ASSERT(
src.world().size() == 1 &&
"TiledArray::array_to_btas_tensor(): a non-replicated array can only "
"be converted to a btas::Tensor on every rank if the number of World "
"ranks is 1.");
Expand Down
65 changes: 33 additions & 32 deletions src/TiledArray/conversions/eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define TILEDARRAY_CONVERSIONS_EIGEN_H__INCLUDED

#include <TiledArray/error.h>
#include <TiledArray/external/madness.h>
#include <TiledArray/external/eigen.h>
#include <TiledArray/external/madness.h>
#include <TiledArray/pmap/replicated_pmap.h>
#include <TiledArray/tensor.h>
#include <tiledarray_fwd.h>
Expand Down Expand Up @@ -413,23 +413,23 @@ A eigen_to_array(World& world, const typename A::trange_type& trange,
typedef typename A::index1_type size_type;
// Check that trange matches the dimensions of other
if ((matrix.cols() > 1) && (matrix.rows() > 1)) {
TA_USER_ASSERT(trange.tiles_range().rank() == 2,
"TiledArray::eigen_to_array(): The number of dimensions in "
"trange is not equal to that of the Eigen matrix.");
TA_USER_ASSERT(
trange.elements_range().extent(0) == size_type(matrix.rows()),
TA_ASSERT(trange.tiles_range().rank() == 2 &&
"TiledArray::eigen_to_array(): The number of dimensions in "
"trange is not equal to that of the Eigen matrix.");
TA_ASSERT(
trange.elements_range().extent(0) == size_type(matrix.rows()) &&
"TiledArray::eigen_to_array(): The number of rows in trange is not "
"equal to the number of rows in the Eigen matrix.");
TA_USER_ASSERT(
trange.elements_range().extent(1) == size_type(matrix.cols()),
TA_ASSERT(
trange.elements_range().extent(1) == size_type(matrix.cols()) &&
"TiledArray::eigen_to_array(): The number of columns in trange is not "
"equal to the number of columns in the Eigen matrix.");
} else {
TA_USER_ASSERT(trange.tiles_range().rank() == 1,
"TiledArray::eigen_to_array(): The number of dimensions in "
"trange must match that of the Eigen matrix.");
TA_USER_ASSERT(
trange.elements_range().extent(0) == size_type(matrix.size()),
TA_ASSERT(trange.tiles_range().rank() == 1 &&
"TiledArray::eigen_to_array(): The number of dimensions in "
"trange must match that of the Eigen matrix.");
TA_ASSERT(
trange.elements_range().extent(0) == size_type(matrix.size()) &&
"TiledArray::eigen_to_array(): The size of trange must be equal to the "
"matrix size.");
}
Expand Down Expand Up @@ -501,17 +501,18 @@ array_to_eigen(const DistArray<Tile, Policy>& array) {
const auto rank = array.trange().tiles_range().rank();

// Check that the array will fit in a matrix or vector
TA_USER_ASSERT((rank == 2u) || (rank == 1u),
"TiledArray::array_to_eigen(): The array dimensions must be "
"equal to 1 or 2.");
TA_ASSERT((rank == 2u) ||
(rank == 1u) &&
"TiledArray::array_to_eigen(): The array dimensions must be "
"equal to 1 or 2.");

// Check that this is not a distributed computing environment or that the
// array is replicated
if (!array.pmap()->is_replicated())
TA_USER_ASSERT(array.world().size() == 1,
"TiledArray::array_to_eigen(): non-replicated Array cannot "
"be assigned to an Eigen::Matrix when the number of World "
"ranks is greater than 1.");
TA_ASSERT(array.world().size() == 1 &&
"TiledArray::array_to_eigen(): non-replicated Array cannot "
"be assigned to an Eigen::Matrix when the number of World "
"ranks is greater than 1.");

// Construct the Eigen matrix
const auto* MADNESS_RESTRICT const array_extent =
Expand Down Expand Up @@ -594,12 +595,12 @@ inline A row_major_buffer_to_array(
const typename A::value_type::value_type* buffer, const std::size_t m,
const std::size_t n, const bool replicated = false,
std::shared_ptr<typename A::pmap_interface> pmap = {}) {
TA_USER_ASSERT(trange.elements_range().extent(0) == m,
"TiledArray::eigen_to_array(): The number of rows in trange "
"is not equal to m.");
TA_USER_ASSERT(trange.elements_range().extent(1) == n,
"TiledArray::eigen_to_array(): The number of columns in "
"trange is not equal to n.");
TA_ASSERT(trange.elements_range().extent(0) == m &&
"TiledArray::eigen_to_array(): The number of rows in trange "
"is not equal to m.");
TA_ASSERT(trange.elements_range().extent(1) == n &&
"TiledArray::eigen_to_array(): The number of columns in "
"trange is not equal to n.");

typedef Eigen::Matrix<typename A::value_type::value_type, Eigen::Dynamic,
Eigen::Dynamic, Eigen::RowMajor>
Expand Down Expand Up @@ -663,12 +664,12 @@ inline A column_major_buffer_to_array(
const typename A::value_type::value_type* buffer, const std::size_t m,
const std::size_t n, const bool replicated = false,
std::shared_ptr<typename A::pmap_interface> pmap = {}) {
TA_USER_ASSERT(trange.elements_range().extent(0) == m,
"TiledArray::eigen_to_array(): The number of rows in trange "
"is not equal to m.");
TA_USER_ASSERT(trange.elements_range().extent(1) == n,
"TiledArray::eigen_to_array(): The number of columns in "
"trange is not equal to n.");
TA_ASSERT(trange.elements_range().extent(0) == m &&
"TiledArray::eigen_to_array(): The number of rows in trange "
"is not equal to m.");
TA_ASSERT(trange.elements_range().extent(1) == n &&
"TiledArray::eigen_to_array(): The number of columns in "
"trange is not equal to n.");

typedef Eigen::Matrix<typename A::value_type::value_type, Eigen::Dynamic,
Eigen::Dynamic, Eigen::ColMajor>
Expand Down
7 changes: 3 additions & 4 deletions src/TiledArray/conversions/foreach.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ inline std::
"if inplace==false, Op must be callable with signature "
"void(ResultTile&,const ArgTile&, const ArgTiles&...)");

TA_USER_ASSERT(compare_trange(arg, args...),
"Tiled ranges of args must match");
TA_ASSERT(compare_trange(arg, args...) && "Tiled ranges of args must match");

typedef DistArray<ArgTile, Policy> arg_array_type;
typedef DistArray<ResultTile, Policy> result_array_type;
Expand Down Expand Up @@ -261,8 +260,8 @@ inline std::
"ret(ResultTile&,const ArgTile&, const ArgTiles&...), where "
"ret={void,Policy::shape_type::value_type}");

TA_USER_ASSERT(detail::compare_trange(arg, args...),
"Tiled ranges of args must match");
TA_ASSERT(detail::compare_trange(arg, args...) &&
"Tiled ranges of args must match");

typedef DistArray<ArgTile, Policy> arg_array_type;
typedef DistArray<ResultTile, Policy> result_array_type;
Expand Down
56 changes: 28 additions & 28 deletions src/TiledArray/dist_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,25 @@ class DistArray : public madness::archive::ParallelSerializableObject {
pmap = Policy::default_pmap(world, trange.tiles_range().volume());
} else {
// Validate the process map
TA_USER_ASSERT(pmap->size() == trange.tiles_range().volume(),
"Array::Array() -- The size of the process map is not "
"equal to the number of tiles in the TiledRange object.");
TA_USER_ASSERT(
pmap->rank() == typename pmap_interface::size_type(world.rank()),
TA_ASSERT(pmap->size() == trange.tiles_range().volume() &&
"Array::Array() -- The size of the process map is not "
"equal to the number of tiles in the TiledRange object.");
TA_ASSERT(
pmap->rank() == typename pmap_interface::size_type(world.rank()) &&
"Array::Array() -- The rank of the process map is not equal to that "
"of the world object.");
TA_USER_ASSERT(
pmap->procs() == typename pmap_interface::size_type(world.size()),
TA_ASSERT(
pmap->procs() == typename pmap_interface::size_type(world.size()) &&
"Array::Array() -- The number of processes in the process map is not "
"equal to that of the world object.");
}

// Validate the shape
TA_USER_ASSERT(!shape.empty(),
"Array::Array() -- The shape is not initialized.");
TA_USER_ASSERT(shape.validate(trange.tiles_range()),
"Array::Array() -- The range of the shape is not equal to "
"the tiles range.");
TA_ASSERT(!shape.empty() &&
"Array::Array() -- The shape is not initialized.");
TA_ASSERT(shape.validate(trange.tiles_range()) &&
"Array::Array() -- The range of the shape is not equal to "
"the tiles range.");

return std::shared_ptr<impl_type>(new impl_type(world, trange, shape, pmap),
lazy_deleter);
Expand Down Expand Up @@ -1434,16 +1434,16 @@ class DistArray : public madness::archive::ParallelSerializableObject {
template <typename Index>
std::enable_if_t<std::is_integral_v<Index>, void> check_index(
const Index i) const {
TA_USER_ASSERT(
impl_ref().tiles_range().includes(i),
TA_ASSERT(
impl_ref().tiles_range().includes(i) &&
"The ordinal index used to access an array tile is out of range.");
}

template <typename Index>
std::enable_if_t<detail::is_integral_range_v<Index>, void> check_index(
const Index& i) const {
TA_USER_ASSERT(
impl_ref().tiles_range().includes(i),
TA_ASSERT(
impl_ref().tiles_range().includes(i) &&
"The coordinate index used to access an array tile is out of range.");
}

Expand All @@ -1456,18 +1456,18 @@ class DistArray : public madness::archive::ParallelSerializableObject {
std::enable_if_t<std::is_integral_v<Index>, void> check_local_index(
const Index i) const {
check_index(i);
TA_USER_ASSERT(
pimpl_->is_local(i), // pimpl_ already checked
"The ordinal index used to access an array tile is not local.");
TA_ASSERT(pimpl_->is_local(i) // pimpl_ already checked
&&
"The ordinal index used to access an array tile is not local.");
}

template <typename Index>
std::enable_if_t<detail::is_integral_range_v<Index>, void> check_local_index(
const Index& i) const {
check_index(i);
TA_USER_ASSERT(
pimpl_->is_local(i), // pimpl_ already checked
"The coordinate index used to access an array tile is not local.");
TA_ASSERT(
pimpl_->is_local(i) // pimpl_ already checked
&& "The coordinate index used to access an array tile is not local.");
}

template <typename Index1>
Expand Down Expand Up @@ -1510,9 +1510,9 @@ class DistArray : public madness::archive::ParallelSerializableObject {

/// Code factorization of the actual assert for the other overloads
void assert_pimpl() const {
TA_USER_ASSERT(pimpl_,
"The Array has not been initialized, likely reason: it was "
"default constructed and used.");
TA_ASSERT(pimpl_ &&
"The Array has not been initialized, likely reason: it was "
"default constructed and used.");
}

/// If this is in an initialized state this returns a const
Expand Down Expand Up @@ -1605,9 +1605,8 @@ inline std::ostream& operator<<(std::ostream& os,
return os;
}


template <typename Tile, typename Policy>
auto rank(const DistArray<Tile, Policy> &a) {
auto rank(const DistArray<Tile, Policy>& a) {
return a.trange().tiles_range().rank();
}

Expand All @@ -1632,7 +1631,8 @@ auto abs_max(const DistArray<Tile, Policy>& a) {
template <typename Tile, typename Policy>
auto dot(const DistArray<Tile, Policy>& a, const DistArray<Tile, Policy>& b) {
return (a(detail::dummy_annotation(rank(a)))
.dot(b(detail::dummy_annotation(rank(b))))).get();
.dot(b(detail::dummy_annotation(rank(b)))))
.get();
}

template <typename Tile, typename Policy>
Expand Down
8 changes: 2 additions & 6 deletions src/TiledArray/distributed_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ class DistributedStorage : public madness::WorldObject<DistributedStorage<T> > {
void set_handler(const size_type i, const value_type& value) {
future& f = get_local(i);

#ifndef NDEBUG
// Check that the future has not been set already.
if (f.probe()) TA_EXCEPTION("Tile has already been assigned.");
#endif // NDEBUG
TA_ASSERT(!f.probe() && "Tile has already been assigned.");

f.set(value);
}
Expand Down Expand Up @@ -281,9 +279,7 @@ class DistributedStorage : public madness::WorldObject<DistributedStorage<T> > {
acc.release();

// Check that the future has not been set already.
#ifndef NDEBUG
if (existing_f.probe()) TA_EXCEPTION("Tile has already been assigned.");
#endif // NDEBUG
TA_ASSERT(!existing_f.probe() && "Tile has already been assigned.");
// Set the future
existing_f.set(f);
}
Expand Down
24 changes: 0 additions & 24 deletions src/TiledArray/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,4 @@ inline void exception_break() {}
std::cerr << "!! ERROR TiledArray: " << m << "\n";
#endif // TILEDARRAY_NO_USER_ERROR_MESSAGES

#ifndef NDEBUG
// User interface assertion
#define TA_USER_ASSERT(a, m) \
do { \
if (!(a)) { \
TA_USER_ERROR_MESSAGE(m) \
TiledArray::exception_break(); \
throw TiledArray::Exception(m); \
} \
} while (0)

#else

// Disable user interface assertion when NDEBUG is defined
// this avoids unused variable warnings, see
// http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/
#define TA_USER_ASSERT(a, m) \
do { \
(void)sizeof(a); \
} while (0)
#define TA_USER_ASSERT_DISABLED 1

#endif

#endif // TILEDARRAY_ERROR_H__INCLUDED
Loading