From a5b30247499ba7ef048f51cd0ecf78c35b5eea0a Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Wed, 10 Jan 2024 16:43:14 +0100 Subject: [PATCH] Use std::span for n-body --- examples/nbody/CMakeLists.txt | 2 +- examples/nbody/nbody.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/nbody/CMakeLists.txt b/examples/nbody/CMakeLists.txt index 89d261bd89..f1a2a0a467 100644 --- a/examples/nbody/CMakeLists.txt +++ b/examples/nbody/CMakeLists.txt @@ -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) diff --git a/examples/nbody/nbody.cpp b/examples/nbody/nbody.cpp index 9f09632496..2e7ed2a75b 100644 --- a/examples/nbody/nbody.cpp +++ b/examples/nbody/nbody.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -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' @@ -1339,7 +1340,7 @@ namespace manualAoSSIMD } template - void update(Particle* particles) + void update(std::span particles) { PARALLEL_FOR for(std::ptrdiff_t i = 0; i < problemSize; i += Simd::size) @@ -1370,7 +1371,7 @@ namespace manualAoSSIMD } template - void move(Particle* particles) + void move(std::span particles) { PARALLEL_FOR for(std::ptrdiff_t i = 0; i < problemSize; i += Simd::size) @@ -1412,10 +1413,10 @@ namespace manualAoSSIMD { if constexpr(runUpdate) { - update(particles.data()); + update(particles); statsUpdate(watch.printAndReset("update", '\t')); } - move(particles.data()); + manualAoSSIMD::move(particles); statsMove(watch.printAndReset("move")); } plotFile << std::quoted(title) << "\t" << statsUpdate.mean() << "\t" << statsUpdate.sem() << '\t'