Skip to content

Task id as a local variable #157

@fredrikekre

Description

@fredrikekre

I think it would be useful to give the user access to the task id (i.e. 1:ntasks:). My motivation for this is code that have this pattern (which is pretty common):

for i in 1:N
    @tasks for j in 1:N
        @local cache = computation_with_heavy_allocs()
    end
end

where there currently isn't a great way to hoist the task local cache allocation out of the outer loop. If I can observe the task id I can do something like

caches = [computation_with_heavy_allocs() for _ in 1:ntasks]
for i in 1:N
    @tasks for j in 1:N
        @local cache = caches[OhMyThreads.taskid()] # or @taskid
    end
end

Is there a better way to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions