Skip to content

Commit

Permalink
Use std::span for n-body
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 10, 2024
1 parent b02cf7a commit a5b3024
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/nbody/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if (NOT TARGET llama::llama)
endif()

add_executable(${PROJECT_NAME} nbody.cpp ../common/Stopwatch.hpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama fmt::fmt)
if (LLAMA_NBODY_OPENMP)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenMP::OpenMP_CXX)
Expand Down
11 changes: 6 additions & 5 deletions examples/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <iostream>
#include <llama/llama.hpp>
#include <random>
#include <span>
#include <thread>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -482,7 +483,7 @@ namespace manualAoS
update(particles.data());
statsUpdate(watch.printAndReset("update", '\t'));
}
move(particles.data());
manualAoS::move(particles.data());
statsMove(watch.printAndReset("move"));
}
plotFile << std::quoted(title) << "\t" << statsUpdate.mean() << "\t" << statsUpdate.sem() << '\t'
Expand Down Expand Up @@ -1339,7 +1340,7 @@ namespace manualAoSSIMD
}

template<typename Simd>
void update(Particle* particles)
void update(std::span<Particle> particles)
{
PARALLEL_FOR
for(std::ptrdiff_t i = 0; i < problemSize; i += Simd::size)
Expand Down Expand Up @@ -1370,7 +1371,7 @@ namespace manualAoSSIMD
}

template<typename Simd>
void move(Particle* particles)
void move(std::span<Particle> particles)
{
PARALLEL_FOR
for(std::ptrdiff_t i = 0; i < problemSize; i += Simd::size)
Expand Down Expand Up @@ -1412,10 +1413,10 @@ namespace manualAoSSIMD
{
if constexpr(runUpdate)
{
update<Simd>(particles.data());
update<Simd>(particles);
statsUpdate(watch.printAndReset("update", '\t'));
}
move<Simd>(particles.data());
manualAoSSIMD::move<Simd>(particles);
statsMove(watch.printAndReset("move"));
}
plotFile << std::quoted(title) << "\t" << statsUpdate.mean() << "\t" << statsUpdate.sem() << '\t'
Expand Down

0 comments on commit a5b3024

Please sign in to comment.