Skip to content

Commit

Permalink
Sanitize the number of threads when parallelizing the count.
Browse files Browse the repository at this point in the history
This avoids overallocation when too many threads are specified, and avoids real
problems when a user specifies a non-positive number of threads. This now
requires a direct (instead of transitive) dependency on subpar.
  • Loading branch information
LTLA committed Sep 2, 2024
1 parent 1f1c8b7 commit 63716be
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ if(TATAMI_STATS_FETCH_EXTERN)
add_subdirectory(extern)
else()
find_package(tatami_tatami 3.0.0 CONFIG REQUIRED)
find_package(ltla_subpar 0.3.0 CONFIG REQUIRED)
endif()

target_link_libraries(tatami_stats INTERFACE tatami::tatami)
target_link_libraries(tatami_stats INTERFACE tatami::tatami ltla::subpar)

include(GNUInstallDirs)
target_include_directories(tatami_stats INTERFACE
Expand Down
1 change: 1 addition & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

include(CMakeFindDependencyMacro)
find_dependency(tatami_tatami 3.0.0 CONFIG REQUIRED)
find_dependency(ltla_subpar 0.3.0 CONFIG REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/tatami_tatami_statsTargets.cmake")
10 changes: 8 additions & 2 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ include(FetchContent)
FetchContent_Declare(
tatami
GIT_REPOSITORY https://github.com/tatami-inc/tatami
GIT_TAG master # ^v3.0.0
GIT_TAG master # ^3.0.0
)

FetchContent_MakeAvailable(tatami)
FetchContent_Declare(
subpar
GIT_REPOSITORY https://github.com/LTLA/subpar
GIT_TAG master # ^0.3.0
)

FetchContent_MakeAvailable(tatami)
FetchContent_MakeAvailable(subpar)
1 change: 1 addition & 0 deletions include/tatami_stats/counts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ void apply(bool row, const tatami::Matrix<Value_, Index_>* p, Output_* output, i
}

} else {
num_threads = subpar::sanitize_num_workers(num_threads, otherdim); // provides some protection against silly num_threads iputs.
std::vector<Output_*> threaded_output_ptrs(num_threads, output);
std::vector<std::vector<Output_> > threaded_output(num_threads - 1);
for (int t = 1; t < num_threads; ++t) {
Expand Down

0 comments on commit 63716be

Please sign in to comment.