Skip to content

Commit ff9cbe4

Browse files
committed
Updated parallelize to now return the number of used workers.
This aligns with the most recent updates to tatami::parallelize() via subpar::parallelize_range. Also fleshed out the documentation and updated the required versions of all dependencies.
1 parent a6d6299 commit ff9cbe4

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.24)
22

33
project(tatami_python
4-
VERSION 0.1.2
4+
VERSION 0.1.3
55
DESCRIPTION "tatami bindings for abstract Python matrices"
66
LANGUAGES CXX)
77

@@ -14,9 +14,9 @@ option(TATAMI_PYTHON_FETCH_EXTERN "Automatically fetch tatami_python's external
1414
if(TATAMI_PYTHON_FETCH_EXTERN)
1515
add_subdirectory(extern)
1616
else()
17-
find_package(tatami_tatami 4.0.0 CONFIG REQUIRED)
18-
find_package(tatami_tatami_chunked 2.0.0 CONFIG REQUIRED)
19-
find_package(ltla_sanisizer 0.1.0 CONFIG REQUIRED)
17+
find_package(tatami_tatami 4.1.0 CONFIG REQUIRED)
18+
find_package(tatami_tatami_chunked 2.1.0 CONFIG REQUIRED)
19+
find_package(ltla_sanisizer 0.2.0 CONFIG REQUIRED)
2020
endif()
2121

2222
target_link_libraries(tatami_python INTERFACE tatami::tatami tatami::tatami_chunked ltla::sanisizer)

cmake/Config.cmake.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@PACKAGE_INIT@
22

33
include(CMakeFindDependencyMacro)
4-
find_dependency(tatami_tatami 4.0.0 CONFIG REQUIRED)
5-
find_dependency(tatami_tatami_chunked 2.0.0 CONFIG REQUIRED)
6-
find_dependency(ltla_sanisizer 0.1.0 CONFIG REQUIRED)
4+
find_dependency(tatami_tatami 4.1.0 CONFIG REQUIRED)
5+
find_dependency(tatami_tatami_chunked 2.1.0 CONFIG REQUIRED)
6+
find_dependency(ltla_sanisizer 0.2.0 CONFIG REQUIRED)
77

88
include("${CMAKE_CURRENT_LIST_DIR}/tatami_tatami_pythonTargets.cmake")

extern/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ include(FetchContent)
33
FetchContent_Declare(
44
tatami
55
GIT_REPOSITORY https://github.com/tatami-inc/tatami
6-
GIT_TAG master # ^4.0.0
6+
GIT_TAG master # ^4.1.0
77
)
88

99
FetchContent_Declare(
1010
tatami_chunked
1111
GIT_REPOSITORY https://github.com/tatami-inc/tatami_chunked
12-
GIT_TAG master # ^2.0.0
12+
GIT_TAG master # ^2.1.0
1313
)
1414

1515
FetchContent_Declare(
1616
sanisizer
1717
GIT_REPOSITORY https://github.com/LTLA/sanisizer
18-
GIT_TAG master # ^1.0.0
18+
GIT_TAG master # ^0.2.0
1919
)
2020

2121
FetchContent_MakeAvailable(tatami)

include/tatami_python/parallelize.hpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,36 @@ namespace tatami_python {
3030

3131
/**
3232
* Replacement for `tatami::parallelize()` that applies a function to a set of tasks in parallel, usually for iterating over a dimension of a `Matrix`.
33-
* This releases the Python GIL so that it can be re-acquired by `UnknownMatrix` extractors in each individual thread.
33+
* This releases the Python GIL so that it can be re-acquired by `UnknownMatrix` extractors in each individual worker.
3434
*
3535
* @tparam Function_ Function to be applied to a contiguous range of tasks.
3636
* This should accept three arguments:
37-
* - `thread`, the thread number executing this task range.
38-
* This will be passed as an `int`.
37+
* - `worker`, the worker ID executing this task range.
38+
* This will be passed as an `int` in `[0, workers)`.
3939
* - `task_start`, the start index of the task range.
40-
* This will be passed as an `Index_`.
40+
* This will be passed as an `Index_` in `[0, tasks)`.
4141
* - `task_length`, the number of tasks in the task range.
42-
* This will be passed as an `Index_`.
42+
* This will be passed as an `Index_` in `(0, tasks)`, i.e., it is always positive.
4343
* @tparam Index_ Integer type for the number of tasks.
4444
*
4545
* @param fun Function that executes a contiguous range of tasks.
46+
* This will be called no more than once in each worker with a different non-overlapping range, where the union of all ranges will cover `[0, tasks)`.
4647
* @param tasks Number of tasks.
47-
* @param threads Number of threads.
48+
* This should be non-negative.
49+
* @param workers Number of workers.
50+
* This should be positive.
51+
*
52+
* @return The number of workers (`K`) that were actually used.
53+
* `K` is guaranteed to be no greater than `workers` (or 1, if `workers` is not positive).
54+
* `fun()` will have been called once for each of the worker IDs `[0, ..., K - 1]`.
4855
*/
4956
template<class Function_, class Index_>
50-
void parallelize(const Function_ fun, const Index_ tasks, int threads) {
57+
int parallelize(const Function_ fun, const Index_ tasks, int workers) {
5158
std::optional<pybind11::gil_scoped_release> ungil;
5259
if (PyGILState_Check()) {
5360
ungil.emplace();
5461
}
55-
subpar::parallelize_range(threads, tasks, std::move(fun));
62+
return subpar::parallelize_range(workers, tasks, std::move(fun));
5663
}
5764

5865
/**

0 commit comments

Comments
 (0)