From 71aa829c1365ef0506e0265cf63495f44cb5675d Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Mon, 11 Nov 2024 15:55:46 -0500 Subject: [PATCH 1/2] Use universal references in generic communciations --- c++/mpi/generic_communication.hpp | 8 ++++---- c++/mpi/ranges.hpp | 15 ++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/c++/mpi/generic_communication.hpp b/c++/mpi/generic_communication.hpp index e5ed0294..244d19e1 100644 --- a/c++/mpi/generic_communication.hpp +++ b/c++/mpi/generic_communication.hpp @@ -73,9 +73,9 @@ namespace mpi { * @param c mpi::communicator. * @param root Rank of the root process. */ - template [[gnu::always_inline]] void broadcast(T &x, communicator c = {}, int root = 0) { + template [[gnu::always_inline]] void broadcast(T &&x, communicator c = {}, int root = 0) { static_assert(not std::is_const_v, "mpi::broadcast cannot be called on const objects"); - if (has_env) mpi_broadcast(x, c, root); + if (has_env) mpi_broadcast(std::forward(x), c, root); } /** @@ -121,9 +121,9 @@ namespace mpi { * @param op `MPI_Op` used in the reduction. */ template - [[gnu::always_inline]] inline void reduce_in_place(T &x, communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) { + [[gnu::always_inline]] inline void reduce_in_place(T &&x, communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) { static_assert(not std::is_const_v, "In-place mpi functions cannot be called on const objects"); - if (has_env) mpi_reduce_in_place(x, c, root, all, op); + if (has_env) mpi_reduce_in_place(std::forward(x), c, root, all, op); } /** diff --git a/c++/mpi/ranges.hpp b/c++/mpi/ranges.hpp index 6dc96a74..5ca79124 100644 --- a/c++/mpi/ranges.hpp +++ b/c++/mpi/ranges.hpp @@ -90,7 +90,7 @@ namespace mpi { * @param c mpi::communicator. * @param root Rank of the root process. */ - template void broadcast_range(R &&rg, communicator c = {}, int root = 0) { + template void broadcast_range(R &&rg, communicator c = {}, int root = 0) { // NOLINT (ranges need not be forwarded) // check the sizes of all ranges using value_t = std::ranges::range_value_t; auto const size = std::ranges::size(rg); @@ -151,7 +151,9 @@ namespace mpi { * @param all Should all processes receive the result of the reduction. * @param op `MPI_Op` used in the reduction. */ - template void reduce_in_place_range(R &&rg, communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) { + template + void reduce_in_place_range(R &&rg, communicator c = {}, int root = 0, bool all = false, // NOLINT (ranges need not be forwarded) + MPI_Op op = MPI_SUM) { // check the sizes of all ranges using value_t = std::ranges::range_value_t; auto const size = std::ranges::size(rg); @@ -221,7 +223,8 @@ namespace mpi { * @param op `MPI_Op` used in the reduction. */ template - void reduce_range(R1 &&in_rg, R2 &&out_rg, communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) { + void reduce_range(R1 &&in_rg, R2 &&out_rg, communicator c = {}, int root = 0, bool all = false, // NOLINT (ranges need not be forwarded) + MPI_Op op = MPI_SUM) { // check input and output ranges auto const in_size = std::ranges::size(in_rg); EXPECTS_WITH_MESSAGE(all_equal(in_size, c), "Input range sizes are not equal across all processes in mpi::reduce_range"); @@ -311,7 +314,8 @@ namespace mpi { */ template requires(std::same_as, std::ranges::range_value_t>) - void scatter_range(R1 &&in_rg, R2 &&out_rg, long in_size, communicator c = {}, int root = 0, long chunk_size = 1) { + void scatter_range(R1 &&in_rg, R2 &&out_rg, long in_size, communicator c = {}, int root = 0, // NOLINT (ranges need not be forwarded) + long chunk_size = 1) { // check the sizes of the input and output ranges if (c.rank() == root) { EXPECTS_WITH_MESSAGE(in_size == std::ranges::size(in_rg), "Input range size not equal to provided size in mpi::scatter_range"); @@ -405,7 +409,8 @@ namespace mpi { * @param all Should all processes receive the result of the reduction. */ template - void gather_range(R1 &&in_rg, R2 &&out_rg, long out_size, communicator c = {}, int root = 0, bool all = false) { + void gather_range(R1 &&in_rg, R2 &&out_rg, long out_size, communicator c = {}, int root = 0, // NOLINT (ranges need not be forwarded) + bool all = false) { // check the sizes of the input and output ranges auto const in_size = std::ranges::size(in_rg); EXPECTS_WITH_MESSAGE(out_size = all_reduce(in_size, c), "Input range sizes don't add up to output range size in mpi::gather_range"); From 7160f46391990bc066b1b2011d0f17ea31b21988 Mon Sep 17 00:00:00 2001 From: Thomas Hahn Date: Mon, 11 Nov 2024 17:01:27 -0500 Subject: [PATCH 2/2] [ghactions] Remove custom doxygen build and build docs on macos --- .github/workflows/build.yml | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6faec3cd..616783ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,9 +27,9 @@ jobs: matrix: include: - {os: ubuntu-24.04, cc: gcc, cxx: g++, doc: OFF} - - {os: ubuntu-24.04, cc: clang, cxx: clang++, doc: ON} + - {os: ubuntu-24.04, cc: clang, cxx: clang++, doc: OFF} - {os: macos-14, cc: gcc-14, cxx: g++-14, doc: OFF} - - {os: macos-14, cc: clang, cxx: clang++, doc: OFF} + - {os: macos-14, cc: clang, cxx: clang++, doc: ON} runs-on: ${{ matrix.os }} @@ -78,34 +78,23 @@ jobs: python3-sphinx python3-nbsphinx + - name: Set up virtualenv + run: | + mkdir $HOME/.venv + python3 -m venv --system-site-packages $HOME/.venv/my_python + source $HOME/.venv/my_python/bin/activate + echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV + echo "PATH=$PATH" >> $GITHUB_ENV + - name: Install homebrew dependencies if: ${{ contains(matrix.os, 'macos') }} run: | brew update - brew install ccache gcc llvm hdf5 open-mpi openblas - mkdir $HOME/.venv - python3 -m venv $HOME/.venv/my_python - source $HOME/.venv/my_python/bin/activate + brew install ccache gcc llvm hdf5 open-mpi openblas doxygen pip install mako numpy scipy mpi4py pip install -r requirements.txt - echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV echo "PATH=$(brew --prefix llvm)/bin:$(brew --prefix gcc)/bin:$PATH" >> $GITHUB_ENV - - - name: Build doxygen - if: matrix.doc == 'ON' - env: - CC: ${{ matrix.cc }} - CXX: ${{ matrix.cxx }} - run: | - cd $HOME - git clone https://github.com/doxygen/doxygen.git - cd doxygen - git checkout Release_1_12_0 - mkdir build - cd build - cmake .. -Duse_libclang=ON -Duse_libc++=OFF - make -j 2 VERBOSE=1 - cp bin/doxygen /usr/local/bin/doxygen + echo "PYTHONPATH=$(brew --prefix llvm)/lib/python3.13/site-packages" >> $GITHUB_ENV - name: Add clang CXXFLAGS if: ${{ contains(matrix.cxx, 'clang') }}