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

Threads macro load balancing option #32207

Closed
ChrisRackauckas opened this issue May 31, 2019 · 6 comments
Closed

Threads macro load balancing option #32207

ChrisRackauckas opened this issue May 31, 2019 · 6 comments
Labels
multithreading Base.Threads and related functionality

Comments

@ChrisRackauckas
Copy link
Member

As discussed with @JeffBezanson in the Slack, @threads still uses a static schedule. However, there are some cases where we are using it as a simple way to express a lot of similar computations to be done on threads, each of which is actually quite expensive and not the same size. Thus for our purposes it would make sense to utilize @par to get the dynamic scheduling, but it makes sense "aesthetics-wise" to just put @threads on the loop. Thus it would make sense to have something like @threads dynamic for i in ... where

macro par(expr)
    thunk = esc(:(()->($expr)))
    quote
        local task = Task($thunk)
        task.sticky = false
        schedule(task)
        task
    end
end

it turns the loop

_f = (i) -> # inner expression of the loop
for i in 1:100
  @par _f(i)
end

If I'm not mistaken that's all that's necessary?

@quinnj
Copy link
Member

quinnj commented May 31, 2019

We should probably also think about asyncmap; maybe it could take a dynamic=true keyword argument or something.

@JeffBezanson JeffBezanson added the multithreading Base.Threads and related functionality label May 31, 2019
@vchuravy
Copy link
Member

Not quite, I think the right way of doing this is to enhance @async so that it can set task.sticky, since you will need an @sync.

@sync for i in 1:100
  @async par=true _f(i)
end

@stevengj
Copy link
Member

Should it just default to a dynamic schedule once partr is working well? That's what Cilk does, right?

@StefanKarpinski
Copy link
Member

Balanced workload is the exception rather than the rule, so imo, yes.

@JeffBezanson
Copy link
Member

Duplicate of #21017

@andreasnoack
Copy link
Member

Why not close if it's a duplicate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multithreading Base.Threads and related functionality
Projects
None yet
Development

No branches or pull requests

8 participants