Skip to content

Commit 57190e0

Browse files
authored
Merge branch 'master' into kmp5/feature/CP
2 parents e5adc86 + 7f76cda commit 57190e0

15 files changed

Lines changed: 198 additions & 62 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ endif()
231231
if(NOT CMAKE_EXE_LINKER_FLAGS OR NOT DEFINED CMAKE_EXE_LINKER_FLAGS)
232232
set(CMAKE_EXE_LINKER_FLAGS "$ENV{LDFLAGS}")
233233
endif()
234+
235+
# Detect libc++ linker mismatch (e.g. Homebrew LLVM headers vs system libc++)
236+
include(CheckCXXFeatures)
237+
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
238+
vgkit_check_libcxx_linker_mismatch(MODIFY_GLOBAL_FLAGS)
239+
else()
240+
vgkit_check_libcxx_linker_mismatch()
241+
endif()
242+
234243
if (NOT CMAKE_CXX_COMPILER)
235244
message(FATAL_ERROR "C++ compiler not found")
236245
endif()

cmake/modules/FindEigen3.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ if(NOT Eigen3_FIND_VERSION)
3131
endif(NOT Eigen3_FIND_VERSION)
3232

3333
macro(_eigen3_check_version)
34-
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
34+
# Try the Eigen 5.x location first
35+
if(EXISTS "${EIGEN3_INCLUDE_DIR}/Eigen/Version")
36+
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/Version" _eigen3_version_header)
37+
# Fall back to Eigen 3.x location
38+
elseif(EXISTS "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h")
39+
file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header)
40+
else()
41+
# Could not locate any known Eigen version header; mark version as not OK and return.
42+
set(EIGEN3_VERSION_OK FALSE)
43+
message(STATUS "Could not find Eigen version header under ${EIGEN3_INCLUDE_DIR}")
44+
return()
45+
endif()
3546

3647
string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}")
3748
set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}")

doc/dox/dev/Basic-Programming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ for(TArrayD::iterator it = array.begin(); it != array.end(); ++it) {
533533
```
534534
The outer loop in this example iterates over the local tiles of `array`. Within the loop body we first create an tile (an object of `TArrayD::value_type` type, which in this case is `TA::Tensor<double>`). Then we loop over its elements and assign each to zero.
535535

536-
N.B. Of course, filling a DistArray with a constant is such a common use case that there's already a method for exactly that: `array.fill(0.0)`.
536+
N.B. Of course, filling a DistArray with a constant is such a common use case that there's already a method for exactly that: `array.fill(0.0)`. Note that for sparse arrays `fill(0.0)` will produce an empty array with no tiles, rather than an array full of tiles filled with zeroes.
537537

538538
There are more serious issues with the last example. First, it is too verbose. Second, it's not generic enough (i.e. trying to reuse it for a sparse DistArray would require changing a few lines). Both issues can be solved by using modern C++ features:
539539
```.cpp

external/versions.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# for each dependency track both current and previous id (the variable for the latter must contain PREVIOUS)
22
# to be able to auto-update them
33

4-
set(TA_TRACKED_VGCMAKEKIT_TAG 4c949fd7ccfe4b4f0e103288a5c0f557c6e740c0)
4+
set(TA_TRACKED_VGCMAKEKIT_TAG 256d9462bb765787f5acb69be154b26d6efba8b6)
55

66
# N.B. may need to update INSTALL.md manually with the CUDA-specific version
77
set(TA_TRACKED_EIGEN_VERSION 3.3.5)
@@ -17,14 +17,14 @@ set(TA_TRACKED_MADNESS_PREVIOUS_TAG bd84a52766ab497dedc2f15f2162fb0eb7ec4653)
1717
set(TA_TRACKED_MADNESS_VERSION 0.10.1)
1818
set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1)
1919

20-
set(TA_TRACKED_BTAS_TAG 9c8c8f68fee2b82e64755270a8348e4612cf9941)
21-
set(TA_TRACKED_BTAS_PREVIOUS_TAG 74dd9277c71043c564f931c9d1f07842548d2349)
20+
set(TA_TRACKED_BTAS_TAG 287b145ead818a0332f2b7ce0b7375a83d328bae)
21+
set(TA_TRACKED_BTAS_PREVIOUS_TAG 62d57d9b1e0c733b4b547bc9cfdd07047159dbca)
2222

2323
set(TA_TRACKED_LIBRETT_TAG 6eed30d4dd2a5aa58840fe895dcffd80be7fbece)
2424
set(TA_TRACKED_LIBRETT_PREVIOUS_TAG 354e0ccee54aeb2f191c3ce2c617ebf437e49d83)
2525

26-
set(TA_TRACKED_UMPIRE-CXX-ALLOCATOR_TAG cbb08408b1cfbbacc24992e36f52edb3a29bdedc)
27-
set(TA_TRACKED_UMPIRE-CXX-ALLOCATOR_PREVIOUS_TAG a48ad360e20b9733263768b54aa24afe5894faa4)
26+
set(TA_TRACKED_UMPIRE-CXX-ALLOCATOR_TAG 1ba7f5f0aa99438826dd1c6bc1cd396080b9d608)
27+
set(TA_TRACKED_UMPIRE-CXX-ALLOCATOR_PREVIOUS_TAG 0f8144f19897766d0f117f7353221d4e3b8b1178)
2828

2929
set(TA_TRACKED_SCALAPACKPP_TAG 6397f52cf11c0dfd82a79698ee198a2fce515d81)
3030
set(TA_TRACKED_SCALAPACKPP_PREVIOUS_TAG 711ef363479a90c88788036f9c6c8adb70736cbf )

src/TiledArray/conversions/foreach.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ inline std::enable_if_t<!is_dense_v<Policy>, void> foreach_inplace(
692692
// Set the arg with the new array
693693
left = detail::foreach<true, Op, LeftTile, LeftTile, Policy, RightTile>(
694694
std::forward<Op>(op), shape_reduction, left, right);
695+
696+
// must also fence after to prevent remote ranks start work on unprocessed
697+
// tiles
698+
if (fence) left.world().gop.fence();
695699
}
696700

697701
/// @}

src/TiledArray/dist_array.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ class DistArray : public madness::archive::ParallelSerializableObject {
918918

919919
/// Fill all local tiles with the specified value
920920

921+
/// For sparse arrays, if \p value is zero (i.e., equal to
922+
/// `element_type()`), the array is empty (no nonzero tiles)
923+
/// and 0 is returned.
921924
/// \tparam fence If Fence::No, the operation will return early,
922925
/// before the tasks have completed
923926
/// \param[in] value What each local tile should be filled with.
@@ -930,6 +933,15 @@ class DistArray : public madness::archive::ParallelSerializableObject {
930933
template <Fence fence = Fence::No>
931934
std::int64_t fill(const element_type& value = numeric_type(),
932935
bool skip_set = false) {
936+
// for sparse arrays filled with zero, replace with an empty array
937+
if constexpr (!is_dense_v<Policy>) {
938+
if (value == element_type()) {
939+
*this = DistArray(
940+
world(), trange(),
941+
shape_type(typename shape_type::value_type(0), trange()), pmap());
942+
return 0;
943+
}
944+
}
933945
return fill_local<fence>(value, skip_set);
934946
}
935947

src/TiledArray/math/linalg/basic.h

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ inline void vec_multiply(
155155
a1.array() *= a2.array();
156156
}
157157

158+
template <typename Derived>
159+
inline auto clone(const Eigen::MatrixBase<Derived>& a) {
160+
return a.eval();
161+
}
162+
163+
template <typename XprType1, int BlockRows1, int BlockCols1, bool InnerPanel1>
164+
inline auto clone(
165+
const Eigen::Block<XprType1, BlockRows1, BlockCols1, InnerPanel1>& a) {
166+
return a.eval();
167+
}
168+
158169
template <typename Derived, typename S>
159170
inline void scale(Eigen::MatrixBase<Derived>& a, S scaling_factor) {
160171
using numeric_type = typename Eigen::MatrixBase<Derived>::value_type;
@@ -239,6 +250,21 @@ inline auto norm2(
239250
return m.template lpNorm<2>();
240251
}
241252

253+
template <typename Derived>
254+
inline auto volume(const Eigen::MatrixBase<Derived>& m) {
255+
return m.size();
256+
}
257+
258+
template <typename Derived>
259+
inline auto abs_min(const Eigen::MatrixBase<Derived>& m) {
260+
return m.array().abs().minCoeff();
261+
}
262+
263+
template <typename Derived>
264+
inline auto abs_max(const Eigen::MatrixBase<Derived>& m) {
265+
return m.array().abs().maxCoeff();
266+
}
267+
242268
} // namespace Eigen
243269

244270
#ifndef TILEDARRAY_MATH_LINALG_DISPATCH_W_TTG
@@ -253,12 +279,12 @@ inline auto norm2(
253279
return scalapack::FN; \
254280
return non_distributed::FN;
255281
#elif (TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK)
256-
#define TILEDARRAY_MATH_LINALG_DISPATCH_W_TTG(FN, MATRIX) \
257-
TA_MAX_THREADS; \
258-
if (get_linalg_backend() == LinearAlgebraBackend::TTG || \
259-
TiledArray::math::linalg::detail::prefer_distributed(MATRIX)) \
260-
return TiledArray::math::linalg::ttg::FN; \
261-
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
282+
#define TILEDARRAY_MATH_LINALG_DISPATCH_W_TTG(FN, MATRIX) \
283+
TA_MAX_THREADS; \
284+
if (get_linalg_backend() == LinearAlgebraBackend::TTG || \
285+
TiledArray::math::linalg::detail::prefer_distributed(MATRIX)) \
286+
return TiledArray::math::linalg::ttg::FN; \
287+
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
262288
TA_EXCEPTION("ScaLAPACK linear algebra backend is not available"); \
263289
return non_distributed::FN;
264290
#elif !TILEDARRAY_HAS_TTG && TILEDARRAY_HAS_SCALAPACK
@@ -271,11 +297,11 @@ inline auto norm2(
271297
return scalapack::FN; \
272298
return non_distributed::FN;
273299
#else // !TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK
274-
#define TILEDARRAY_MATH_LINALG_DISPATCH_W_TTG(FN, MATRIX) \
275-
TA_MAX_THREADS; \
276-
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
277-
TA_EXCEPTION("TTG linear algebra backend is not available"); \
278-
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
300+
#define TILEDARRAY_MATH_LINALG_DISPATCH_W_TTG(FN, MATRIX) \
301+
TA_MAX_THREADS; \
302+
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
303+
TA_EXCEPTION("TTG linear algebra backend is not available"); \
304+
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
279305
TA_EXCEPTION("ScaLAPACK linear algebra backend is not available"); \
280306
return non_distributed::FN;
281307
#endif // !TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK
@@ -297,12 +323,12 @@ inline auto norm2(
297323
return scalapack::FN; \
298324
return non_distributed::FN;
299325
#elif TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK
300-
#define TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG(FN, MATRIX) \
301-
TA_MAX_THREADS; \
302-
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
303-
TA_EXCEPTION(TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG_STRINGIFY( \
304-
FN) " is not provided by the TTG backend"); \
305-
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
326+
#define TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG(FN, MATRIX) \
327+
TA_MAX_THREADS; \
328+
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
329+
TA_EXCEPTION(TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG_STRINGIFY( \
330+
FN) " is not provided by the TTG backend"); \
331+
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
306332
TA_EXCEPTION("ScaLAPACK linear algebra backend is not available"); \
307333
return non_distributed::FN;
308334
#elif !TILEDARRAY_HAS_TTG && TILEDARRAY_HAS_SCALAPACK
@@ -315,11 +341,11 @@ inline auto norm2(
315341
return scalapack::FN; \
316342
return non_distributed::FN;
317343
#else // !TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK
318-
#define TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG(FN, MATRIX) \
319-
TA_MAX_THREADS; \
320-
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
321-
TA_EXCEPTION("TTG linear algebra backend is not available"); \
322-
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
344+
#define TILEDARRAY_MATH_LINALG_DISPATCH_WO_TTG(FN, MATRIX) \
345+
TA_MAX_THREADS; \
346+
if (get_linalg_backend() == LinearAlgebraBackend::TTG) \
347+
TA_EXCEPTION("TTG linear algebra backend is not available"); \
348+
if (get_linalg_backend() == LinearAlgebraBackend::ScaLAPACK) \
323349
TA_EXCEPTION("ScaLAPACK linear algebra backend is not available"); \
324350
return non_distributed::FN;
325351
#endif // !TILEDARRAY_HAS_TTG && !TILEDARRAY_HAS_SCALAPACK

src/TiledArray/math/solvers/conjgrad.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <TiledArray/math/linalg/basic.h>
3030
#include <TiledArray/math/solvers/diis.h>
3131
#include "TiledArray/dist_array.h"
32+
#include "TiledArray/type_traits.h"
3233

3334
namespace TiledArray::math {
3435

@@ -44,8 +45,8 @@ namespace TiledArray::math {
4445
/// stand-alone functions:
4546
/// \li <tt> std::size_t volume(const D&) </tt> (returns the total number of elements)
4647
/// \li <tt> D clone(const D&) </tt>, returns a deep copy
47-
/// \li <tt> value_type minabs_value(const D&) </tt>
48-
/// \li <tt> value_type maxabs_value(const D&) </tt>
48+
/// \li <tt> value_type abs_min(const D&) </tt>
49+
/// \li <tt> value_type abs_max(const D&) </tt>
4950
/// \li <tt> void vec_multiply(D& a, const D& b) </tt> (element-wise multiply
5051
/// of \c a by \c b )
5152
/// \li <tt> value_type inner_product(const D& a, const D& b) </tt>
@@ -60,7 +61,7 @@ namespace TiledArray::math {
6061
// clang-format on
6162
template <typename D, typename F>
6263
struct ConjugateGradientSolver {
63-
typedef typename D::numeric_type value_type;
64+
typedef TiledArray::detail::numeric_t<D> value_type;
6465

6566
/// \param a object of type F
6667
/// \param b RHS
@@ -73,8 +74,8 @@ struct ConjugateGradientSolver {
7374
value_type convergence_target = -1.0) {
7475
std::size_t n = volume(preconditioner);
7576

76-
const bool use_diis = false;
77-
DIIS<D> diis;
77+
constexpr bool use_diis = false;
78+
std::conditional_t<use_diis, DIIS<D>, char> diis{};
7879

7980
// solution vector
8081
D XX_i;
@@ -120,7 +121,7 @@ struct ConjugateGradientSolver {
120121
scale(RR_i, -1.0);
121122
axpy(RR_i, 1.0, b); // RR_i = b - a(XX_i)
122123

123-
if (use_diis) diis.extrapolate(XX_i, RR_i, true);
124+
if constexpr (use_diis) diis.extrapolate(XX_i, RR_i, true);
124125

125126
// z_0 = D^-1 . r_0
126127
ZZ_i = RR_i;
@@ -144,7 +145,7 @@ struct ConjugateGradientSolver {
144145
// r_i -= alpha_i Ap_i
145146
axpy(RR_i, -alpha_i, APP_i);
146147

147-
if (use_diis) diis.extrapolate(XX_i, RR_i, true);
148+
if constexpr (use_diis) diis.extrapolate(XX_i, RR_i, true);
148149

149150
const value_type r_ip1_norm = norm2(RR_i) / rhs_size;
150151
if (r_ip1_norm < convergence_target) {

src/TiledArray/math/solvers/diis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <TiledArray/math/linalg/basic.h>
3030
#include "TiledArray/dist_array.h"
3131
#include "TiledArray/external/eigen.h"
32+
#include "TiledArray/type_traits.h"
3233

3334
#include <Eigen/QR>
3435
#include <deque>
@@ -82,7 +83,7 @@ namespace TiledArray::math {
8283
template <typename D>
8384
class DIIS {
8485
public:
85-
typedef typename D::numeric_type value_type;
86+
typedef TiledArray::detail::numeric_t<D> value_type;
8687
typedef typename TiledArray::detail::scalar_t<value_type> scalar_type;
8788
typedef Eigen::Matrix<value_type, Eigen::Dynamic, Eigen::Dynamic,
8889
Eigen::RowMajor>

src/TiledArray/tensor/tensor_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class TensorInterface {
179179
/// \param data The data pointer for this tensor
180180
TensorInterface(const range_type& range, pointer data)
181181
: range_(range), data_(data) {
182-
TA_ASSERT(data);
183182
}
184183

185184
/// Construct a new view of \c tensor
@@ -188,7 +187,6 @@ class TensorInterface {
188187
/// \param data The data pointer for this tensor
189188
TensorInterface(range_type&& range, pointer data)
190189
: range_(std::move(range)), data_(data) {
191-
TA_ASSERT(data);
192190
}
193191

194192
template <typename T1, typename std::enable_if<detail::is_nested_tensor<

0 commit comments

Comments
 (0)