Skip to content

Commit a526677

Browse files
authored
Merge pull request #40 from bluescarni/pr/coll
Initial support for collision detection.
2 parents 1ef5f71 + 85f30c9 commit a526677

16 files changed

+1838
-599
lines changed

.travis.yml

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ matrix:
1616
# - env: RAKAU_BUILD="osx_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="2"
1717
# os: osx
1818
# osx_image: xcode10.1
19-
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
19+
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
2020
compiler: gcc
2121
os: linux
2222
addons:
@@ -25,7 +25,7 @@ matrix:
2525
- ubuntu-toolchain-r-test
2626
packages:
2727
- g++-7
28-
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
28+
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
2929
compiler: gcc
3030
os: linux
3131
addons:
@@ -34,7 +34,7 @@ matrix:
3434
- ubuntu-toolchain-r-test
3535
packages:
3636
- g++-7
37-
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
37+
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
3838
compiler: gcc
3939
os: linux
4040
addons:
@@ -43,7 +43,7 @@ matrix:
4343
- ubuntu-toolchain-r-test
4444
packages:
4545
- g++-7
46-
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
46+
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
4747
compiler: gcc
4848
os: linux
4949
addons:
@@ -52,7 +52,7 @@ matrix:
5252
- ubuntu-toolchain-r-test
5353
packages:
5454
- g++-7
55-
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
55+
- env: RAKAU_BUILD="gcc7_debug" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
5656
compiler: gcc
5757
os: linux
5858
addons:
@@ -61,7 +61,7 @@ matrix:
6161
- ubuntu-toolchain-r-test
6262
packages:
6363
- g++-7
64-
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
64+
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
6565
compiler: gcc
6666
os: linux
6767
addons:
@@ -70,7 +70,7 @@ matrix:
7070
- ubuntu-toolchain-r-test
7171
packages:
7272
- g++-7
73-
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
73+
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
7474
compiler: gcc
7575
os: linux
7676
addons:
@@ -79,7 +79,7 @@ matrix:
7979
- ubuntu-toolchain-r-test
8080
packages:
8181
- g++-7
82-
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
82+
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
8383
compiler: gcc
8484
os: linux
8585
addons:
@@ -88,7 +88,7 @@ matrix:
8888
- ubuntu-toolchain-r-test
8989
packages:
9090
- g++-7
91-
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
91+
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
9292
compiler: gcc
9393
os: linux
9494
addons:
@@ -97,7 +97,7 @@ matrix:
9797
- ubuntu-toolchain-r-test
9898
packages:
9999
- g++-7
100-
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="0" TEST_NSPLIT="3"
100+
- env: RAKAU_BUILD="gcc7_debug_nosimd" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
101101
compiler: gcc
102102
os: linux
103103
addons:
@@ -106,7 +106,7 @@ matrix:
106106
- ubuntu-toolchain-r-test
107107
packages:
108108
- g++-7
109-
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="1" TEST_NSPLIT="3"
109+
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
110110
compiler: gcc
111111
os: linux
112112
addons:
@@ -115,7 +115,79 @@ matrix:
115115
- ubuntu-toolchain-r-test
116116
packages:
117117
- g++-7
118-
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="2" TEST_NSPLIT="3"
118+
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
119+
compiler: gcc
120+
os: linux
121+
addons:
122+
apt:
123+
sources:
124+
- ubuntu-toolchain-r-test
125+
packages:
126+
- g++-7
127+
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
128+
compiler: gcc
129+
os: linux
130+
addons:
131+
apt:
132+
sources:
133+
- ubuntu-toolchain-r-test
134+
packages:
135+
- g++-7
136+
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
137+
compiler: gcc
138+
os: linux
139+
addons:
140+
apt:
141+
sources:
142+
- ubuntu-toolchain-r-test
143+
packages:
144+
- g++-7
145+
- env: RAKAU_BUILD="gcc7_debug_native" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
146+
compiler: gcc
147+
os: linux
148+
addons:
149+
apt:
150+
sources:
151+
- ubuntu-toolchain-r-test
152+
packages:
153+
- g++-7
154+
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="0" TEST_NSPLIT="5"
155+
compiler: gcc
156+
os: linux
157+
addons:
158+
apt:
159+
sources:
160+
- ubuntu-toolchain-r-test
161+
packages:
162+
- g++-7
163+
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="1" TEST_NSPLIT="5"
164+
compiler: gcc
165+
os: linux
166+
addons:
167+
apt:
168+
sources:
169+
- ubuntu-toolchain-r-test
170+
packages:
171+
- g++-7
172+
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="2" TEST_NSPLIT="5"
173+
compiler: gcc
174+
os: linux
175+
addons:
176+
apt:
177+
sources:
178+
- ubuntu-toolchain-r-test
179+
packages:
180+
- g++-7
181+
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="3" TEST_NSPLIT="5"
182+
compiler: gcc
183+
os: linux
184+
addons:
185+
apt:
186+
sources:
187+
- ubuntu-toolchain-r-test
188+
packages:
189+
- g++-7
190+
- env: RAKAU_BUILD="gcc7_debug_native_norsqrt" SPLIT_TEST_NUM="4" TEST_NSPLIT="5"
119191
compiler: gcc
120192
os: linux
121193
addons:

CMakeLists.txt

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
cmake_minimum_required(VERSION 3.3.0)
22

3-
project(rakau VERSION 0.1 LANGUAGES CXX C)
4-
5-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")
6-
7-
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
8-
message(STATUS "rakau version: ${rakau_VERSION}")
9-
103
# Set default build type to "Release".
4+
# NOTE: this should be done before the project command since the latter can set
5+
# CMAKE_BUILD_TYPE itself (it does so for nmake).
116
if(NOT CMAKE_BUILD_TYPE)
127
set(CMAKE_BUILD_TYPE Release CACHE STRING
138
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
149
FORCE)
1510
endif()
1611

12+
project(rakau VERSION 0.1 LANGUAGES CXX C)
13+
14+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")
15+
16+
message(STATUS "System name: ${CMAKE_SYSTEM_NAME}")
17+
message(STATUS "rakau version: ${rakau_VERSION}")
18+
1719
# The build options.
1820
option(RAKAU_BUILD_TESTS "Build unit tests." OFF)
1921
option(RAKAU_BUILD_BENCHMARKS "Build benchmarks." OFF)
@@ -104,6 +106,28 @@ find_package(TBB REQUIRED)
104106
# Threading setup.
105107
include(RakauFindThreads)
106108

109+
# NOTE: on Unix systems, the correct library installation path
110+
# could be something other than just "lib", such as "lib64",
111+
# "lib32", etc., depending on platform/configuration. Apparently,
112+
# CMake provides this information via the GNUInstallDirs module.
113+
# Let's enable this for now on all Unixes except OSX.
114+
# NOTE: potentially, this could be applicable to Cygwin as well.
115+
#
116+
# https://cmake.org/cmake/help/v3.15/module/GNUInstallDirs.html
117+
# https://cmake.org/pipermail/cmake/2013-July/055375.html
118+
if(UNIX AND NOT APPLE)
119+
include(GNUInstallDirs)
120+
set(_RAKAU_INSTALL_LIBDIR_DEFAULT "${CMAKE_INSTALL_LIBDIR}")
121+
else()
122+
set(_RAKAU_INSTALL_LIBDIR_DEFAULT "lib")
123+
endif()
124+
if(NOT RAKAU_INSTALL_LIBDIR)
125+
set(RAKAU_INSTALL_LIBDIR "${_RAKAU_INSTALL_LIBDIR_DEFAULT}" CACHE STRING
126+
"Library installation directory." FORCE)
127+
endif()
128+
mark_as_advanced(RAKAU_INSTALL_LIBDIR)
129+
message(STATUS "Library installation directory: ${RAKAU_INSTALL_LIBDIR}")
130+
107131
# Initial setup of the rakau library.
108132
if(RAKAU_WITH_ROCM)
109133
add_library(rakau SHARED "${CMAKE_CURRENT_SOURCE_DIR}/src/rakau_rocm.cpp")
@@ -185,20 +209,20 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_BINA
185209
set(_RAKAU_CONFIG_OPTIONAL_DEPS)
186210
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/rakau-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" @ONLY)
187211
if(RAKAU_WITH_ROCM OR RAKAU_WITH_CUDA)
188-
install(TARGETS rakau EXPORT rakau_export LIBRARY DESTINATION "lib")
212+
install(TARGETS rakau EXPORT rakau_export LIBRARY DESTINATION "${RAKAU_INSTALL_LIBDIR}")
189213
else()
190214
install(TARGETS rakau EXPORT rakau_export)
191215
endif()
192-
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" DESTINATION "lib/cmake/rakau")
193-
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindBoost.cmake" DESTINATION "lib/cmake/rakau")
194-
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake" DESTINATION "lib/cmake/rakau")
195-
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindThreads.cmake" DESTINATION "lib/cmake/rakau")
196-
install(EXPORT rakau_export NAMESPACE rakau:: DESTINATION lib/cmake/rakau)
216+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
217+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindBoost.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
218+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindTBB.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
219+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/RakauFindThreads.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
220+
install(EXPORT rakau_export NAMESPACE rakau:: DESTINATION ${RAKAU_INSTALL_LIBDIR}/cmake/rakau)
197221
# Take care of versioning.
198222
include(CMakePackageConfigHelpers)
199223
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" VERSION ${rakau_VERSION}
200224
COMPATIBILITY SameMajorVersion)
201-
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" DESTINATION "lib/cmake/rakau")
225+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/rakau-config-version.cmake" DESTINATION "${RAKAU_INSTALL_LIBDIR}/cmake/rakau")
202226
unset(_RAKAU_CONFIG_OPTIONAL_DEPS)
203227

204228
# Installation of the header files.

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ endfunction()
1212

1313
ADD_RAKAU_BENCHMARK(benchmark_acc)
1414
ADD_RAKAU_BENCHMARK(benchmark_acc_pot)
15+
ADD_RAKAU_BENCHMARK(benchmark_coll)
1516
ADD_RAKAU_BENCHMARK(benchmark_pot)
1617
ADD_RAKAU_BENCHMARK(benchmark_move)
1718
ADD_RAKAU_BENCHMARK(benchmark_leapfrog)

benchmark/benchmark_coll.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2018 Francesco Biscani (bluescarni@gmail.com)
2+
//
3+
// This file is part of the rakau library.
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla
6+
// Public License v. 2.0. If a copy of the MPL was not distributed
7+
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
9+
#include <initializer_list>
10+
#include <iostream>
11+
#include <numeric>
12+
#include <optional>
13+
#include <tuple>
14+
#include <vector>
15+
16+
#include <tbb/task_scheduler_init.h>
17+
18+
#include <rakau/tree.hpp>
19+
20+
#include "common.hpp"
21+
22+
using namespace rakau;
23+
using namespace rakau_benchmark;
24+
25+
int main(int argc, char **argv)
26+
{
27+
std::cout.precision(20);
28+
29+
const auto popts = parse_coll_benchmark_options(argc, argv);
30+
31+
std::optional<tbb::task_scheduler_init> t_init;
32+
if (std::get<2>(popts)) {
33+
t_init.emplace(std::get<2>(popts));
34+
}
35+
36+
auto runner = [&popts](auto x) {
37+
using fp_type = decltype(x);
38+
39+
const auto [nparts, max_leaf_n, _1, bsize, a, parinit, _2, ordered, psize] = popts;
40+
41+
auto parts = get_plummer_sphere(nparts, static_cast<fp_type>(a), static_cast<fp_type>(bsize), parinit);
42+
const std::vector<fp_type> aabb_sizes(nparts, psize);
43+
44+
octree<fp_type> t{kwargs::x_coords = parts.data() + nparts,
45+
kwargs::y_coords = parts.data() + 2 * nparts,
46+
kwargs::z_coords = parts.data() + 3 * nparts,
47+
kwargs::masses = parts.data(),
48+
kwargs::nparts = nparts,
49+
kwargs::max_leaf_n = max_leaf_n};
50+
51+
std::cout << t << '\n';
52+
53+
decltype(t.compute_cgraph_o(aabb_sizes.data())) cgraph;
54+
if (ordered) {
55+
cgraph = t.compute_cgraph_o(aabb_sizes.data());
56+
} else {
57+
cgraph = t.compute_cgraph_u(aabb_sizes.data());
58+
}
59+
60+
const auto acc = std::accumulate(cgraph.begin(), cgraph.end(), 0ull,
61+
[](auto cur, const auto &c) { return cur + c.size(); });
62+
63+
std::cout << "Total number of collisions detected: " << acc / 2u << '\n';
64+
};
65+
66+
if (std::get<6>(popts) == "float") {
67+
runner(0.f);
68+
} else {
69+
runner(0.);
70+
}
71+
}

0 commit comments

Comments
 (0)