Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with nested loops #86

Closed
ctkelley opened this issue Mar 16, 2024 · 2 comments · Fixed by #88
Closed

Problem with nested loops #86

ctkelley opened this issue Mar 16, 2024 · 2 comments · Fixed by #88
Labels
bug Something isn't working fix scheduled

Comments

@ctkelley
Copy link

ctkelley commented Mar 16, 2024

I am trying to get @tasks to work with a nested loop and am able to
find what I need in the docs. Herewith a MWE:

I've tried using @set but with no luck.

function looper(n = 10)
    A = rand(n, n)
    for k = 1:n
        A[:, k] .*= 2.0
        @tasks for j = k+1:n
            for i = k+1:n
                A[i, j] -= A[i, k] * A[k, j]
            end
        end
    end
end

I run Julia from a directory with only this file in it.

% julia --project=.
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.2 (2024-03-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using OhMyThreads

julia> include("looper.jl")
looper (generic function with 2 methods)

julia> looper()
ERROR: ArgumentError: You must either indicate the desired number of chunks (n) or the target size of a chunk (size).
Stacktrace:
  [1] missing_input_err()
    @ ChunkSplitters ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:118
  [2] getchunk(itr::UnitRange{Int64}, ichunk::Int64; n::Int64, size::Int64, split::Symbol)
    @ ChunkSplitters ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:274
  [3] getchunk
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:273 [inlined]
  [4] getchunk
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:293 [inlined]
  [5] iterate
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:142 [inlined]
  [6] iterate
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:141 [inlined]
  [7] iterate
    @ ./generator.jl:44 [inlined]
  [8] collect(itr::Base.Generator{ChunkSplitters.Chunk{…}, OhMyThreads.Implementation.var"#13#21"{…}})
    @ Base ./array.jl:834
  [9] map(f::Function, A::ChunkSplitters.Chunk{UnitRange{Int64}, ChunkSplitters.FixedCount})
    @ Base ./abstractarray.jl:3313
 [10] _tmapreduce(f::Function, op::Function, Arrs::Tuple{…}, ::Type{…}, scheduler::DynamicScheduler{…}, mapreduce_kwargs::@Kwargs{…})
    @ OhMyThreads.Implementation ~/.julia/packages/OhMyThreads/N9muZ/src/implementation.jl:52
 [11] #tmapreduce#10
    @ ~/.julia/packages/OhMyThreads/N9muZ/src/implementation.jl:33 [inlined]
 [12] tmapreduce
    @ ~/.julia/packages/OhMyThreads/N9muZ/src/implementation.jl:25 [inlined]
 [13] #tforeach#70
    @ ~/.julia/packages/OhMyThreads/N9muZ/src/implementation.jl:180 [inlined]
 [14] macro expansion
    @ ~/.julia/packages/OhMyThreads/N9muZ/src/macro_impl.jl:45 [inlined]
 [15] looper(n::Int64)
    @ Main ~/OMTest/looper.jl:5
 [16] looper()
    @ Main ~/OMTest/looper.jl:2
 [17] top-level scope
    @ REPL[3]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> 
@carstenbauer carstenbauer added the bug Something isn't working label Mar 16, 2024
@carstenbauer
Copy link
Member

carstenbauer commented Mar 17, 2024

The issue is

julia> using ChunkSplitters

julia> collect(chunks(11:10; n=6))
ERROR: ArgumentError: You must either indicate the desired number of chunks (n) or the target size of a chunk (size).
Stacktrace:
  [1] missing_input_err()
    @ ChunkSplitters ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:118
  [2] getchunk(itr::UnitRange{Int64}, ichunk::Int64; n::Int64, size::Int64, split::Symbol)
    @ ChunkSplitters ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:274
  [3] getchunk
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:273 [inlined]
  [4] getchunk
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:293 [inlined]
  [5] iterate
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:142 [inlined]
  [6] iterate
    @ ~/.julia/packages/ChunkSplitters/R5lnx/src/ChunkSplitters.jl:141 [inlined]
  [7] copyto!(dest::Vector{StepRange{Int64, Int64}}, src::ChunkSplitters.Chunk{UnitRange{Int64}, ChunkSplitters.FixedCount})
    @ Base ./abstractarray.jl:943
  [8] _collect
    @ ./array.jl:765 [inlined]
  [9] collect(itr::ChunkSplitters.Chunk{UnitRange{Int64}, ChunkSplitters.FixedCount})
    @ Base ./array.jl:759
 [10] top-level scope
    @ REPL[32]:1

It occurs because for k=n you get k+1:n == n+1:n which isempty.

Regular for loops support this case (i.e. they don't to anything) so we should as well. However, at least partially, this is an upstream issue because the error message above is clearly wrong and bad. On our side, we might consider checking !isempty(coll).

@carstenbauer
Copy link
Member

Will be fixed by #88 (in the next release).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix scheduled
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants