Skip to content

Commit

Permalink
fix some doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed Dec 20, 2023
1 parent a1cf1a5 commit 2df4df0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

Working with chunks and their respective indices also improves thread-safety compared to a naive approach based on `threadid()` indexing (see [PSA: Thread-local state is no longer recommended](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/)).

!!! compat
In ChunkSplitters version 3.0 the iteration with `chunks` returns the ranges of indices only. The retrieve
the chunk indices, use `enumerate(chunks(...))`. Additionally, the number of chunks and the distribution type
of chunks are assigned with keyword arguments `n`, and `distribution`.

## Installation

Install with:
Expand All @@ -13,10 +18,6 @@ julia> import Pkg; Pkg.add("ChunkSplitters")

## The `chunks` iterator

!!! compat
In ChunkSplitters version 3.0 the iteration with `chunks` returns the ranges of indices only. The retrieve
the chunk indices, use `enumerate(chunks(...))`.

The main interface is the `chunks` iterator, and the enumeration of chunks, with `enumerate`.

```julia
Expand Down Expand Up @@ -134,7 +135,7 @@ julia> sum(chunk_sums)

The package also provides a lower-level `getchunk` function:
```julia-repl
getchunk(array::AbstractArray, ichunk::Int, n::Int, distribution::Symbol=:batch)
getchunk(array::AbstractArray, ichunk::Int, n::Int, distribution::Symbol)
```
that returns the range of indices corresponding to the work items in the input `array` that are associated with chunk number `ichunk`.

Expand Down Expand Up @@ -163,13 +164,13 @@ julia> using ChunkSplitters
julia> x = rand(7);
julia> getchunk(x, 1, 3, distribution=:scatter)
julia> getchunk(x, 1, 3, :scatter)
1:3:7
julia> getchunk(x, 2, 3, distribution=:scatter)
julia> getchunk(x, 2, 3, :scatter)
2:3:5
julia> getchunk(x, 3, 3, distribution=:scatter)
julia> getchunk(x, 3, 3, :scatter)
3:3:6
```

Expand Down
4 changes: 2 additions & 2 deletions docs/src/load_balancing.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ Using `n == Thread.nthreads() == 12`, we get the following timings:
```julia-repl
julia> using BenchmarkTools
julia> @btime uneven_workload_threads($x, $work_load; n=nthreads(), chunk_distribution=:batch)
julia> @btime uneven_workload_threads($x, $work_load; n=nthreads(), distribution=:batch)
2.030 ms (71 allocations: 7.06 KiB)
julia> @btime uneven_workload_threads($x, $work_load; n=nthreads(), chunk_distribution=:scatter)
julia> @btime uneven_workload_threads($x, $work_load; n=nthreads(), distribution=:scatter)
587.309 μs (70 allocations: 7.03 KiB)
```

Expand Down
6 changes: 3 additions & 3 deletions src/ChunkSplitters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ julia> using ChunkSplitters
julia> x = rand(7);
julia> getchunk(x, 1, 3, distribution=:scatter)
julia> getchunk(x, 1, 3, :scatter)
1:3:7
julia> getchunk(x, 2, 3, distribution=:scatter)
julia> getchunk(x, 2, 3, :scatter)
2:3:5
julia> getchunk(x, 3, 3, distribution=:scatter)
julia> getchunk(x, 3, 3, :scatter)
3:3:6
```
"""
Expand Down

0 comments on commit 2df4df0

Please sign in to comment.