Get task id of `@asyncmap`

How to get the task id in a asyncmap, similar to myid() in pmap?

Something like

asyncmap(_->myasyncid(), 1:10)

I want to use the id to balance workload on GPUs.

Okay, workaround:

n = 0
gpumap = Dict()
asyncmap(1:32; ntasks=16) do file
    # get gpu id
    if haskey(gpumap, objectid(current_task()))
        GPU = gpumap[objectid(current_task())]
    else
        global n
        GPU = n % 8
        n += 1
        gpumap[objectid(current_task())] = GPU
    end
    println(GPU)
end

Seems like you should just be keying the Dict off of the Task itself (e.g. current_task()), rather than converting to a (theoretically non-unique) integer first?

1 Like