From 602dbf4512fd6e49f4cd124e181246a5839ebf8a Mon Sep 17 00:00:00 2001 From: asadchev Date: Tue, 2 Feb 2021 16:24:59 -0500 Subject: [PATCH 01/29] ci: reorganize CI scripts around generalised ./ci/.build-project --- .gitlab-ci.yml | 54 ++++++++++------------ bin/gitlab-ci.sh | 41 ----------------- ci/.build-project | 97 +++++++++++++++++++++++++++++++++++++++ ci/host_system_info.cmake | 22 +++++++++ ci/openmpi.env | 5 ++ 5 files changed, 147 insertions(+), 72 deletions(-) delete mode 100755 bin/gitlab-ci.sh create mode 100755 ci/.build-project create mode 100644 ci/host_system_info.cmake create mode 100644 ci/openmpi.env diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 104a5f6eeb..ee54cf681a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,35 +7,21 @@ default: variables: MAD_NUM_THREADS : 2 - TA_CI_TARGETS : "tiledarray examples ta_test check" - TA_CI_CONFIG : > - TA_BUILD_UNITTEST=TRUE - CMAKE_BUILD_TYPE=${BUILD_TYPE} - ${TA_PYTHON} - ${ENABLE_CUDA} - ${BLA_VENDOR} - ${ENABLE_SCALAPACK} + TA_TARGETS : "tiledarray examples ta_test check" + TA_CONFIG : > + TA_BUILD_UNITTEST=TRUE + CMAKE_BUILD_TYPE=${BUILD_TYPE} + ${TA_PYTHON} + ${ENABLE_CUDA} + ${BLA_VENDOR} + ${ENABLE_SCALAPACK} before_script: - - echo 'localhost slots=2' > /etc/openmpi/openmpi-default-hostfile + # NB: below tag parsing is not robust - echo "CI_RUNNER_TAGS=$CI_RUNNER_TAGS" - # NB: tag parsing below is not robust - CMAKE_BUILD_PARALLEL_LEVEL=$(echo $CI_RUNNER_TAGS | sed -n 's/CMAKE_BUILD_PARALLEL_LEVEL=\([0-9]\+\).*/\1/p') - export CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:=1} - echo "CMAKE_BUILD_PARALLEL_LEVEL=$CMAKE_BUILD_PARALLEL_LEVEL" - - |- - if [[ "$BLA_VENDOR" == "BLA_VENDOR=Intel10"* ]]; then - # apt-get install -yq intel-mkl-core-c-2020.4-304 - # source /opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/bin/mklvars.sh intel64 - make -C /home/ValeevGroup install/intel-mkl - source /opt/intel/mkl/bin/mklvars.sh intel64 - echo "MKLROOT=$MKLROOT" - fi - - |- - if [[ "$ENABLE_CUDA" == "ENABLE_CUDA=ON" ]]; then - make -C /home/ValeevGroup install/cuda - export CUDACXX=/usr/local/cuda/bin/nvcc - fi ubuntu: stage: build @@ -46,17 +32,23 @@ ubuntu: TA_PYTHON : "TA_PYTHON=ON" ENABLE_SCALAPACK : "ENABLE_SCALAPACK=OFF" script: - - mkdir build - - cd build - # !!! Unset env vars that may conflict with build, eg FindBLAS uses $ENV{BLA_VENDOR} - - unset BUILD_TYPE TA_PYTHON BLA_VENDOR ENABLE_SCALAPACK ENABLE_CUDA - - ../bin/gitlab-ci.sh .. - ${TA_CI_TARGETS} - ${TA_CI_CONFIG} + - ./ci/.build-project + --build ./build + --metrics ./build/metrics.txt + ${TA_CONFIG} + ${TA_TARGETS} MPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' blacs_LIBRARIES=scalapack-openmpi scalapack_LIBRARIES=scalapack-openmpi #lapack_LIBRARIES=lapack + artifacts: + paths: + - build/metrics.txt + - build/CMakeCache.txt + - build/CMakeFiles/CMakeOutput.log + - build/CMakeFiles/CMakeError.log + reports: + metrics: build/metrics.txt parallel: matrix: - IMAGE : [ "ubuntu:18.04", "ubuntu:20.04" ] @@ -73,4 +65,4 @@ ubuntu: CXX: [ g++ ] BUILD_TYPE : [ "Release", "Debug" ] ENABLE_CUDA : [ "ENABLE_CUDA=ON" ] - TA_CI_TARGETS : [ "tiledarray examples" ] \ No newline at end of file + TA_TARGETS : [ "tiledarray examples" ] \ No newline at end of file diff --git a/bin/gitlab-ci.sh b/bin/gitlab-ci.sh deleted file mode 100755 index f83140682d..0000000000 --- a/bin/gitlab-ci.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -echo "$ $0 $@" - -if [ "$#" -lt 1 ]; then - echo "CMake project directory argument required" - exit 1 -fi - -project_dir=$1 -shift - -targets="" -cmake_args="" - -for arg in "$@"; do - #echo $arg - case $arg in - *=*) cmake_args+=" \"-D$arg\"" ;; - *) targets+=" $arg" ;; - esac -done - -echo "CMake args: $cmake_args" -echo "Build targets: $targets" -echo "" - -set -e -set -x - -# to run OpenMPI in docker as root -export OMPI_ALLOW_RUN_AS_ROOT=1 -export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 -export OMPI_MCA_btl_vader_single_copy_mechanism="none" - -eval "cmake $project_dir $cmake_args" - -for target in $targets; do - echo "Building target $target" - eval "cmake --build . --target $target" -done diff --git a/ci/.build-project b/ci/.build-project new file mode 100755 index 0000000000..7b6f4d0b3a --- /dev/null +++ b/ci/.build-project @@ -0,0 +1,97 @@ +#!/bin/bash + +set -e + +build_dir="" +metrics="" + +var=" " +targets=" " + +while [ $# -gt 0 ]; do + case $1 in + --build) shift; build_dir=$1 ;; + --metrics) shift; metrics=$1 ;; + -*) echo "Invalid option $arg"; exit 1 ;; + CXX=*) eval "export $1" ;; + *=*) vars+="\"-D$1\" " + # NB unset vars from s.t. CMake doesn't see env vars, eg BLA_VENDOR + unset $(echo "$1" | cut -d= -f1) + ;; + *) targets+="$1 ";; + esac + shift +done + +if [ -z "$build_dir" ]; then + echo "--build is required" + exit 1 +fi + +xtime="/usr/bin/time" + +if [ -n "$metrics" ]; then + #sudo apt install time + if [ ! -x $xtime ]; then + echo >&2 "${xtime} is not executable, metrics disabled" + metrics="" + fi + rm -f "${metrics}" +fi + +function time_cmd { + step=$1; shift + cmd="$@" + echo "+ $cmd" + if [ -n "$metrics" ]; then + format="'${step}.memory %Mk\n${step}.time %E\n'" + cmd="${xtime} -f ${format} -a -o $metrics $cmd" + #echo "$cmd" + fi + eval "$cmd" +} + +function cmd { + echo "+ $@" + eval "$@" +} + +# NB Gitlab section: https://docs.gitlab.com/ee/ci/jobs/#custom-collapsible-sections +function section_start { + echo -e "section_start:`date +%s`:$1\r\e[0K$2" +} + +function section_end { + echo -e "section_end:`date +%s`:$1\r\e[0K" +} + +echo "" +section_start "host_system_info[collapsed=true]" "Host system info" +cmd "cmake -P ci/host_system_info.cmake" +section_end host_system_info + +section_start "preparing_system_section[collapsed=true]" "Preparing system" +cmd "source ci/openmpi.env" +cmd "echo 'localhost slots=2' > /etc/openmpi/openmpi-default-hostfile" +if [[ "$vars" =~ \"-DBLA_VENDOR=Intel ]]; then + cmd "make -C /home/ValeevGroup install/intel-mkl" + cmd "source /opt/intel/mkl/bin/mklvars.sh intel64" + cmd "echo MKLROOT=\$MKLROOT" +fi +if [[ "$vars" =~ \"-D([a-zA-Z]+_)?ENABLE_CUDA=(ON|TRUE|1|YES)\" ]]; then + cmd "make -C /home/ValeevGroup install/cuda" + cmd "export CUDACXX=/usr/local/cuda/bin/nvcc" +fi +section_end preparing_system_section + +section_start configure_section "Configure" +cmd mkdir -p ${build_dir} +time_cmd configure "cmake -B${build_dir} $vars" +section_end configure_section + +for target in ${targets}; do + section_start build_${target}_section "Build ${target}" + time_cmd ${target} "cmake --build ${build_dir} --target ${target}" + section_end build_${target}_section +done + diff --git a/ci/host_system_info.cmake b/ci/host_system_info.cmake new file mode 100644 index 0000000000..4e10a30121 --- /dev/null +++ b/ci/host_system_info.cmake @@ -0,0 +1,22 @@ +set( + keys + + OS_NAME + OS_RELEASE + OS_VERSION + OS_PLATFORM + + + PROCESSOR_DESCRIPTION + NUMBER_OF_PHYSICAL_CORES + + TOTAL_VIRTUAL_MEMORY + AVAILABLE_VIRTUAL_MEMORY + TOTAL_PHYSICAL_MEMORY + AVAILABLE_PHYSICAL_MEMORY + ) + +foreach (key ${keys}) + cmake_host_system_information(RESULT result QUERY ${key}) + message(STATUS "${key}: ${result}") +endforeach() diff --git a/ci/openmpi.env b/ci/openmpi.env new file mode 100644 index 0000000000..50ea751bea --- /dev/null +++ b/ci/openmpi.env @@ -0,0 +1,5 @@ +# to run OpenMPI in docker as root +export OMPI_ALLOW_RUN_AS_ROOT=1 +export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1 +export OMPI_MCA_btl_vader_single_copy_mechanism="none" + From 60027c2b3c8bef18ad80354d2dcfbbac58e0826b Mon Sep 17 00:00:00 2001 From: asadchev Date: Tue, 2 Feb 2021 16:24:59 -0500 Subject: [PATCH 02/29] ci: ci/docker-run-ci to build project via docker run, cf ci/README.md --- ci/README.md | 14 ++++++++++++++ ci/docker-run-ci | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 ci/README.md create mode 100755 ci/docker-run-ci diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000000..b97e8154a4 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,14 @@ +To run CI in docker use `docker-run-ci` and give build parameters, eg: + +``` +$ ./ci/docker-run-ci TA_PYTHON=OFF ENABLE_CUDA=ON all check +Removing previous build container: andrey.tiledarray.build + +Running new build of /home/andrey/github/tiledarray on andrey.tiledarray.build +* Use CTRL-p CTRL-q to dettach +* To reattach use: docker start -a -i andrey.tiledarray.build +... +``` + +This builds targets `all check` on current Git branch in a docker container named `${USER}.$(basename $PWD).build` + diff --git a/ci/docker-run-ci b/ci/docker-run-ci new file mode 100755 index 0000000000..32aedfcfa3 --- /dev/null +++ b/ci/docker-run-ci @@ -0,0 +1,39 @@ +#!/bin/bash + +# build project via docker run, eg +# usage: docker-run-ci [ VAR=VALUE ... ] [ target ... ] +# example: ./ci/docker-run-ci ./build-dir MPQC_BUILD_DEPENDENCIES_FROM_SOURCE=OFF ENABLE_CUDA=ON all check + +project=$(basename $PWD) +image=valeevgroup/ubuntu +name=$USER.${project}.build +project_source_dir=$PWD + +script="cd /builds/ValeevGroup/${project} + +echo '# git checkout .' +git checkout . +echo + +echo '# git log -1' +git log -1 +echo + +./ci/.build-project --build ./build --metrics ./build/metrics.txt $@; + +bash +" + +echo -n "Removing previous build container: " +docker rm -f ${name} + +echo " +Running new build of ${project_source_dir} on ${name} +* Use CTRL-p CTRL-q to dettach +* To reattach use: docker start -a -i ${name} +" +#sleep 1 + +docker run --name ${name} -ti \ + -v ${project_source_dir}/.git:/builds/ValeevGroup/${project}/.git \ + ${image} bash -c "$script" From af87d441b2697805eb7b71845be3892b923765e0 Mon Sep 17 00:00:00 2001 From: asadchev Date: Tue, 2 Feb 2021 16:25:28 -0500 Subject: [PATCH 03/29] ci: MacOS GitHub Actions CI/CD --- .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..999c00f459 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: TiledArray CI + +on: [push] + +env: + CMAKE_BUILD_PARALLEL_LEVEL : 2 + +jobs: + + MacOS-Build: + + strategy: + fail-fast: false + matrix: + os : [ macos-latest ] + cxx : [ clang++, /usr/local/bin/g++-10 ] + build_type : [ Release, Debug ] + prerequisites : [ gcc@10 boost eigen open-mpi ] + + name: "${{ matrix.os }}: ${{ matrix.cxx }} ${{ matrix.build_type }}" + runs-on: ${{ matrix.os }} + env: + CXX : ${{ matrix.cxx }} + BUILD_CONFIG : > + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DTA_BUILD_UNITTEST=ON + -DMPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' + + steps: + - uses: actions/checkout@v2 + + - name: Host system info + shell: bash + run: cmake -P ${{github.workspace}}/ci/host_system_info.cmake + + - name: Install ${{matrix.prerequisites}} + run: brew install ${{matrix.prerequisites}} + + - name: "Configure build: ${{ env.BUILD_CONFIG }}" + shell: bash + run: | + set -x; + cmake -B${{github.workspace}}/build $BUILD_CONFIG + + - name: Build + working-directory: ${{github.workspace}}/build + shell: bash + run: | + cmake --build . --target tiledarray + cmake --build . --target examples + + - name: Test + working-directory: ${{github.workspace}}/build + shell: bash + #run: ctest -C $${{matrix.build_type}} + run: | + source ${{github.workspace}}/ci/openmpi.env + cmake --build . --target ta_test + cmake --build . --target check From f8e4ad5a997e29a04f8f04e2eeeafaae3909bfbe Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 11 Feb 2021 13:33:14 -0500 Subject: [PATCH 04/29] [cmake] bump BTAS tag to load blaspp_header target from tiledarray-config, resolves #252 --- INSTALL.md | 2 +- external/versions.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4e32c98eca..c03fba69bf 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -40,7 +40,7 @@ Both methods are supported. However, for most users we _strongly_ recommend to b - Boost.Container: header-only - Boost.Test: header-only or (optionally) as a compiled library, *only used for unit testing* - Boost.Range: header-only, *only used for unit testing* -- [BTAS](http://github.com/ValeevGroup/BTAS), tag 784911dc65c5aec04c1f4c9a70a750bba563b173 . If usable BTAS installation is not found, TiledArray will download and compile +- [BTAS](http://github.com/ValeevGroup/BTAS), tag 1ee43ef413c12166e3ce3db2ac69160c7622f497 . If usable BTAS installation is not found, TiledArray will download and compile BTAS from source. *This is the recommended way to compile BTAS for all users*. - [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag b22ee85059e6ccc9a6e803ba0550652ece8d9df1 . Only the MADworld runtime and BLAS/LAPACK C API component of MADNESS is used by TiledArray. diff --git a/external/versions.cmake b/external/versions.cmake index 2caddcb479..5f65ca97d8 100644 --- a/external/versions.cmake +++ b/external/versions.cmake @@ -22,8 +22,8 @@ set(TA_TRACKED_MADNESS_PREVIOUS_TAG 925552feaf326cca8e83de7bd042074ad3cfd3f1) set(TA_TRACKED_MADNESS_VERSION 0.10.1) set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1) -set(TA_TRACKED_BTAS_TAG 784911dc65c5aec04c1f4c9a70a750bba563b173) -set(TA_TRACKED_BTAS_PREVIOUS_TAG 1c6099ed2d709896430a892b05bcb94b306f76c9) +set(TA_TRACKED_BTAS_TAG 1ee43ef413c12166e3ce3db2ac69160c7622f497) +set(TA_TRACKED_BTAS_PREVIOUS_TAG 784911dc65c5aec04c1f4c9a70a750bba563b173) set(TA_TRACKED_CUTT_TAG 0e8685bf82910bc7435835f846e88f1b39f47f09) set(TA_TRACKED_CUTT_PREVIOUS_TAG 592198b93c93b7ca79e7900b9a9f2e79f9dafec3) From 8c91685556af6bb578317c7e349c35a9eadbde4c Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 11 Feb 2021 20:37:15 -0500 Subject: [PATCH 05/29] typo --- cmake/modules/FindOrFetchRangeV3.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/FindOrFetchRangeV3.cmake b/cmake/modules/FindOrFetchRangeV3.cmake index ff812162ce..6a6805614b 100644 --- a/cmake/modules/FindOrFetchRangeV3.cmake +++ b/cmake/modules/FindOrFetchRangeV3.cmake @@ -16,7 +16,7 @@ else (TARGET range-v3::range-v3) BINARY_DIR RANGEV3_BINARY_DIR ) - # set BTAS_CONFIG to the install location so that we know where to find it + # set range-v3_CONFIG to the install location so that we know where to find it set(range-v3_CONFIG ${CMAKE_INSTALL_PREFIX}/lib/cmake/range-v3/range-v3-config.cmake) endif(TARGET range-v3::range-v3) From 481103b96e9c34d6d7bcded749138d6db0291cb1 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 11 Feb 2021 20:38:08 -0500 Subject: [PATCH 06/29] [cmake] bump BTAS tag to load blaspp/lapackpp from tiledarray-config, resolves #255 --- INSTALL.md | 2 +- external/versions.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index c03fba69bf..42b473da4e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -40,7 +40,7 @@ Both methods are supported. However, for most users we _strongly_ recommend to b - Boost.Container: header-only - Boost.Test: header-only or (optionally) as a compiled library, *only used for unit testing* - Boost.Range: header-only, *only used for unit testing* -- [BTAS](http://github.com/ValeevGroup/BTAS), tag 1ee43ef413c12166e3ce3db2ac69160c7622f497 . If usable BTAS installation is not found, TiledArray will download and compile +- [BTAS](http://github.com/ValeevGroup/BTAS), tag 8752fb97fc68d1982c48283aba4b03c744389ba8 . If usable BTAS installation is not found, TiledArray will download and compile BTAS from source. *This is the recommended way to compile BTAS for all users*. - [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag b22ee85059e6ccc9a6e803ba0550652ece8d9df1 . Only the MADworld runtime and BLAS/LAPACK C API component of MADNESS is used by TiledArray. diff --git a/external/versions.cmake b/external/versions.cmake index 5f65ca97d8..8ad6d8eb6b 100644 --- a/external/versions.cmake +++ b/external/versions.cmake @@ -22,8 +22,8 @@ set(TA_TRACKED_MADNESS_PREVIOUS_TAG 925552feaf326cca8e83de7bd042074ad3cfd3f1) set(TA_TRACKED_MADNESS_VERSION 0.10.1) set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1) -set(TA_TRACKED_BTAS_TAG 1ee43ef413c12166e3ce3db2ac69160c7622f497) -set(TA_TRACKED_BTAS_PREVIOUS_TAG 784911dc65c5aec04c1f4c9a70a750bba563b173) +set(TA_TRACKED_BTAS_TAG 8752fb97fc68d1982c48283aba4b03c744389ba8) +set(TA_TRACKED_BTAS_PREVIOUS_TAG 1ee43ef413c12166e3ce3db2ac69160c7622f497) set(TA_TRACKED_CUTT_TAG 0e8685bf82910bc7435835f846e88f1b39f47f09) set(TA_TRACKED_CUTT_PREVIOUS_TAG 592198b93c93b7ca79e7900b9a9f2e79f9dafec3) From ecbb3c7b63fe635b23bc9da7a6e7963f2eb792da Mon Sep 17 00:00:00 2001 From: Bimal Gaudel <44385776+bimalgaudel@users.noreply.github.com> Date: Thu, 11 Feb 2021 21:04:07 -0500 Subject: [PATCH 07/29] Update README.md for TA::TiledRange1 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d8d86e944..853629526a 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ int main(int argc, char** argv) { // Construct a 2D tiled range structure that defines // the tiling of an array. Each dimension contains // 10 tiles. - TA::TiledRange trange = - { { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, - { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 } }; + auto trange = TA::TiledRange{ + TA::TiledRange1{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}, + TA::TiledRange1{0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}}; // Construct and fill the argument arrays with data TA::TArrayD A(world, trange); From 949a982fe31ac37a1cf62699dd153dfd66ed711a Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Fri, 26 Feb 2021 17:16:21 -0500 Subject: [PATCH 08/29] typo --- src/TiledArray/util/annotation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TiledArray/util/annotation.h b/src/TiledArray/util/annotation.h index 2b3ed8ce81..49ca916aff 100644 --- a/src/TiledArray/util/annotation.h +++ b/src/TiledArray/util/annotation.h @@ -54,7 +54,7 @@ inline auto remove_whitespace(std::string s) { return s; } -/// Splits a sting into tokens based on a character delimiter +/// Splits a string into tokens based on a character delimiter /// /// This function assumes that the input string can be considered a series of /// delimiter separated tokens. It will split the string into tokens and return From 3f563ca4be97dc06f8ab799b2810022c27df15d5 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Fri, 26 Feb 2021 17:19:34 -0500 Subject: [PATCH 09/29] streamline DistArray::check_str_index --- src/TiledArray/dist_array.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index 664f5da503..4ed557613c 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -1498,10 +1498,12 @@ class DistArray : public madness::archive::ParallelSerializableObject { if (is_tot) { // Make sure the index is capable of being interpreted as a ToT index TA_ASSERT(detail::is_tot_index(vars)); - const auto idx = detail::split_index(vars); // Rank of outer tiles must match number of outer indices - TA_ASSERT(idx.first.size() == rank); + // is_tot_index(vars) implies vars.find(';') < vars.size() + TA_ASSERT(std::count(vars.begin(), vars.begin() + vars.find(';'), ',') + + 1ul == + rank); // Check inner index rank? } else { @@ -1509,7 +1511,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { TA_ASSERT(!detail::is_tot_index(vars)); // Number of indices must match rank - TA_ASSERT(detail::tokenize_index(vars, ',').size() == rank); + TA_ASSERT(std::count(vars.begin(), vars.end(), ',') + 1ul == rank); } #endif // NDEBUG } From d0318dcb9e669c4d5ef9fd3d0763b6c3780fb963 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Fri, 12 Mar 2021 16:22:05 -0500 Subject: [PATCH 10/29] updated pre-commit-config.yaml to remove clang-format --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74692eb749..23f1509ca1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -40,4 +40,3 @@ repos: files: \.(c|cc|cxx|cpp|h|hpp|hxx)$ entry: clang-format -i args: [--style=file] - additional_dependencies: [clang-format] From 24c40a97a8dd19817f8d85b85a725724fced9df4 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Fri, 12 Mar 2021 16:22:34 -0500 Subject: [PATCH 11/29] [cmake] bump BTAS tag --- INSTALL.md | 2 +- external/versions.cmake | 4 +- src/TiledArray/external/btas.h | 87 ---------------------------------- src/TiledArray/util/vector.h | 28 +---------- 4 files changed, 4 insertions(+), 117 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 42b473da4e..a2f288f66d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -40,7 +40,7 @@ Both methods are supported. However, for most users we _strongly_ recommend to b - Boost.Container: header-only - Boost.Test: header-only or (optionally) as a compiled library, *only used for unit testing* - Boost.Range: header-only, *only used for unit testing* -- [BTAS](http://github.com/ValeevGroup/BTAS), tag 8752fb97fc68d1982c48283aba4b03c744389ba8 . If usable BTAS installation is not found, TiledArray will download and compile +- [BTAS](http://github.com/ValeevGroup/BTAS), tag bbb11894802d7e2f89182a2e7fce9aed1078f851 . If usable BTAS installation is not found, TiledArray will download and compile BTAS from source. *This is the recommended way to compile BTAS for all users*. - [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag b22ee85059e6ccc9a6e803ba0550652ece8d9df1 . Only the MADworld runtime and BLAS/LAPACK C API component of MADNESS is used by TiledArray. diff --git a/external/versions.cmake b/external/versions.cmake index 8ad6d8eb6b..cb0d892014 100644 --- a/external/versions.cmake +++ b/external/versions.cmake @@ -22,8 +22,8 @@ set(TA_TRACKED_MADNESS_PREVIOUS_TAG 925552feaf326cca8e83de7bd042074ad3cfd3f1) set(TA_TRACKED_MADNESS_VERSION 0.10.1) set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1) -set(TA_TRACKED_BTAS_TAG 8752fb97fc68d1982c48283aba4b03c744389ba8) -set(TA_TRACKED_BTAS_PREVIOUS_TAG 1ee43ef413c12166e3ce3db2ac69160c7622f497) +set(TA_TRACKED_BTAS_TAG bbb11894802d7e2f89182a2e7fce9aed1078f851) +set(TA_TRACKED_BTAS_PREVIOUS_TAG 8752fb97fc68d1982c48283aba4b03c744389ba8) set(TA_TRACKED_CUTT_TAG 0e8685bf82910bc7435835f846e88f1b39f47f09) set(TA_TRACKED_CUTT_PREVIOUS_TAG 592198b93c93b7ca79e7900b9a9f2e79f9dafec3) diff --git a/src/TiledArray/external/btas.h b/src/TiledArray/external/btas.h index 8f1b99c9e9..294298d50d 100644 --- a/src/TiledArray/external/btas.h +++ b/src/TiledArray/external/btas.h @@ -851,91 +851,4 @@ struct Cast, }; } // namespace TiledArray -namespace madness { -namespace archive { - -template -struct ArchiveLoadImpl> { - static inline void load(const Archive& ar, btas::varray& x) { - typename btas::varray::size_type n{}; - ar& n; - x.resize(n); - for (typename btas::varray::value_type& xi : x) ar& xi; - } -}; - -template -struct ArchiveStoreImpl> { - static inline void store(const Archive& ar, const btas::varray& x) { - ar& x.size(); - for (const typename btas::varray::value_type& xi : x) ar& xi; - } -}; - -template -struct ArchiveLoadImpl> { - static inline void load(const Archive& ar, - btas::BoxOrdinal<_Order, _Index>& o) { - typename btas::BoxOrdinal<_Order, _Index>::stride_type stride{}; - typename btas::BoxOrdinal<_Order, _Index>::value_type offset{}; - bool cont{}; - ar& stride& offset& cont; - o = btas::BoxOrdinal<_Order, _Index>(std::move(stride), std::move(offset), - std::move(cont)); - } -}; - -template -struct ArchiveStoreImpl> { - static inline void store(const Archive& ar, - const btas::BoxOrdinal<_Order, _Index>& o) { - ar& o.stride() & o.offset() & o.contiguous(); - } -}; - -template -struct ArchiveLoadImpl> { - static inline void load(const Archive& ar, - btas::RangeNd<_Order, _Index, _Ordinal>& r) { - typedef typename btas::BaseRangeNd< - btas::RangeNd<_Order, _Index, _Ordinal>>::index_type index_type; - index_type lobound{}, upbound{}; - _Ordinal ordinal{}; - ar& lobound& upbound& ordinal; - r = btas::RangeNd<_Order, _Index, _Ordinal>( - std::move(lobound), std::move(upbound), std::move(ordinal)); - } -}; - -template -struct ArchiveStoreImpl> { - static inline void store(const Archive& ar, - const btas::RangeNd<_Order, _Index, _Ordinal>& r) { - ar& r.lobound() & r.upbound() & r.ordinal(); - } -}; - -template -struct ArchiveLoadImpl> { - static inline void load(const Archive& ar, - btas::Tensor<_T, _Range, _Store>& t) { - _Range range{}; - _Store store{}; - ar& range& store; - t = btas::Tensor<_T, _Range, _Store>(std::move(range), std::move(store)); - } -}; - -template -struct ArchiveStoreImpl> { - static inline void store(const Archive& ar, - const btas::Tensor<_T, _Range, _Store>& t) { - ar& t.range() & t.storage(); - } -}; -} // namespace archive -} // namespace madness - #endif /* TILEDARRAY_EXTERNAL_BTAS_H__INCLUDED */ diff --git a/src/TiledArray/util/vector.h b/src/TiledArray/util/vector.h index 5d578ceb82..e98688b20f 100644 --- a/src/TiledArray/util/vector.h +++ b/src/TiledArray/util/vector.h @@ -26,9 +26,9 @@ #ifndef TILEDARRAY_UTIL_VECTOR_H #define TILEDARRAY_UTIL_VECTOR_H -#include "TiledArray/config.h" #include #include +#include "TiledArray/config.h" #include #include @@ -84,32 +84,6 @@ constexpr auto iv(Int i0, Ints... rest) { } // namespace container } // namespace TiledArray -namespace madness { -namespace archive { - -template -struct ArchiveLoadImpl> { - static inline void load(const Archive& ar, - boost::container::small_vector& x) { - std::size_t n{}; - ar& n; - x.resize(n); - for (auto& xi : x) ar& xi; - } -}; - -template -struct ArchiveStoreImpl> { - static inline void store(const Archive& ar, - const boost::container::small_vector& x) { - ar& x.size(); - for (const auto& xi : x) ar& xi; - } -}; - -} // namespace archive -} // namespace madness - namespace TiledArray { /// Vector output stream operator From 0ad370a0efaf9df60c5e3fa7c46ddebdfeca57c2 Mon Sep 17 00:00:00 2001 From: asadchev Date: Tue, 9 Mar 2021 16:29:24 -0500 Subject: [PATCH 12/29] Refactor TA_ASSERT --- CMakeLists.txt | 33 +++------ src/TiledArray/config.h.in | 9 ++- src/TiledArray/dist_array.h | 2 +- src/TiledArray/error.h | 124 +++++++++++---------------------- src/TiledArray/tiledarray.cpp | 9 +++ tests/ta_test.cpp | 5 +- tests/tot_dist_array_part2.cpp | 8 --- 7 files changed, 70 insertions(+), 120 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42cccfa424..56cf6d8ea4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,7 @@ if((ENABLE_GPERFTOOLS OR ENABLE_TCMALLOC_MINIMAL) AND CMAKE_SYSTEM_NAME MATCHES set(ENABLE_LIBUNWIND ON) add_feature_info(Libunwind ENABLE_LIBUNWIND "Libunwind provides stack unwinding") endif() -option(TA_BUILD_UNITTEST "Causes building TiledArray unit tests" OFF) +option(TA_BUILD_UNITTEST "Causes building TiledArray unit tests" ON) option(TA_EXPERT "TiledArray Expert mode: disables automatically downloading or building dependencies" OFF) option(TA_SIGNED_1INDEX_TYPE "Enables the use of signed 1-index coordinate type (OFF in 1.0.0-alpha.2 and older)" ON) @@ -255,28 +255,17 @@ include(CheckTypeSize) check_type_size("long double" TILEDARRAY_HAS_LONG_DOUBLE LANGUAGE CXX) 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 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() +# TA_ASSERT +set (TA_ASSERT_POLICY TA_ASSERT_THROW CACHE STRING "") +set_property( + CACHE TA_ASSERT_POLICY PROPERTY + STRINGS TA_ASSERT_THROW TA_ASSERT_ABORT TA_ASSERT_IGNORE) + # 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) -elseif (TA_ERROR STREQUAL throw) - set (TA_DEFAULT_ERROR 1) -elseif (TA_ERROR STREQUAL assert) - set (TA_DEFAULT_ERROR 2) -elseif (TA_ERROR STREQUAL abort) - set (TA_DEFAULT_ERROR 3) +if (NOT (TA_ASSERT_POLICY STREQUAL TA_ASSERT_THROW)) + if (TA_BUILD_UNITTEST) + message(FATAL_ERROR "TA_ASSERT_POLICY=${TA_ASSERT_POLICY} requires TA_BUILD_UNITTEST=OFF") + endif(TA_BUILD_UNITTEST) endif() ########################## diff --git a/src/TiledArray/config.h.in b/src/TiledArray/config.h.in index f26da58c13..8e66bf7159 100644 --- a/src/TiledArray/config.h.in +++ b/src/TiledArray/config.h.in @@ -53,8 +53,11 @@ #endif -/* Defines the default error checking behavior. none = 0, throw = 1, assert = 2, abort = 3 */ -#define TA_DEFAULT_ERROR @TA_DEFAULT_ERROR@ +/* Defines the default error checking behavior */ +#define TA_ASSERT_THROW 2 +#define TA_ASSERT_ABORT 3 +#define TA_ASSERT_IGNORE 4 +#define TA_ASSERT_POLICY @TA_ASSERT_POLICY@ /* define if compiler supports long double, the value is sizeof(long double) */ #cmakedefine TILEDARRAY_HAS_LONG_DOUBLE 1 @@ -69,7 +72,7 @@ #cmakedefine TILEDARRAY_CACHELINE_SIZE @TILEDARRAY_CACHELINE_SIZE@ /* Define if TA has enabled ScaLAPACK Bindings */ -#cmakedefine TILEDARRAY_HAS_SCALAPACK 1 +#cmakedefine TILEDARRAY_HAS_SCALAPACK 1 /* Define if TiledArray configured with CUDA support */ #cmakedefine TILEDARRAY_HAS_CUDA @TILEDARRAY_HAS_CUDA@ diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index 4ed557613c..0378c01f43 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -1487,7 +1487,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// @warning this tests contents of @p vars using #TA_ASSERT() only if /// preprocessor macro @c NDEBUG is not defined void check_str_index(const std::string& vars) const { -#ifndef NDEBUG +#if (TA_ASSERT_POLICY != TA_ASSERT_IGNORE) // Only check indices if the PIMPL is initialized (okay to not initialize // the RHS of an equation) if (!is_initialized()) return; diff --git a/src/TiledArray/error.h b/src/TiledArray/error.h index 147e9fe7f4..87a2ca1052 100644 --- a/src/TiledArray/error.h +++ b/src/TiledArray/error.h @@ -22,43 +22,57 @@ #include -// Check for default error checking method, which is determined by -// TA_DEFAULT_ERROR, which is defined in TiledArray/config.h. -#ifdef TA_DEFAULT_ERROR -#if !defined(TA_EXCEPTION_ERROR) && !defined(TA_ASSERT_ERROR) && \ - !defined(TA_NO_ERROR) && !defined(TA_ABORT_ERROR) -#if TA_DEFAULT_ERROR == 0 -#define TA_NO_ERROR -#elif TA_DEFAULT_ERROR == 1 -#define TA_EXCEPTION_ERROR -#elif TA_DEFAULT_ERROR == 2 -#define TA_ASSERT_ERROR -#elif TA_DEFAULT_ERROR == 3 -#define TA_ABORT_ERROR -#endif // TA_DEFAULT_ERROR == ? -#endif // !defined(TA_EXCEPTION_ERROR) && !defined(TA_ASSERT_ERROR) && - // !defined(TA_NO_ERROR) && !defined(TA_ABORT_ERROR) -#endif // TA_DEFAULT_ERROR - -#include +#ifndef TA_ASSERT_POLICY +#define TA_ASSERT_POLICY TA_ASSERT_THROW +#endif + +#define TA_STRINGIZE_IMPL(s) #s +#define TA_STRINGIZE(s) TA_STRINGIZE_IMPL(s) + +#define TA_ASSERT_MESSAGE(EXPR, ...) \ + __FILE__ ":" TA_STRINGIZE(__LINE__) ": " \ + "TA_ASSERT failed: " TA_STRINGIZE(EXPR) + +#if TA_ASSERT_POLICY == TA_ASSERT_IGNORE +#define TA_ASSERT(...) do { } while(0) +#else +#define TA_ASSERT(EXPR, ...) \ + do { \ + if (!(EXPR)) \ + TiledArray::assert_failed(TA_ASSERT_MESSAGE(EXPR, __VA_ARGS__)); \ + } while(0) + +#endif + +#include +#include + namespace TiledArray { -class Exception : public std::exception { - public: - Exception(const char* m) : message_(m) {} +void ta_abort(); - virtual const char* what() const noexcept { return message_; } +void ta_abort(const std::string &m); - private: - const char* message_; +class Exception : public std::runtime_error { + using std::runtime_error::runtime_error; }; // class Exception /// Place a break point on this function to stop before TiledArray exceptions /// are thrown. inline void exception_break() {} -} // namespace TiledArray -#define TA_STRINGIZE(s) #s +inline void assert_failed(const std::string &m) { +#if TA_ASSERT_POLICY == TA_ASSERT_THROW + TiledArray::exception_break(); + throw TiledArray::Exception(m); +#elif TA_ASSERT_POLICY == TA_ASSERT_ABORT + TiledArray::ta_abort(m); +#elif TA_ASSERT_POLICY != TA_ASSERT_IGNORE +#error Invalid TA_ASSERT_POLICY parameter +#endif +} + +} // namespace TiledArray #define TA_EXCEPTION_MESSAGE(file, line, mess) \ "TiledArray: exception at " file "(" TA_STRINGIZE(line) "): " mess @@ -72,62 +86,6 @@ inline void exception_break() {} throw TiledArray::Exception(TA_EXCEPTION_MESSAGE(__FILE__, __LINE__, m)); \ } while (0) -#ifdef TA_EXCEPTION_ERROR -// This section defines the behavior for TiledArray assertion error checking -// which will throw exceptions. -#ifdef TA_ASSERT_ERROR -#undef TA_ASSERT_ERROR -#endif -#ifdef TA_ABORT_ERROR -#undef TA_ABORT_ERROR -#endif - -/// TiledArray assertion is configured to throw TiledArray::Exception -/// if \p a is false -/// \param a an expression convertible to bool -#define TA_ASSERT(a) \ - do { \ - if (!(a)) TA_EXCEPTION("assertion failure"); \ - } while (0) - -#elif defined(TA_ASSERT_ERROR) -// This sections defines behavior for TiledArray assertion error checking which -// uses assertions. -#include - -/// TiledArray assertion is configured to call \c assert() -/// if \p a is false -/// \param a an expression convertible to bool -#define TA_ASSERT(a) assert(a) - -#elif defined(TA_ABORT_ERROR) -// This sections defines behavior for TiledArray assertion error checking which -// calls std::abort -#include - -/// TiledArray assertion is configured to call std::abort if \p a is false -/// \param a an expression convertible to bool -#define TA_ASSERT(a) \ - do { \ - if (!(a)) std::abort(); \ - } while (0) - -#else -// This section defines behavior for TiledArray assertion error checking which -// does no error checking. -// WARNING: TiledArray will perform no error checking. -// this avoids unused variable warnings, see -// http://cnicholson.net/2009/02/stupid-c-tricks-adventures-in-assert/ - -/// TiledArray assertion is configured to do nothing -/// \param a an expression convertible to bool -#define TA_ASSERT(a) \ - do { \ - (void)sizeof(a); \ - } while (0) - -#endif // TA_EXCEPTION_ERROR - #ifdef TILEDARRAY_NO_USER_ERROR_MESSAGES #define TA_USER_ERROR_MESSAGE(m) #else diff --git a/src/TiledArray/tiledarray.cpp b/src/TiledArray/tiledarray.cpp index 44bcabd788..4f6aa96176 100644 --- a/src/TiledArray/tiledarray.cpp +++ b/src/TiledArray/tiledarray.cpp @@ -132,3 +132,12 @@ void TiledArray::finalize() { initialized_accessor() = false; finalized_accessor() = true; } + +void TiledArray::ta_abort() { + std::abort(); +} + +void TiledArray::ta_abort(const std::string &m) { + std::cerr << m << std::endl; + ta_abort(); +} diff --git a/tests/ta_test.cpp b/tests/ta_test.cpp index c342e7523a..8e2bc45705 100644 --- a/tests/ta_test.cpp +++ b/tests/ta_test.cpp @@ -24,9 +24,8 @@ #include "unit_test_config.h" #include -#ifndef TA_EXCEPTION_ERROR -#error \ - "TiledArray unit tests can only be built if CMake variable TA_ERROR is set of \"throw\"" +#if (TA_ASSERT_POLICY != TA_ASSERT_THROW) +#error "TiledArray unit tests require TA_ASSERT_POLICY=TA_ASSERT_THROW" #endif GlobalFixture::GlobalFixture() { diff --git a/tests/tot_dist_array_part2.cpp b/tests/tot_dist_array_part2.cpp index 30c3634a40..ed3b2b71af 100644 --- a/tests/tot_dist_array_part2.cpp +++ b/tests/tot_dist_array_part2.cpp @@ -348,17 +348,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(call_operator, TestParam, test_params) { std::string outer_idx = (outer_rank == 1 ? "i" : "i,j"); std::string inner_idx = (inner_rank == 1 ? "k" : "k,l"); - // call operators validate inputs only if NDEBUG not defined -#ifndef NDEBUG if (m_world.nproc() == 1) { using except_t = TiledArray::Exception; // Throws if no semicolon BOOST_CHECK_THROW(t(outer_idx), except_t); - // Throws if wrong outer rank BOOST_CHECK_THROW(t("i,j,k,l,m;" + inner_idx), except_t); } -#endif auto vars = outer_idx + ";" + inner_idx; auto expr = t(vars); @@ -375,17 +371,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(const_call_operator, TestParam, test_params) { std::string outer_idx = (outer_rank == 1 ? "i" : "i,j"); std::string inner_idx = (inner_rank == 1 ? "k" : "k,l"); - // call operators validate inputs only if NDEBUG not defined -#ifndef NDEBUG if (m_world.nproc() == 1) { using except_t = TiledArray::Exception; // Throws if no semicolon BOOST_CHECK_THROW(t(outer_idx), except_t); - // Throws if wrong outer rank BOOST_CHECK_THROW(t("i,j,k,l,m;" + inner_idx), except_t); } -#endif auto vars = outer_idx + ";" + inner_idx; auto expr = t(vars); From 77a0dae9b63106490facf9ed3ba0c6137df4433e Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sun, 14 Mar 2021 15:56:53 -0400 Subject: [PATCH 13/29] dox --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 42b473da4e..e13950f20d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -135,7 +135,6 @@ $ cmake -D CMAKE_INSTALL_PREFIX=/path/to/install/tiledarray \ ``` $ cmake -D CMAKE_INSTALL_PREFIX=/path/to/install/tiledarray \ -D CMAKE_BUILD_TYPE=Debug \ - -D TA_BUILD_UNITTEST=ON \ -D BOOST_ROOT=/path/to/boost \ -D CMAKE_PREFIX_PATH=/path/to/dependency;/path/to/another/dependency \ $TILEDARRAY_SOURCE_DIR @@ -349,7 +348,8 @@ 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. 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_ASSERT_POLICY` -- Set to `TA_ASSERT_IGNORE` to disable `TA_ASSERT` assertions, `TA_ASSERT_THROW` to cause `TA_ASSERT` assertions to throw, `TA_ASSERT_ABORT` to cause `TA_ASSERT` assertions to abort. The default is `TA_ASSERT_THROW`. +* `TA_BUILD_UNITTEST` -- Set of `OFF` to disable building unit tests. The default is `ON`. * `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. From 9394446529920d768a40f58fb2db69acbc844cad Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sun, 14 Mar 2021 15:57:13 -0400 Subject: [PATCH 14/29] removed unnecessary TA_BUILD_UNITTEST=ON --- .github/workflows/ci.yml | 1 - .gitlab-ci.yml | 1 - bin/build-linux.sh | 2 -- bin/docker-build.sh | 2 +- 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 999c00f459..ed5b9001a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ jobs: CXX : ${{ matrix.cxx }} BUILD_CONFIG : > -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DTA_BUILD_UNITTEST=ON -DMPIEXEC_PREFLAGS='--bind-to;none;--allow-run-as-root' steps: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee54cf681a..ed72df3e72 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,6 @@ variables: MAD_NUM_THREADS : 2 TA_TARGETS : "tiledarray examples ta_test check" TA_CONFIG : > - TA_BUILD_UNITTEST=TRUE CMAKE_BUILD_TYPE=${BUILD_TYPE} ${TA_PYTHON} ${ENABLE_CUDA} diff --git a/bin/build-linux.sh b/bin/build-linux.sh index bf5d1391b6..bf27d220fe 100755 --- a/bin/build-linux.sh +++ b/bin/build-linux.sh @@ -96,7 +96,6 @@ if [ "$BUILD_TYPE" = "Debug" ]; then -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}/madness;${INSTALL_PREFIX}/eigen3;${INSTALL_PREFIX}/boost" \ -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \ -DTA_PYTHON="${TA_PYTHON}" \ - -DTA_BUILD_UNITTEST=ON \ -DENABLE_SCALAPACK=ON else @@ -126,7 +125,6 @@ else -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}/eigen3;${INSTALL_PREFIX}/boost" \ -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" \ -DTA_PYTHON="${TA_PYTHON}" \ - -DTA_BUILD_UNITTEST=ON \ -DENABLE_SCALAPACK=ON fi diff --git a/bin/docker-build.sh b/bin/docker-build.sh index 5deb1fa9da..a0d052b497 100755 --- a/bin/docker-build.sh +++ b/bin/docker-build.sh @@ -35,7 +35,7 @@ RUN apt-get update && apt-get install -y python3 ninja-build liblapacke-dev libl RUN CMAKE_URL="https://cmake.org/files/v${CMAKE_VERSION%.[0-9]}/cmake-${CMAKE_VERSION}-Linux-x86_64.tar.gz" && wget --no-check-certificate -O - \$CMAKE_URL | tar --strip-components=1 -xz -C /usr/local ENV CMAKE=/usr/local/bin/cmake # 3. download and build TiledArray -RUN cd /usr/local/src && git clone --depth=1 https://github.com/ValeevGroup/tiledarray.git && cd /usr/local/src/tiledarray && mkdir build && cd build && \$CMAKE .. -G Ninja -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_C_COMPILER=clang-8 -DTA_BUILD_UNITTEST=ON -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=RelWithDebInfo && \$CMAKE --build . --target tiledarray && \$CMAKE --build . --target check && $CMAKE --build . --target examples && \$CMAKE --build . --target install +RUN cd /usr/local/src && git clone --depth=1 https://github.com/ValeevGroup/tiledarray.git && cd /usr/local/src/tiledarray && mkdir build && cd build && \$CMAKE .. -G Ninja -DCMAKE_CXX_COMPILER=clang++-8 -DCMAKE_C_COMPILER=clang-8 -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=RelWithDebInfo && \$CMAKE --build . --target tiledarray && \$CMAKE --build . --target check && $CMAKE --build . --target examples && \$CMAKE --build . --target install # Clean up APT when done. RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* From 339606478d9250b75aa0bb3f0ad7f0350834fcf7 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Wed, 24 Mar 2021 11:08:07 -0400 Subject: [PATCH 15/29] function_ref is comparable --- src/TiledArray/util/function.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TiledArray/util/function.h b/src/TiledArray/util/function.h index 9acb593f68..b9449eda13 100644 --- a/src/TiledArray/util/function.h +++ b/src/TiledArray/util/function.h @@ -107,6 +107,9 @@ class function_ref { /// Converts to true if non-default initialized explicit operator bool() const { return obj_; } + /// @return true if `other` refers to the same callable as `*this` + bool operator==(const function_ref& other) const { return obj_ == other.obj_; } + private: void *obj_ = nullptr; R (*callback_)(void *, Args...) = nullptr; From 3b1e8b7d64c563ef8ea785da8b45da4617c1cc86 Mon Sep 17 00:00:00 2001 From: David Williams-Young Date: Thu, 25 Mar 2021 21:15:55 +0000 Subject: [PATCH 16/29] Fix default vector return conventions in rank-local SVD --- src/TiledArray/math/linalg/rank-local.cpp | 11 ++++++----- tests/CMakeLists.txt | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/TiledArray/math/linalg/rank-local.cpp b/src/TiledArray/math/linalg/rank-local.cpp index e26ec3da59..c74ee8ed52 100644 --- a/src/TiledArray/math/linalg/rank-local.cpp +++ b/src/TiledArray/math/linalg/rank-local.cpp @@ -143,18 +143,19 @@ template void svd(Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { integer m = A.rows(); integer n = A.cols(); + integer k = std::min(m, n); T* a = A.data(); integer lda = A.rows(); - S.resize(std::min(m, n)); + S.resize(k); T* s = S.data(); auto jobu = lapack::Job::NoVec; T* u = nullptr; integer ldu = m; if (U) { - jobu = lapack::Job::AllVec; - U->resize(m, n); + jobu = lapack::Job::SomeVec; + U->resize(m, k); u = U->data(); ldu = U->rows(); } @@ -163,8 +164,8 @@ void svd(Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { T* vt = nullptr; integer ldvt = n; if (VT) { - jobvt = lapack::Job::AllVec; - VT->resize(n, m); + jobvt = lapack::Job::SomeVec; + VT->resize(k, n); vt = VT->data(); ldvt = VT->rows(); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d75c0f8e5f..bab83c0b5c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -88,11 +88,11 @@ set(ta_test_src_files ta_test.cpp reduce_task.cpp proc_grid.cpp dist_eval_contraction_eval.cpp - expressions.cpp - expressions_sparse.cpp - expressions_complex.cpp - expressions_btas.cpp - expressions_mixed.cpp + #expressions.cpp + #expressions_sparse.cpp + #expressions_complex.cpp + #expressions_btas.cpp + #expressions_mixed.cpp foreach.cpp solvers.cpp initializer_list.cpp @@ -102,7 +102,7 @@ set(ta_test_src_files ta_test.cpp tot_dist_array_part2.cpp random.cpp trace.cpp - tot_expressions.cpp + #tot_expressions.cpp annotation.cpp diagonal_array.cpp contraction_helpers.cpp From 343cc88a17b51d4773a20303047967ff6f69ebce Mon Sep 17 00:00:00 2001 From: David Williams-Young Date: Thu, 25 Mar 2021 21:44:45 +0000 Subject: [PATCH 17/29] Extended the flexibility of the rank-local SVD wrapper to allow for all allowed combinations of vector Job options provided by LAPACK --- src/TiledArray/math/linalg/rank-local.cpp | 55 ++++++++++++++++++----- src/TiledArray/math/linalg/rank-local.h | 11 ++++- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/TiledArray/math/linalg/rank-local.cpp b/src/TiledArray/math/linalg/rank-local.cpp index c74ee8ed52..3cc10a99c8 100644 --- a/src/TiledArray/math/linalg/rank-local.cpp +++ b/src/TiledArray/math/linalg/rank-local.cpp @@ -140,7 +140,7 @@ void heig(Matrix& A, Matrix& B, std::vector& W) { } template -void svd(Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { +void svd(Job jobu, Job jobvt, Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { integer m = A.rows(); integer n = A.cols(); integer k = std::min(m, n); @@ -150,6 +150,7 @@ void svd(Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { S.resize(k); T* s = S.data(); +#if 0 auto jobu = lapack::Job::NoVec; T* u = nullptr; integer ldu = m; @@ -169,6 +170,40 @@ void svd(Matrix& A, std::vector& S, Matrix* U, Matrix* VT) { vt = VT->data(); ldvt = VT->rows(); } +#else + T* u = nullptr; + T* vt = nullptr; + integer ldu = 1, ldvt = 1; + if( (jobu == Job::SomeVec or jobu == Job::AllVec) and (not U) ) + TA_LAPACK_ERROR("Requested out-of-place right singular vectors with null U input"); + if( (jobvt == Job::SomeVec or jobvt == Job::AllVec) and (not VT) ) + TA_LAPACK_ERROR("Requested out-of-place left singular vectors with null VT input"); + + if( jobu == Job::SomeVec ) { + U->resize(m, k); + u = U->data(); + ldu = m; + } + + if( jobu == Job::AllVec ) { + U->resize(m, m); + u = U->data(); + ldu = m; + } + + if( jobvt == Job::SomeVec ) { + VT->resize(k, n); + vt = VT->data(); + ldvt = k; + } + + if( jobvt == Job::AllVec ) { + VT->resize(n, n); + vt = VT->data(); + ldvt = n; + } + +#endif TA_LAPACK(gesvd, jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt); } @@ -195,15 +230,15 @@ void lu_inv(Matrix& A) { TA_LAPACK(getri, n, a, lda, ipiv.data()); } -#define TA_LAPACK_EXPLICIT(MATRIX, VECTOR) \ - template void cholesky(MATRIX&); \ - template void cholesky_linv(MATRIX&); \ - template void cholesky_solve(MATRIX&, MATRIX&); \ - template void cholesky_lsolve(Op, MATRIX&, MATRIX&); \ - template void heig(MATRIX&, VECTOR&); \ - template void heig(MATRIX&, MATRIX&, VECTOR&); \ - template void svd(MATRIX&, VECTOR&, MATRIX*, MATRIX*); \ - template void lu_solve(MATRIX&, MATRIX&); \ +#define TA_LAPACK_EXPLICIT(MATRIX, VECTOR) \ + template void cholesky(MATRIX&); \ + template void cholesky_linv(MATRIX&); \ + template void cholesky_solve(MATRIX&, MATRIX&); \ + template void cholesky_lsolve(Op, MATRIX&, MATRIX&); \ + template void heig(MATRIX&, VECTOR&); \ + template void heig(MATRIX&, MATRIX&, VECTOR&); \ + template void svd(Job,Job,MATRIX&, VECTOR&, MATRIX*, MATRIX*); \ + template void lu_solve(MATRIX&, MATRIX&); \ template void lu_inv(MATRIX&); TA_LAPACK_EXPLICIT(Matrix, std::vector); diff --git a/src/TiledArray/math/linalg/rank-local.h b/src/TiledArray/math/linalg/rank-local.h index 144c844e3c..87d4b44a56 100644 --- a/src/TiledArray/math/linalg/rank-local.h +++ b/src/TiledArray/math/linalg/rank-local.h @@ -10,6 +10,8 @@ namespace TiledArray::math::linalg::rank_local { +using Job = ::lapack::Job; + template using Matrix = ::Eigen::Matrix; @@ -35,7 +37,14 @@ template void heig(Matrix &A, Matrix &B, std::vector &W); template -void svd(Matrix &A, std::vector &S, Matrix *U, Matrix *VT); +void svd(Job jobu, Job jobvt, Matrix &A, std::vector &S, Matrix *U, Matrix *VT); + +template +void svd(Matrix &A, std::vector &S, Matrix *U, Matrix *VT) { + svd( U ? Job::SomeVec : Job::NoVec, + VT ? Job::SomeVec : Job::NoVec, + A, S, U, VT ); +} template void lu_solve(Matrix &A, Matrix &B); From f3e04149388a36f5e25278be39e028366f535d95 Mon Sep 17 00:00:00 2001 From: David Williams-Young Date: Thu, 25 Mar 2021 21:49:24 +0000 Subject: [PATCH 18/29] Cleanup of old SVD code --- src/TiledArray/math/linalg/rank-local.cpp | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/TiledArray/math/linalg/rank-local.cpp b/src/TiledArray/math/linalg/rank-local.cpp index 3cc10a99c8..5413ad0e5f 100644 --- a/src/TiledArray/math/linalg/rank-local.cpp +++ b/src/TiledArray/math/linalg/rank-local.cpp @@ -150,27 +150,6 @@ void svd(Job jobu, Job jobvt, Matrix& A, std::vector& S, Matrix* U, Mat S.resize(k); T* s = S.data(); -#if 0 - auto jobu = lapack::Job::NoVec; - T* u = nullptr; - integer ldu = m; - if (U) { - jobu = lapack::Job::SomeVec; - U->resize(m, k); - u = U->data(); - ldu = U->rows(); - } - - auto jobvt = lapack::Job::NoVec; - T* vt = nullptr; - integer ldvt = n; - if (VT) { - jobvt = lapack::Job::SomeVec; - VT->resize(k, n); - vt = VT->data(); - ldvt = VT->rows(); - } -#else T* u = nullptr; T* vt = nullptr; integer ldu = 1, ldvt = 1; @@ -203,8 +182,6 @@ void svd(Job jobu, Job jobvt, Matrix& A, std::vector& S, Matrix* U, Mat ldvt = n; } -#endif - TA_LAPACK(gesvd, jobu, jobvt, m, n, a, lda, s, u, ldu, vt, ldvt); } From cd5f534f67aca4a2dea54877a98c4aaaeba1605e Mon Sep 17 00:00:00 2001 From: David Williams-Young Date: Thu, 25 Mar 2021 15:12:22 -0700 Subject: [PATCH 19/29] Re-enable expressions tests --- tests/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bab83c0b5c..d75c0f8e5f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -88,11 +88,11 @@ set(ta_test_src_files ta_test.cpp reduce_task.cpp proc_grid.cpp dist_eval_contraction_eval.cpp - #expressions.cpp - #expressions_sparse.cpp - #expressions_complex.cpp - #expressions_btas.cpp - #expressions_mixed.cpp + expressions.cpp + expressions_sparse.cpp + expressions_complex.cpp + expressions_btas.cpp + expressions_mixed.cpp foreach.cpp solvers.cpp initializer_list.cpp @@ -102,7 +102,7 @@ set(ta_test_src_files ta_test.cpp tot_dist_array_part2.cpp random.cpp trace.cpp - #tot_expressions.cpp + tot_expressions.cpp annotation.cpp diagonal_array.cpp contraction_helpers.cpp From 19d465ac13f88778b76556c6bb6d6f46b48b144f Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Fri, 2 Apr 2021 08:24:38 -0400 Subject: [PATCH 20/29] numeric_type trait for Eigen matrices not needed since Eigen 3.3 value_type were added via https://gitlab.com/libeigen/eigen/-/issues/360 --- src/TiledArray/type_traits.h | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/TiledArray/type_traits.h b/src/TiledArray/type_traits.h index b6ce5ec3b4..c08c2ca048 100644 --- a/src/TiledArray/type_traits.h +++ b/src/TiledArray/type_traits.h @@ -65,17 +65,6 @@ inline constexpr bool is_integral_v = is_integral::value; ////////////////////////////////////////////////////////////////////////////////////////////// // forward declarations -namespace Eigen { - -template -class Matrix; -template -class Array; -template -class Map; - -} // namespace Eigen - namespace madness { template @@ -736,20 +725,6 @@ struct numeric_type::value && !is_numeric_v>::type> : public numeric_type::type> {}; -template -struct numeric_type, void> - : public numeric_type::Scalar> {}; - -template -struct numeric_type, void> - : public numeric_type::Scalar> {}; - -template -struct numeric_type, void> - : public numeric_type {}; - /// \c numeric_t is an alias for \c numeric_type::type template using numeric_t = typename TiledArray::detail::numeric_type::type; From 6e9a98b3254977d81091101e6241d3b2bb6fe9e1 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 5 Apr 2021 13:59:25 -0400 Subject: [PATCH 21/29] solver adaptors for Eigen data --- src/TiledArray/math/linalg/basic.h | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/TiledArray/math/linalg/basic.h b/src/TiledArray/math/linalg/basic.h index 32d7cbb94d..88f995f8ea 100644 --- a/src/TiledArray/math/linalg/basic.h +++ b/src/TiledArray/math/linalg/basic.h @@ -27,9 +27,12 @@ #define TILEDARRAY_MATH_LINALG_BASIC_H__INCLUDED #include "TiledArray/dist_array.h" +#include "TiledArray/external/eigen.h" namespace TiledArray::math::linalg { +// freestanding adaptors for DistArray needed by solvers like DIIS + template inline void vec_multiply(DistArray& a1, const DistArray& a2) { @@ -59,4 +62,51 @@ inline void axpy(DistArray& y, S alpha, } // namespace TiledArray::math::linalg +namespace Eigen { + +// freestanding adaptors for Eigen::MatrixBase needed by solvers like DIIS + +template +inline void vec_multiply(Eigen::MatrixBase& a1, + const Eigen::MatrixBase& a2) { + a1.array() *= a2.array(); +} + +template +inline void scale(Eigen::MatrixBase& a, S scaling_factor) { + using numeric_type = typename Eigen::MatrixBase::value_type; + a.array() *= numeric_type(scaling_factor); +} + +template +inline void zero(Eigen::MatrixBase& a) { + a = Derived::Zero(a.rows(), a.cols()); +} + +template +inline void axpy(Eigen::MatrixBase& y, S alpha, + const Eigen::MatrixBase& x) { + using numeric_type = typename Eigen::MatrixBase::value_type; + y.array() += numeric_type(alpha) * x.array(); +} + +template +inline auto dot(const Eigen::MatrixBase& l, + const Eigen::MatrixBase& r) { + return l.adjoint().dot(r); +} + +template +inline auto inner_product(const Eigen::MatrixBase& l, + const Eigen::MatrixBase& r) { + return l.dot(r); +} + +template +inline auto norm2(const Eigen::MatrixBase& m) { + return m.template lpNorm<2>(); +} + +} // namespace Eigen + #endif // TILEDARRAY_MATH_LINALG_BASIC_H__INCLUDED From 7a07752f3e6e3874b7321845ff78f414beaa912a Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 5 Apr 2021 14:00:31 -0400 Subject: [PATCH 22/29] extra sfinae sprinkles --- src/TiledArray/tensor/complex.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/TiledArray/tensor/complex.h b/src/TiledArray/tensor/complex.h index 0aba127c9f..66854b3f43 100644 --- a/src/TiledArray/tensor/complex.h +++ b/src/TiledArray/tensor/complex.h @@ -40,7 +40,8 @@ namespace detail { /// \param r The real scalar /// \return `r` template ::value>::type* = nullptr> + typename std::enable_if && + !is_complex::value>::type* = nullptr> TILEDARRAY_FORCE_INLINE R conj(const R r) { return r; } @@ -61,7 +62,8 @@ TILEDARRAY_FORCE_INLINE std::complex conj(const std::complex z) { /// \tparam R A numeric type /// \return `r` template ::value>::type* = nullptr> + typename std::enable_if && + !is_complex::value>::type* = nullptr> TILEDARRAY_FORCE_INLINE auto inner_product(const L l, const R r) { return l * r; } @@ -72,7 +74,8 @@ TILEDARRAY_FORCE_INLINE auto inner_product(const L l, const R r) { /// \tparam R A numeric type /// \return `r` template ::value>::type* = nullptr> + typename std::enable_if && + is_complex::value>::type* = nullptr> TILEDARRAY_FORCE_INLINE auto inner_product(const L l, const R r) { return TiledArray::detail::conj(l) * r; } @@ -85,7 +88,8 @@ TILEDARRAY_FORCE_INLINE auto inner_product(const L l, const R r) { /// \param r The real scalar /// \return `r` template ::value>::type* = nullptr> + typename std::enable_if && + !is_complex::value>::type* = nullptr> TILEDARRAY_FORCE_INLINE R norm(const R r) { return r * r; } From 15658a2da5b5e025595401c2c9ca390fe708ad3c Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 5 Apr 2021 14:01:11 -0400 Subject: [PATCH 23/29] DIIS + CG both use inner_product rather than dot --- src/TiledArray/dist_array.h | 8 ++++++++ src/TiledArray/math/linalg/conjgrad.h | 13 ++++++------- src/TiledArray/math/linalg/diis.h | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index 0378c01f43..7a1d90393a 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -1643,6 +1643,14 @@ auto dot(const DistArray& a, const DistArray& b) { .get(); } +template +auto inner_product(const DistArray& a, + const DistArray& b) { + return (a(detail::dummy_annotation(rank(a))) + .inner_product(b(detail::dummy_annotation(rank(b))))) + .get(); +} + template auto squared_norm(const DistArray& a) { return a(detail::dummy_annotation(rank(a))).squared_norm(); diff --git a/src/TiledArray/math/linalg/conjgrad.h b/src/TiledArray/math/linalg/conjgrad.h index 8ee0ffffe4..25ea53aff3 100644 --- a/src/TiledArray/math/linalg/conjgrad.h +++ b/src/TiledArray/math/linalg/conjgrad.h @@ -26,8 +26,8 @@ #ifndef TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED #define TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED -#include #include +#include #include "TiledArray/dist_array.h" namespace TiledArray::math::linalg { @@ -48,7 +48,7 @@ namespace TiledArray::math::linalg { /// \li value_type maxabs_value(const D&) /// \li void vec_multiply(D& a, const D& b) (element-wise multiply /// of \c a by \c b ) -/// \li value_type dot_product(const D& a, const D& b) +/// \li value_type inner_product(const D& a, const D& b) /// \li void scale(D&, value_type) /// \li void axpy(D& y,value_type a, const D& x) /// \li void assign(D&, const D&) @@ -71,7 +71,6 @@ struct ConjugateGradientSolver { /// elements in the residual. value_type operator()(F& a, const D& b, D& x, const D& preconditioner, value_type convergence_target = -1.0) { - std::size_t n = volume(preconditioner); const bool use_diis = false; @@ -133,10 +132,10 @@ struct ConjugateGradientSolver { unsigned int iter = 0; while (not converged) { // alpha_i = (r_i . z_i) / (p_i . A . p_i) - value_type rz_norm2 = dot(RR_i, ZZ_i); + value_type rz_norm2 = inner_product(RR_i, ZZ_i); a(PP_i, APP_i); - const value_type pAp_i = dot(PP_i, APP_i); + const value_type pAp_i = inner_product(PP_i, APP_i); const value_type alpha_i = rz_norm2 / pAp_i; // x_i += alpha_i p_i @@ -157,7 +156,7 @@ struct ConjugateGradientSolver { ZZ_i = RR_i; vec_multiply(ZZ_i, preconditioner); - const value_type rz_ip1_norm2 = dot(ZZ_i, RR_i); + const value_type rz_ip1_norm2 = inner_product(ZZ_i, RR_i); const value_type beta_i = rz_ip1_norm2 / rz_norm2; @@ -186,7 +185,7 @@ struct ConjugateGradientSolver { } // namespace TiledArray::math::linalg namespace TiledArray { - using TiledArray::math::linalg::ConjugateGradientSolver; +using TiledArray::math::linalg::ConjugateGradientSolver; } #endif // TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED diff --git a/src/TiledArray/math/linalg/diis.h b/src/TiledArray/math/linalg/diis.h index b1335e3666..951fc6a11a 100644 --- a/src/TiledArray/math/linalg/diis.h +++ b/src/TiledArray/math/linalg/diis.h @@ -251,8 +251,10 @@ class DIIS { // and compute the most recent elements of B, B(i,j) = for (unsigned int i = 0; i < nvec - 1; i++) - B_(i, nvec - 1) = B_(nvec - 1, i) = dot(errors_[i], errors_[nvec - 1]); - B_(nvec - 1, nvec - 1) = dot(errors_[nvec - 1], errors_[nvec - 1]); + B_(i, nvec - 1) = B_(nvec - 1, i) = + inner_product(errors_[i], errors_[nvec - 1]); + B_(nvec - 1, nvec - 1) = + inner_product(errors_[nvec - 1], errors_[nvec - 1]); using std::abs; using std::sqrt; const auto current_error_2norm = sqrt(abs(B_(nvec - 1, nvec - 1))); From 85be9e4473d2c0d465321a6c86f15cc9c64145d5 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Mon, 5 Apr 2021 14:49:34 -0500 Subject: [PATCH 24/29] Fixes #265 --- src/TiledArray/conversions/eigen.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TiledArray/conversions/eigen.h b/src/TiledArray/conversions/eigen.h index d6a6697aac..238b1025b9 100644 --- a/src/TiledArray/conversions/eigen.h +++ b/src/TiledArray/conversions/eigen.h @@ -412,10 +412,13 @@ A eigen_to_array(World& world, const typename A::trange_type& trange, std::shared_ptr pmap = {}) { typedef typename A::index1_type size_type; // Check that trange matches the dimensions of other - if ((matrix.cols() > 1) && (matrix.rows() > 1)) { - 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."); + const auto rank = trange.tiles_range().rank(); + + TA_ASSERT(rank == 1 || rank == 2 && + "TiledArray::eigen_to_array(): The number of dimensions in " + "trange must match that of the Eigen matrix."); + + if(rank == 2) { TA_ASSERT( trange.elements_range().extent(0) == size_type(matrix.rows()) && "TiledArray::eigen_to_array(): The number of rows in trange is not " @@ -425,15 +428,12 @@ A eigen_to_array(World& world, const typename A::trange_type& trange, "TiledArray::eigen_to_array(): The number of columns in trange is not " "equal to the number of columns in the Eigen matrix."); } else { - 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."); } - + // Create a new tensor if (replicated && (world.size() > 1)) pmap = std::static_pointer_cast( From 9b53cf34349641aa99283174aeab31d87bd3056e Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 19 Apr 2021 10:09:46 -0400 Subject: [PATCH 25/29] use CHAR_BIT instead of 8 --- tests/bitset.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/bitset.cpp b/tests/bitset.cpp index bffc0ddc89..289a47c295 100644 --- a/tests/bitset.cpp +++ b/tests/bitset.cpp @@ -22,6 +22,8 @@ #include "tiledarray.h" #include "unit_test_config.h" +#include + using namespace TiledArray; struct BitsetFixture { @@ -35,7 +37,7 @@ struct BitsetFixture { }; const std::size_t BitsetFixture::size = - sizeof(BitsetFixture::Bitset::block_type) * 8 * 10.5; + sizeof(BitsetFixture::Bitset::block_type) * CHAR_BIT * 10.5; const std::size_t BitsetFixture::blocks = 11; // ============================================================================= From 3760d77e9843368aa3b2ccc56aea40386cab92b5 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Wed, 21 Apr 2021 15:16:53 -0400 Subject: [PATCH 26/29] [cmake] bump MADNESS tag to include https://github.com/m-a-d-n-e-s-s/madness/pull/372 --- INSTALL.md | 2 +- external/versions.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index b141b218f3..0195f8527e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -42,7 +42,7 @@ Both methods are supported. However, for most users we _strongly_ recommend to b - Boost.Range: header-only, *only used for unit testing* - [BTAS](http://github.com/ValeevGroup/BTAS), tag bbb11894802d7e2f89182a2e7fce9aed1078f851 . If usable BTAS installation is not found, TiledArray will download and compile BTAS from source. *This is the recommended way to compile BTAS for all users*. - - [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag b22ee85059e6ccc9a6e803ba0550652ece8d9df1 . + - [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag a3f3dce8c9d81262cf9fd7b29f97fcdafc7372a5 . Only the MADworld runtime and BLAS/LAPACK C API component of MADNESS is used by TiledArray. If usable MADNESS installation is not found, TiledArray will download and compile MADNESS from source. *This is the recommended way to compile MADNESS for all users*. diff --git a/external/versions.cmake b/external/versions.cmake index cb0d892014..90c9fcccd8 100644 --- a/external/versions.cmake +++ b/external/versions.cmake @@ -17,8 +17,8 @@ set(TA_INSTALL_EIGEN_PREVIOUS_VERSION 3.3.7) set(TA_INSTALL_EIGEN_URL_HASH b9e98a200d2455f06db9c661c5610496) set(TA_INSTALL_EIGEN_PREVIOUS_URL_HASH b9e98a200d2455f06db9c661c5610496) -set(TA_TRACKED_MADNESS_TAG b22ee85059e6ccc9a6e803ba0550652ece8d9df1) -set(TA_TRACKED_MADNESS_PREVIOUS_TAG 925552feaf326cca8e83de7bd042074ad3cfd3f1) +set(TA_TRACKED_MADNESS_TAG a3f3dce8c9d81262cf9fd7b29f97fcdafc7372a5) +set(TA_TRACKED_MADNESS_PREVIOUS_TAG b22ee85059e6ccc9a6e803ba0550652ece8d9df1) set(TA_TRACKED_MADNESS_VERSION 0.10.1) set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1) From 285f0dfffea13f3489976a56bf96297f6f968e3b Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sat, 24 Apr 2021 00:21:23 -0400 Subject: [PATCH 27/29] typos --- examples/cuda/ta_dense_cuda.cpp | 2 +- examples/cuda/ta_reduce_cuda.cpp | 2 +- examples/cuda/ta_vector_cuda.cpp | 2 +- examples/dgemm/ta_dense_asymm.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/cuda/ta_dense_cuda.cpp b/examples/cuda/ta_dense_cuda.cpp index cf56a15d01..51ebc67b11 100644 --- a/examples/cuda/ta_dense_cuda.cpp +++ b/examples/cuda/ta_dense_cuda.cpp @@ -328,7 +328,7 @@ int try_main(int argc, char **argv) { } if ((Nm % Bm) != 0ul || Nn % Bn != 0ul || Nk % Bk != 0ul) { std::cerr - << "Error: diminsion size must be evenly divisible by block size.\n"; + << "Error: dimension size must be evenly divisible by block size.\n"; return 1; } const long nrepeat = (argc >= 8 ? atol(argv[7]) : 5); diff --git a/examples/cuda/ta_reduce_cuda.cpp b/examples/cuda/ta_reduce_cuda.cpp index 504dbaafa8..417fa2d72f 100644 --- a/examples/cuda/ta_reduce_cuda.cpp +++ b/examples/cuda/ta_reduce_cuda.cpp @@ -265,7 +265,7 @@ int try_main(int argc, char **argv) { } if ((Nm % Bm) != 0ul || Nn % Bn != 0ul) { std::cerr - << "Error: diminsion size must be evenly divisible by block size.\n"; + << "Error: dimension size must be evenly divisible by block size.\n"; return 1; } const long nrepeat = (argc >= 6 ? atol(argv[5]) : 5); diff --git a/examples/cuda/ta_vector_cuda.cpp b/examples/cuda/ta_vector_cuda.cpp index 802f0d4683..f3c6265eb1 100644 --- a/examples/cuda/ta_vector_cuda.cpp +++ b/examples/cuda/ta_vector_cuda.cpp @@ -284,7 +284,7 @@ int try_main(int argc, char **argv) { } if ((Nm % Bm) != 0ul || Nn % Bn != 0ul) { std::cerr - << "Error: diminsion size must be evenly divisible by block size.\n"; + << "Error: dimension size must be evenly divisible by block size.\n"; return 1; } const long nrepeat = (argc >= 6 ? atol(argv[5]) : 5); diff --git a/examples/dgemm/ta_dense_asymm.cpp b/examples/dgemm/ta_dense_asymm.cpp index cc528698f3..d5ee98fc43 100644 --- a/examples/dgemm/ta_dense_asymm.cpp +++ b/examples/dgemm/ta_dense_asymm.cpp @@ -49,7 +49,7 @@ int main(int argc, char** argv) { } if ((Nm % Bm) != 0ul || Nn % Bn != 0ul || Nk % Bk != 0ul) { std::cerr - << "Error: diminsion size must be evenly divisible by block size.\n"; + << "Error: dimension size must be evenly divisible by block size.\n"; return 1; } const long repeat = (argc >= 8 ? atol(argv[7]) : 5); From 626eb79fda57d7a911925014a9f5110142f8320a Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sat, 24 Apr 2021 00:22:15 -0400 Subject: [PATCH 28/29] ta_dense_asymm can use floats as well as doubles + misc fixes --- examples/dgemm/ta_dense_asymm.cpp | 89 ++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/examples/dgemm/ta_dense_asymm.cpp b/examples/dgemm/ta_dense_asymm.cpp index d5ee98fc43..ac586b9edf 100644 --- a/examples/dgemm/ta_dense_asymm.cpp +++ b/examples/dgemm/ta_dense_asymm.cpp @@ -30,7 +30,8 @@ int main(int argc, char** argv) { std::cout << "multiplies A(Nm,Nk) * B(Nk,Nn), with dimensions m, n, and k " "blocked by Bm, Bn, and Bk, respectively" << std::endl - << "Usage: " << argv[0] << " Nm Bm Nn Bn Nk Bk [repetitions]\n"; + << "Usage: " << argv[0] + << " Nm Bm Nn Bn Nk Bk [repetitions=5] [real=double]\n"; return 0; } const long Nm = atol(argv[1]); @@ -58,6 +59,12 @@ int main(int argc, char** argv) { return 1; } + const std::string real_type_str = (argc >= 9 ? argv[8] : "double"); + if (real_type_str != "double" && real_type_str != "float") { + std::cerr << "Error: invalid real type " << real_type_str << ".\n"; + return 1; + } + const std::size_t Tm = Nm / Bm; const std::size_t Tn = Nn / Bn; const std::size_t Tk = Nk / Bk; @@ -124,39 +131,57 @@ int main(int argc, char** argv) { TiledArray::TiledRange // TRange for b trange_b(blocking_B.begin(), blocking_B.end()); - // Construct and initialize arrays - // by default use TiledArray tensors, uncomment second line if want to use - // btas::Tensor instead - using Array = TiledArray::TArrayD; - // using Array = - // TiledArray::DistArray>>; - Array a(world, trange_a); - Array b(world, trange_b); - Array c(world, trange_c); - a.fill(1.0); - b.fill(1.0); - - // Start clock - world.gop.fence(); - const double wall_time_start = madness::wall_time(); - - // Do matrix multiplication - for (int i = 0; i < repeat; ++i) { - c("m,n") = a("m,k") * b("k,n"); - world.gop.fence(); - if (world.rank() == 0) std::cout << "Iteration " << i + 1 << "\n"; - } + auto run = [&](auto* tarray_ptr) { + using Array = std::decay_t>; - // Stop clock - const double wall_time_stop = madness::wall_time(); + // Construct and initialize arrays + Array a(world, trange_a); + Array b(world, trange_b); + Array c(world, trange_c); + a.fill(1.0); + b.fill(1.0); - if (world.rank() == 0) - std::cout << "Average wall time = " - << (wall_time_stop - wall_time_start) / double(repeat) - << " sec\nAverage GFLOPS = " - << double(repeat) * 2.0 * double(Nn * Nm * Nm) / - (wall_time_stop - wall_time_start) / 1.0e9 - << "\n"; + // Start clock + world.gop.fence(); + const double wall_time_start = madness::wall_time(); + + // Do matrix multiplication + for (int i = 0; i < repeat; ++i) { + c("m,n") = a("m,k") * b("k,n"); + world.gop.fence(); + if (world.rank() == 0) std::cout << "Iteration " << i + 1 << "\n"; + } + + // Stop clock + const double wall_time_stop = madness::wall_time(); + + if (world.rank() == 0) + std::cout << "Average wall time = " + << (wall_time_stop - wall_time_start) / double(repeat) + << " sec\nAverage GFLOPS = " + << double(repeat) * 2.0 * double(Nn * Nm * Nk) / + (wall_time_stop - wall_time_start) / 1.0e9 + << "\n"; + }; + + // by default use TiledArray tensors + constexpr bool use_btas = false; + // btas::Tensor instead + if (real_type_str == "double") { + if constexpr (!use_btas) + run(static_cast(nullptr)); + else + run(static_cast>>*>( + nullptr)); + } else { + if constexpr (!use_btas) + run(static_cast(nullptr)); + else + run(static_cast>>*>( + nullptr)); + } TiledArray::finalize(); return 0; From 7aa5114ec28acbe487439a5775e716644158f478 Mon Sep 17 00:00:00 2001 From: asadchev Date: Wed, 3 Mar 2021 18:24:16 -0500 Subject: [PATCH 29/29] Refactor forward declarations --- src/CMakeLists.txt | 3 +- src/TiledArray/dist_array.h | 70 +++++----- src/TiledArray/expressions/blk_tsr_engine.h | 11 +- src/TiledArray/expressions/blk_tsr_expr.h | 8 -- src/TiledArray/expressions/expr.h | 19 +-- src/TiledArray/expressions/expr_trace.h | 6 +- src/TiledArray/expressions/fwd.h | 73 +++++++++++ src/TiledArray/expressions/scal_tsr_engine.h | 6 +- src/TiledArray/expressions/scal_tsr_expr.h | 16 +-- src/TiledArray/expressions/tsr_engine.h | 6 - src/TiledArray/expressions/tsr_expr.h | 7 - src/TiledArray/fwd.h | 131 +++++++++++++++++++ src/tiledarray_fwd.h | 126 +----------------- tests/tot_dist_array_part1.cpp | 5 - 14 files changed, 255 insertions(+), 232 deletions(-) create mode 100644 src/TiledArray/expressions/fwd.h create mode 100644 src/TiledArray/fwd.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79fd5bb6d6..ca46d0a419 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ set(TILEDARRAY_HEADER_FILES tiledarray.h tiledarray_fwd.h +TiledArray/fwd.h TiledArray/config.h TiledArray/array_impl.h TiledArray/bitset.h @@ -98,6 +99,7 @@ TiledArray/expressions/contraction_helpers.h TiledArray/expressions/expr.h TiledArray/expressions/expr_engine.h TiledArray/expressions/expr_trace.h +TiledArray/expressions/fwd.h TiledArray/expressions/leaf_engine.h TiledArray/expressions/mult_engine.h TiledArray/expressions/mult_expr.h @@ -177,7 +179,6 @@ TiledArray/util/random.h TiledArray/util/singleton.h TiledArray/util/time.h TiledArray/util/vector.h - ) if(CUDA_FOUND) diff --git a/src/TiledArray/dist_array.h b/src/TiledArray/dist_array.h index 7a1d90393a..7931db27ed 100644 --- a/src/TiledArray/dist_array.h +++ b/src/TiledArray/dist_array.h @@ -20,9 +20,7 @@ #ifndef TILEDARRAY_ARRAY_H__INCLUDED #define TILEDARRAY_ARRAY_H__INCLUDED -#include - -#include +#include "TiledArray/expressions/fwd.h" #include "TiledArray/array_impl.h" #include "TiledArray/conversions/clone.h" @@ -35,15 +33,14 @@ #include "TiledArray/util/initializer_list.h" #include "TiledArray/util/random.h" +#include +#include + namespace TiledArray { // Forward declarations template class Tensor; -namespace expressions { -template -class TsrExpr; -} // namespace expressions /// A (multidimensional) tiled array @@ -56,7 +53,6 @@ template >, typename Policy = DensePolicy> class DistArray : public madness::archive::ParallelSerializableObject { public: - typedef DistArray DistArray_; ///< This object's type typedef TiledArray::detail::ArrayImpl impl_type; ///< The type of the PIMPL typedef typename impl_type::policy_type policy_type; ///< Policy type @@ -107,7 +103,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// used elsewhere too. /// template - using is_my_type = std::is_same>; + using is_my_type = std::is_same>; template using enable_if_not_my_type = @@ -149,7 +145,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { try { world.gop.lazy_sync(id, [pimpl]() { delete pimpl; - DistArray_::cleanup_counter_--; + DistArray::cleanup_counter_--; }); } catch (madness::MadnessException& e) { fprintf(stderr, @@ -245,7 +241,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// This is a shallow copy, that is no data is copied. /// \param other The array to be copied - DistArray(const DistArray_& other) : pimpl_(other.pimpl_) {} + DistArray(const DistArray& other) : pimpl_(other.pimpl_) {} /// Dense array constructor @@ -301,27 +297,27 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// raised \p world and \p il are unchanged. template DistArray(World& world, detail::vector_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} template DistArray(World& world, detail::matrix_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} template DistArray(World& world, detail::tensor3_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} template DistArray(World& world, detail::tensor4_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} template DistArray(World& world, detail::tensor5_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} template DistArray(World& world, detail::tensor6_il il) - : DistArray(array_from_il(world, il)) {} + : DistArray(array_from_il(world, il)) {} ///@} /// \name Tiling initializer list constructors @@ -352,27 +348,27 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// raised \p world and \p il are unchanged. template DistArray(World& world, const trange_type& trange, detail::vector_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} template DistArray(World& world, const trange_type& trange, detail::matrix_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} template DistArray(World& world, const trange_type& trange, detail::tensor3_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} template DistArray(World& world, const trange_type& trange, detail::tensor4_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} template DistArray(World& world, const trange_type& trange, detail::tensor5_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} template DistArray(World& world, const trange_type& trange, detail::tensor6_il il) - : DistArray(array_from_il(world, trange, il)) {} + : DistArray(array_from_il(world, trange, il)) {} /// @} /// converting copy constructor @@ -410,7 +406,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// Create a deep copy of this array /// \return An array that is equal to this array - DistArray_ clone() const { return TiledArray::clone(*this); } + DistArray clone() const { return TiledArray::clone(*this); } /// Accessor for the (shared_ptr to) implementation object @@ -462,7 +458,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// This is a shallow copy, that is no data is copied. /// \param other The array to be copied - DistArray_& operator=(const DistArray_& other) { + DistArray& operator=(const DistArray& other) { pimpl_ = other.pimpl_; return *this; @@ -977,10 +973,9 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// \return A const tensor expression object /// \note size and contents of \p vars are validated using /// DistArray::check_str_index() - TiledArray::expressions::TsrExpr operator()( - const std::string& vars) const { + auto operator()(const std::string& vars) const { check_str_index(vars); - return TiledArray::expressions::TsrExpr(*this, + return TiledArray::expressions::TsrExpr(*this, vars); } @@ -990,10 +985,9 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// \return A non-const tensor expression object /// \note size and contents of \p vars are validated using /// DistArray::check_str_index() - TiledArray::expressions::TsrExpr operator()( - const std::string& vars) { + auto operator()(const std::string& vars) { check_str_index(vars); - return TiledArray::expressions::TsrExpr(*this, vars); + return TiledArray::expressions::TsrExpr(*this, vars); } /// \deprecated use DistArray::world() @@ -1161,7 +1155,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { /// \param other The array to be swapped with this array. /// \throw None no throw guarantee. - void swap(DistArray_& other) { std::swap(pimpl_, other.pimpl_); } + void swap(DistArray& other) { std::swap(pimpl_, other.pimpl_); } /// Convert a distributed array into a replicated array /// \throw TiledArray::Exception if the PIMPL is not initialized. Strong throw @@ -1170,19 +1164,19 @@ class DistArray : public madness::archive::ParallelSerializableObject { if ((!impl_ref().pmap()->is_replicated()) && (world().size() > 1)) { // Construct a replicated array auto pmap = std::make_shared(world(), size()); - DistArray_ result = DistArray_(world(), trange(), shape(), pmap); + DistArray result = DistArray(world(), trange(), shape(), pmap); // Create the replicator object that will do an all-to-all broadcast of // the local tile data. auto replicator = - std::make_shared>(*this, result); + std::make_shared>(*this, result); // Put the replicator pointer in the deferred cleanup object so it will // be deleted at the end of the next fence. TA_ASSERT(replicator.unique()); // Required for deferred_cleanup madness::detail::deferred_cleanup(world(), replicator); - DistArray_::operator=(result); + DistArray::operator=(result); } } @@ -1264,7 +1258,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { // use default pmap, ensure it's the same pmap used to serialize auto volume = trange.tiles_range().volume(); - auto pmap = detail::policy_t::default_pmap(world, volume); + auto pmap = detail::policy_t::default_pmap(world, volume); size_t pmap_hash_code = 0; ar& pmap_hash_code; if (pmap_hash_code != typeid(pmap.get()).hash_code()) @@ -1337,7 +1331,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { // use default pmap auto volume = trange.tiles_range().volume(); - auto pmap = detail::policy_t::default_pmap(world, volume); + auto pmap = detail::policy_t::default_pmap(world, volume); pimpl_.reset( new impl_type(world, std::move(trange), std::move(shape), pmap)); @@ -1371,7 +1365,7 @@ class DistArray : public madness::archive::ParallelSerializableObject { // use default pmap auto volume = trange.tiles_range().volume(); - auto pmap = detail::policy_t::default_pmap(world, volume); + auto pmap = detail::policy_t::default_pmap(world, volume); pimpl_.reset( new impl_type(world, std::move(trange), std::move(shape), pmap)); } diff --git a/src/TiledArray/expressions/blk_tsr_engine.h b/src/TiledArray/expressions/blk_tsr_engine.h index 7393e462a6..5157ccac09 100644 --- a/src/TiledArray/expressions/blk_tsr_engine.h +++ b/src/TiledArray/expressions/blk_tsr_engine.h @@ -26,6 +26,7 @@ #ifndef TILEDARRAY_EXPRESSIONS_BLK_TSR_ENGINE_H__INCLUDED #define TILEDARRAY_EXPRESSIONS_BLK_TSR_ENGINE_H__INCLUDED +#include #include #include @@ -37,16 +38,6 @@ class DistArray; namespace expressions { -// Forward declaration -template -class BlkTsrExpr; -template -class ScalBlkTsrExpr; -template -class BlkTsrEngine; -template -class ScalBlkTsrEngine; - template struct EngineTrait, Result, Alias>> { // Argument typedefs diff --git a/src/TiledArray/expressions/blk_tsr_expr.h b/src/TiledArray/expressions/blk_tsr_expr.h index a5bf1f4884..e2680559b5 100644 --- a/src/TiledArray/expressions/blk_tsr_expr.h +++ b/src/TiledArray/expressions/blk_tsr_expr.h @@ -35,14 +35,6 @@ namespace TiledArray { namespace expressions { -// Forward declaration -template -class TsrExpr; -template -class BlkTsrExpr; -template -class ScalBlkTsrExpr; - template using ConjBlkTsrExpr = ScalBlkTsrExpr>; diff --git a/src/TiledArray/expressions/expr.h b/src/TiledArray/expressions/expr.h index fbe6e314b5..ccb562591c 100644 --- a/src/TiledArray/expressions/expr.h +++ b/src/TiledArray/expressions/expr.h @@ -26,6 +26,9 @@ #ifndef TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED #define TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED +#include "TiledArray/expressions/fwd.h" + + #include "../reduce_task.h" #include "../tile_interface/cast.h" #include "../tile_interface/scale.h" @@ -45,18 +48,7 @@ #include -namespace TiledArray { -namespace expressions { - -// Forward declaration -template -struct ExprTrait; -template -class TsrExpr; -template -class BlkTsrExpr; -template -struct is_aliased; +namespace TiledArray::expressions { template struct EngineParamOverride { @@ -881,7 +873,6 @@ class Expr { }; // class Expr -} // namespace expressions -} // namespace TiledArray +} #endif // TILEDARRAY_EXPRESSIONS_EXPR_H__INCLUDED diff --git a/src/TiledArray/expressions/expr_trace.h b/src/TiledArray/expressions/expr_trace.h index bf337832a0..e9010ea6d7 100644 --- a/src/TiledArray/expressions/expr_trace.h +++ b/src/TiledArray/expressions/expr_trace.h @@ -26,17 +26,13 @@ #ifndef TILEDARRAY_EXPR_TRACE_H__INCLUDED #define TILEDARRAY_EXPR_TRACE_H__INCLUDED +#include #include #include namespace TiledArray { namespace expressions { -template -class Expr; -template -class TsrExpr; - /// Expression output stream class ExprOStream { std::ostream& os_; ///< output stream diff --git a/src/TiledArray/expressions/fwd.h b/src/TiledArray/expressions/fwd.h new file mode 100644 index 0000000000..7960baf648 --- /dev/null +++ b/src/TiledArray/expressions/fwd.h @@ -0,0 +1,73 @@ +/* + * This file is a part of TiledArray. + * Copyright (C) 2013 Virginia Tech + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Justus Calvin + * Department of Chemistry, Virginia Tech + * + * expr.h + * Apr 1, 2014 + * + */ + +#ifndef TILEDARRAY_EXPRESSIONS_FWD_H__INCLUDED +#define TILEDARRAY_EXPRESSIONS_FWD_H__INCLUDED + +#include + + +namespace TiledArray::expressions { + +template +class Expr; + +template +class TsrExpr; + +template +class BlkTsrExpr; + +template +class ScalBlkTsrExpr; + +template +struct is_aliased : std::true_type {}; + +template +struct is_aliased> : std::false_type {}; + +// Forward declaration +template +struct ExprTrait; + +template +class TsrEngine; + +template +class BlkTsrEngine; + +template +class ScalBlkTsrEngine; + +template +class ScalTsrExpr; + +template +class ScalTsrEngine; + +} // namespace TiledArray + +#endif // TILEDARRAY_EXPRESSIONS_FWD_H__INCLUDED diff --git a/src/TiledArray/expressions/scal_tsr_engine.h b/src/TiledArray/expressions/scal_tsr_engine.h index 0d9aa66e7f..6bb75204cf 100644 --- a/src/TiledArray/expressions/scal_tsr_engine.h +++ b/src/TiledArray/expressions/scal_tsr_engine.h @@ -26,6 +26,7 @@ #ifndef TILEDARRAY_EXPRESSIONS_SCAL_TSR_ENGINE_H__INCLUDED #define TILEDARRAY_EXPRESSIONS_SCAL_TSR_ENGINE_H__INCLUDED +#include #include #include #include @@ -33,11 +34,6 @@ namespace TiledArray { namespace expressions { -template -class ScalTsrExpr; -template -class ScalTsrEngine; - template struct EngineTrait, Scalar, Result>> { // Argument typedefs diff --git a/src/TiledArray/expressions/scal_tsr_expr.h b/src/TiledArray/expressions/scal_tsr_expr.h index f1bed83fc0..ba7b96bf3e 100644 --- a/src/TiledArray/expressions/scal_tsr_expr.h +++ b/src/TiledArray/expressions/scal_tsr_expr.h @@ -128,7 +128,7 @@ template >::type* = nullptr> inline ScalTsrExpr::type, Scalar> operator*( - const TsrExpr& expr, const Scalar& factor) { + const TsrExpr& expr, const Scalar& factor) { return ScalTsrExpr::type, Scalar>( expr.array(), expr.annotation(), factor); } @@ -144,7 +144,7 @@ template >::type* = nullptr> inline ScalTsrExpr::type, Scalar> operator*( - const Scalar& factor, const TsrExpr& expr) { + const Scalar& factor, const TsrExpr& expr) { return ScalTsrExpr::type, Scalar>( expr.array(), expr.annotation(), factor); } @@ -190,10 +190,10 @@ inline ScalTsrExpr > operator*( /// \return A scaled-tensor expression object template inline ScalTsrExpr::type, - typename ExprTrait >::numeric_type> -operator-(const TsrExpr& expr) { + typename ExprTrait >::numeric_type> +operator-(const TsrExpr& expr) { return ScalTsrExpr::type, - typename ExprTrait >::numeric_type>( + typename ExprTrait >::numeric_type>( expr.array(), expr.annotation(), -1); } @@ -217,7 +217,7 @@ inline ScalTsrExpr operator-( /// \return A conjugated expression object template inline ConjTsrExpr::type> conj( - const TsrExpr& expr) { + const TsrExpr& expr) { return ConjTsrExpr::type>( expr.array(), expr.annotation(), conj_op()); } @@ -228,8 +228,8 @@ inline ConjTsrExpr::type> conj( /// \param expr The tensor expression object /// \return A tensor expression object template -inline TsrExpr conj(const ConjTsrExpr& expr) { - return TsrExpr(expr.array(), expr.annotation()); +inline TsrExpr conj(const ConjTsrExpr& expr) { + return TsrExpr(expr.array(), expr.annotation()); } /// Conjugated-tensor expression factor diff --git a/src/TiledArray/expressions/tsr_engine.h b/src/TiledArray/expressions/tsr_engine.h index 1b51b1c9cd..5219af37ca 100644 --- a/src/TiledArray/expressions/tsr_engine.h +++ b/src/TiledArray/expressions/tsr_engine.h @@ -38,12 +38,6 @@ class DistArray; namespace expressions { -// Forward declaration -template -class TsrExpr; -template -class TsrEngine; - template struct EngineTrait, Result, Alias>> { // Argument typedefs diff --git a/src/TiledArray/expressions/tsr_expr.h b/src/TiledArray/expressions/tsr_expr.h index bfc5cf7546..e2b57b6524 100644 --- a/src/TiledArray/expressions/tsr_expr.h +++ b/src/TiledArray/expressions/tsr_expr.h @@ -39,13 +39,6 @@ namespace expressions { using TiledArray::detail::numeric_t; using TiledArray::detail::scalar_t; -template -struct is_aliased : public std::true_type {}; - -template -struct is_aliased> - : public std::integral_constant {}; - template struct ExprTrait> { typedef Array array_type; ///< The \c Array type diff --git a/src/TiledArray/fwd.h b/src/TiledArray/fwd.h new file mode 100644 index 0000000000..3863ad6d7e --- /dev/null +++ b/src/TiledArray/fwd.h @@ -0,0 +1,131 @@ +/* + * This file is a part of TiledArray. + * Copyright (C) 2014 Virginia Tech + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef TILEDARRAY_FWD_H__INCLUDED +#define TILEDARRAY_FWD_H__INCLUDED + +#include + +#include +#include + +namespace Eigen { // fwd define Eigen's aligned allocator for + // TiledArray::Tensor +template +class aligned_allocator; +} // namespace Eigen + +namespace madness { + class World; +} + +namespace TiledArray { + +using madness::World; +World& get_default_world(); + +// Ranges +class Range; +class TiledRange1; +class TiledRange; + +// TiledArray Policy +class DensePolicy; +class SparsePolicy; + +// TiledArray Tensors +template +class Tensor; + +typedef Tensor > TensorD; +typedef Tensor > TensorI; +typedef Tensor > TensorF; +typedef Tensor > TensorL; +typedef Tensor, + Eigen::aligned_allocator > > + TensorZ; +typedef Tensor, + Eigen::aligned_allocator > > + TensorC; + +// CUDA tensor +#ifdef TILEDARRAY_HAS_CUDA + +template +class cuda_um_allocator_impl; + +template > +class default_init_allocator; + +template +using cuda_um_allocator = default_init_allocator>; + +/// \brief a vector that lives in CUDA Unified Memory, with most operations +/// implemented on the CPU +template +using cuda_um_btas_varray = ::btas::varray>; + +/** + * btas::Tensor with UM storage cuda_um_btas_varray + */ +template +using btasUMTensorVarray = + ::btas::Tensor>; + +#endif + +// TiledArray Arrays +template +class DistArray; + +// Dense Array Typedefs +template +using TArray = DistArray >, DensePolicy>; +typedef TArray TArrayD; +typedef TArray TArrayI; +typedef TArray TArrayF; +typedef TArray TArrayL; +typedef TArray > TArrayZ; +typedef TArray > TArrayC; + +// Sparse Array Typedefs +template +using TSpArray = + DistArray >, SparsePolicy>; +typedef TSpArray TSpArrayD; +typedef TSpArray TSpArrayI; +typedef TSpArray TSpArrayF; +typedef TSpArray TSpArrayL; +typedef TSpArray > TSpArrayZ; +typedef TSpArray > TSpArrayC; + +// type alias for backward compatibility: the old Array has static type, +// DistArray is rank-polymorphic +template >, + typename Policy = DensePolicy> +using Array = DistArray; + +} // namespace TiledArray + +#ifndef TILEDARRAY_DISABLE_NAMESPACE_TA +namespace TA = TiledArray; +#endif // TILEDARRAY_DISABLE_NAMESPACE_TA + +#endif // TILEDARRAY_FWD_H__INCLUDED diff --git a/src/tiledarray_fwd.h b/src/tiledarray_fwd.h index af41f63c6f..2bb10ed659 100644 --- a/src/tiledarray_fwd.h +++ b/src/tiledarray_fwd.h @@ -1,125 +1 @@ -/* - * This file is a part of TiledArray. - * Copyright (C) 2014 Virginia Tech - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#ifndef TILEDARRAY_FWD_H__INCLUDED -#define TILEDARRAY_FWD_H__INCLUDED - -#include - -#include - -#include - -namespace Eigen { // fwd define Eigen's aligned allocator for - // TiledArray::Tensor -template -class aligned_allocator; -} // namespace Eigen - -namespace TiledArray { - -// Ranges -class Range; -class TiledRange1; -class TiledRange; - -// TiledArray Policy -class DensePolicy; -class SparsePolicy; - -// TiledArray Tensors -template -class Tensor; - -typedef Tensor > TensorD; -typedef Tensor > TensorI; -typedef Tensor > TensorF; -typedef Tensor > TensorL; -typedef Tensor, - Eigen::aligned_allocator > > - TensorZ; -typedef Tensor, - Eigen::aligned_allocator > > - TensorC; - -// CUDA tensor -#ifdef TILEDARRAY_HAS_CUDA - -template -class cuda_um_allocator_impl; - -template > -class default_init_allocator; - -template -using cuda_um_allocator = default_init_allocator>; - -/// \brief a vector that lives in CUDA Unified Memory, with most operations -/// implemented on the CPU -template -using cuda_um_btas_varray = ::btas::varray>; - -/** - * btas::Tensor with UM storage cuda_um_btas_varray - */ -template -using btasUMTensorVarray = - ::btas::Tensor>; - -#endif - -// TiledArray Arrays -template -class DistArray; - -// Dense Array Typedefs -template -using TArray = DistArray >, DensePolicy>; -typedef TArray TArrayD; -typedef TArray TArrayI; -typedef TArray TArrayF; -typedef TArray TArrayL; -typedef TArray > TArrayZ; -typedef TArray > TArrayC; - -// Sparse Array Typedefs -template -using TSpArray = - DistArray >, SparsePolicy>; -typedef TSpArray TSpArrayD; -typedef TSpArray TSpArrayI; -typedef TSpArray TSpArrayF; -typedef TSpArray TSpArrayL; -typedef TSpArray > TSpArrayZ; -typedef TSpArray > TSpArrayC; - -// type alias for backward compatibility: the old Array has static type, -// DistArray is rank-polymorphic -template >, - typename Policy = DensePolicy> -using Array = DistArray; - -} // namespace TiledArray - -#ifndef TILEDARRAY_DISABLE_NAMESPACE_TA -namespace TA = TiledArray; -#endif // TILEDARRAY_DISABLE_NAMESPACE_TA - -#endif // TILEDARRAY_FWD_H__INCLUDED +#include diff --git a/tests/tot_dist_array_part1.cpp b/tests/tot_dist_array_part1.cpp index 8f1f36d199..e71392ef8c 100644 --- a/tests/tot_dist_array_part1.cpp +++ b/tests/tot_dist_array_part1.cpp @@ -24,11 +24,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(typedefs, TestParam, test_params) { using tensor_t = tensor_type; //------------ Actual type checks start here ------------------------- - { - constexpr bool is_same = - std::is_same_v; - BOOST_TEST(is_same); - } { using corr_impl_type = detail::ArrayImpl;