Skip to content

Commit

Permalink
Test for correct use of the thread ID in parallelize() calls.
Browse files Browse the repository at this point in the history
This requires an additional test executable where subpar's silly test
parallelization has been enabled. Also made sure that all thread IDs
were passed around as int's for consistency with tatami's parallelize.
  • Loading branch information
LTLA committed Sep 16, 2024
1 parent 2dd81e4 commit 3fccec5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
10 changes: 5 additions & 5 deletions include/scran_qc/per_cell_qc_metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void compute_qc_direct_dense(
}
}

tatami::parallelize([&](size_t, Index_ start, Index_ length) {
tatami::parallelize([&](int, Index_ start, Index_ length) {
auto NR = mat.nrow();
auto ext = tatami::consecutive_extractor<false>(&mat, false, start, length);
std::vector<Value_> vbuffer(NR);
Expand Down Expand Up @@ -261,7 +261,7 @@ void compute_qc_direct_sparse(
{
auto is_in_subset = boolify_subsets(mat.nrow(), subsets, output);

tatami::parallelize([&](size_t, Index_ start, Index_ length) {
tatami::parallelize([&](int, Index_ start, Index_ length) {
auto NR = mat.nrow();
auto ext = tatami::consecutive_extractor<true>(&mat, false, start, length);
std::vector<Value_> vbuffer(NR);
Expand Down Expand Up @@ -362,7 +362,7 @@ void compute_qc_direct_sparse(
template<typename Sum_, typename Detected_, typename Value_, typename Index_>
class PerCellQcMetricsRunningBuffers {
public:
PerCellQcMetricsRunningBuffers(const PerCellQcMetricsBuffers<Sum_, Detected_, Value_, Index_>& output, size_t thread, Index_ start, Index_ len) {
PerCellQcMetricsRunningBuffers(const PerCellQcMetricsBuffers<Sum_, Detected_, Value_, Index_>& output, int thread, Index_ start, Index_ len) {
if (output.sum) {
my_sum = tatami_stats::LocalOutputBuffer<Sum_>(thread, start, len, output.sum);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ void compute_qc_running_dense(
{
auto is_in_subset = boolify_subsets(mat.nrow(), subsets, output);

tatami::parallelize([&](size_t thread, Index_ start, Index_ len) {
tatami::parallelize([&](int thread, Index_ start, Index_ len) {
auto NR = mat.nrow();
auto ext = tatami::consecutive_extractor<false>(&mat, true, static_cast<Index_>(0), NR, start, len);
std::vector<Value_> vbuffer(len);
Expand Down Expand Up @@ -576,7 +576,7 @@ void compute_qc_running_sparse(
opt.sparse_ordered_index = false;
auto is_in_subset = boolify_subsets(mat.nrow(), subsets, output);

tatami::parallelize([&](size_t thread, Index_ start, Index_ len) {
tatami::parallelize([&](int thread, Index_ start, Index_ len) {
auto NR = mat.nrow();
auto ext = tatami::consecutive_extractor<true>(&mat, true, static_cast<Index_>(0), NR, start, len, opt);
std::vector<Value_> vbuffer(len);
Expand Down
46 changes: 31 additions & 15 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(scran_tests)

option(CODE_COVERAGE "Enable coverage testing" OFF)
set(DO_CODE_COVERAGE OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
set(DO_CODE_COVERAGE ON)
endif()

include(GoogleTest)

macro(decorate_executable target)
target_link_libraries(
${target}
scran_qc
scran_tests
)

target_compile_options(${target} PRIVATE -Wall -Werror -Wpedantic -Wextra)

if(DO_CODE_COVERAGE)
target_compile_options(${target} PRIVATE -O0 -g --coverage)
target_link_options(${target} PRIVATE --coverage)
endif()

gtest_discover_tests(${target})
endmacro()

add_executable(
libtest
src/per_cell_qc_metrics.cpp
Expand All @@ -16,20 +41,11 @@ add_executable(
src/crispr_quality_control.cpp
src/format_filters.cpp
)
decorate_executable(libtest)

target_link_libraries(
libtest
scran_qc
scran_tests
add_executable(
cuspartest
src/per_cell_qc_metrics.cpp
)

target_compile_options(libtest PRIVATE -Wall -Werror -Wpedantic -Wextra)

option(CODE_COVERAGE "Enable coverage testing" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(libtest PRIVATE -O0 -g --coverage)
target_link_options(libtest PRIVATE --coverage)
endif()

include(GoogleTest)
gtest_discover_tests(libtest)
decorate_executable(cuspartest)
target_compile_definitions(cuspartest PRIVATE SUBPAR_CUSTOM_PARALLELIZE_RANGE=::subpar::test_parallelize_range)

0 comments on commit 3fccec5

Please sign in to comment.