Skip to content

Commit

Permalink
Merge pull request #40 from bluescarni/pr/coll
Browse files Browse the repository at this point in the history
Initial support for collision detection.
  • Loading branch information
bluescarni authored Apr 30, 2020
2 parents 1ef5f71 + 85f30c9 commit a526677
Show file tree
Hide file tree
Showing 16 changed files with 1,838 additions and 599 deletions.
96 changes: 84 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:
# - env: RAKAU_BUILD="osx_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="2"
# os: osx
# osx_image: xcode10.1
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -25,7 +25,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -34,7 +34,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -43,7 +43,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -52,7 +52,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -61,7 +61,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -70,7 +70,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -79,7 +79,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -88,7 +88,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -97,7 +97,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -106,7 +106,7 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand All @@ -115,7 +115,79 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-7
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
compiler: gcc
os: linux
addons:
Expand Down
52 changes: 38 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
cmake_minimum_required(VERSION 3.3.0)

project(rakau VERSION 0.1 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "rakau version: ${rakau_VERSION}")

# Set default build type to "Release".
# NOTE: this should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake).
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()

project(rakau VERSION 0.1 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
message(STATUS "rakau version: ${rakau_VERSION}")

# The build options.
option(RAKAU_BUILD_TESTS "Build unit tests." OFF)
option(RAKAU_BUILD_BENCHMARKS "Build benchmarks." OFF)
Expand Down Expand Up @@ -104,6 +106,28 @@ find_package(TBB REQUIRED)
# Threading setup.
include(RakauFindThreads)

# NOTE: on Unix systems, the correct library installation path
# could be something other than just "lib", such as "lib64",
# "lib32", etc., depending on platform/configuration. Apparently,
# CMake provides this information via the GNUInstallDirs module.
# Let's enable this for now on all Unixes except OSX.
# NOTE: potentially, this could be applicable to Cygwin as well.
#
# https://cmake.org/cmake/help/v3.15/module/GNUInstallDirs.html
# https://cmake.org/pipermail/cmake/2013-July/055375.html
if(UNIX AND NOT APPLE)
include(GNUInstallDirs)
set(_RAKAU_INSTALL_LIBDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}")
else()
set(_RAKAU_INSTALL_LIBDIR_DEFAULT "lib")
endif()
if(NOT RAKAU_INSTALL_LIBDIR)
set(RAKAU_INSTALL_LIBDIR "${_RAKAU_INSTALL_LIBDIR_DEFAULT}" CACHE STRING
"Library installation directory." FORCE)
endif()
mark_as_advanced(RAKAU_INSTALL_LIBDIR)
message(STATUS "Library installation directory: ${RAKAU_INSTALL_LIBDIR}")

# Initial setup of the rakau library.
if(RAKAU_WITH_ROCM)
add_library(rakau SHARED "${CMAKE_CURRENT_SOURCE_DIR}/src/rakau_rocm.cpp")
Expand Down Expand Up @@ -185,20 +209,20 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_BINA
set(_RAKAU_CONFIG_OPTIONAL_DEPS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/rakau-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" @ONLY)
if(RAKAU_WITH_ROCM OR RAKAU_WITH_CUDA)
install(TARGETS rakau EXPORT rakau_export LIBRARY DESTINATION "lib")
install(TARGETS rakau EXPORT rakau_export LIBRARY DESTINATION "${RAKAU_INSTALL_LIBDIR}")
else()
install(TARGETS rakau EXPORT rakau_export)
endif()
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" DESTINATION "lib/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindBoost.cmake" DESTINATION "lib/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake" DESTINATION "lib/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindThreads.cmake" DESTINATION "lib/cmake/rakau")
install(EXPORT rakau_export NAMESPACE rakau:: DESTINATION lib/cmake/rakau)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindBoost.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindThreads.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
install(EXPORT rakau_export NAMESPACE rakau:: DESTINATION ${RAKAU_INSTALL_LIBDIR}/cmake/rakau)
# Take care of versioning.
include(CMakePackageConfigHelpers)
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" VERSION ${rakau_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" DESTINATION "lib/cmake/rakau")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
unset(_RAKAU_CONFIG_OPTIONAL_DEPS)

# Installation of the header files.
Expand Down
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ endfunction()

ADD_RAKAU_BENCHMARK(benchmark_acc)
ADD_RAKAU_BENCHMARK(benchmark_acc_pot)
ADD_RAKAU_BENCHMARK(benchmark_coll)
ADD_RAKAU_BENCHMARK(benchmark_pot)
ADD_RAKAU_BENCHMARK(benchmark_move)
ADD_RAKAU_BENCHMARK(benchmark_leapfrog)
71 changes: 71 additions & 0 deletions benchmark/benchmark_coll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2018 Francesco Biscani ([email protected])
//
// This file is part of the rakau library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <initializer_list>
#include <iostream>
#include <numeric>
#include <optional>
#include <tuple>
#include <vector>

#include <tbb/task_scheduler_init.h>

#include <rakau/tree.hpp>

#include "common.hpp"

using namespace rakau;
using namespace rakau_benchmark;

int main(int argc, char **argv)
{
std::cout.precision(20);

const auto popts = parse_coll_benchmark_options(argc, argv);

std::optional<tbb::task_scheduler_init> t_init;
if (std::get<2>(popts)) {
t_init.emplace(std::get<2>(popts));
}

auto runner = [&popts](auto x) {
using fp_type = decltype(x);

const auto [nparts, max_leaf_n, _1, bsize, a, parinit, _2, ordered, psize] = popts;

auto parts = get_plummer_sphere(nparts, static_cast<fp_type>(a), static_cast<fp_type>(bsize), parinit);
const std::vector<fp_type> aabb_sizes(nparts, psize);

octree<fp_type> t{kwargs::x_coords = parts.data() + nparts,
kwargs::y_coords = parts.data() + 2 * nparts,
kwargs::z_coords = parts.data() + 3 * nparts,
kwargs::masses = parts.data(),
kwargs::nparts = nparts,
kwargs::max_leaf_n = max_leaf_n};

std::cout << t << '\n';

decltype(t.compute_cgraph_o(aabb_sizes.data())) cgraph;
if (ordered) {
cgraph = t.compute_cgraph_o(aabb_sizes.data());
} else {
cgraph = t.compute_cgraph_u(aabb_sizes.data());
}

const auto acc = std::accumulate(cgraph.begin(), cgraph.end(), 0ull,
[](auto cur, const auto &c) { return cur + c.size(); });

std::cout << "Total number of collisions detected: " << acc / 2u << '\n';
};

if (std::get<6>(popts) == "float") {
runner(0.f);
} else {
runner(0.);
}
}
Loading

0 comments on commit a526677

Please sign in to comment.