Skip to content

Commit

Permalink
Merge 5e94707 into ff7c461
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenvd committed May 28, 2020
2 parents ff7c461 + 5e94707 commit c9aac59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Strided.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ export StridedView, @strided, @unsafe_strided, sreshape, sview
# Threads.nthreads() == 1 && warn("Strided disables BLAS multithreading, enable Julia threading (`export JULIA_NUM_THREADS = N`) to benefit from multithreaded matrix multiplication and more")
# end

const _use_threads = Ref(true)
use_threads() = _use_threads[]

"""
disable_threads()
Disable the use of threading in Strided.
Also see [`enable_threads()`](@ref)
"""
function disable_threads()
_use_threads[] = false
return
end

"""
enable_threads()
(Re)-enable threading in Strided.
"""
function enable_threads()
_use_threads[] = true
return
end

# used to factor the number of threads
function simpleprimefactorization(n::Int)
factors = Vector{Int}()
Expand Down
2 changes: 1 addition & 1 deletion src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function _mapreduce_block!(@nospecialize(f), @nospecialize(op), @nospecialize(in
mincosts = map(a->ifelse(iszero(a), 1, a << 1), minstrides)
blocks = _computeblocks(dims, mincosts, strides)

if Threads.nthreads() == 1 || prod(dims) < BLOCKSIZE
if Threads.nthreads() == 1 || !use_threads() || prod(dims) < BLOCKSIZE
_mapreduce_kernel!(f, op, initop, dims, blocks, arrays, strides, offsets)
elseif _length(dims, strides[1]) == 1 # complete reduction
T = eltype(arrays[1])
Expand Down

0 comments on commit c9aac59

Please sign in to comment.