julia> function f(_...)
s = 0.0
for i = 1:10^9
s = max(cos(i), sin(i))
end
return s
end
f (generic function with 2 methods)
julia> asyncmap(f, 1:2)
I always assumed asyncmap
never uses more than 100% * 1 CPU thread, and the above example indeed never exceed 100% when looking at top
command.
But the documentation is IMO confusion:
asyncmap(f, c…; ntasks=0, batch_size=nothing)
ntasks
specifies the number of tasks to run concurrently. Depending on the length of the collections, ifntasks
is unspecified, up to 100 tasks will be used for concurrent mapping.
ntasks
can also be specified as a zero-arg function. In this case, the number of tasks to run in parallel is checked before processing every element and a new task started if the value ofntasks_func
is greater than the current number of tasks.
I suspect the problem is that the word “concurrent” here is used under a super specific / narrow definition. Because this last bit of the doc actually describes the “will ever only use 100% * 1 CPU”
Currently, all tasks in Julia are executed in a single OS thread co-operatively. Consequently,
asyncmap
is beneficial only when the mapping function involves any I/O - disk, network, remote worker invocation, etc.
My “question” is, can we make the doc better? and what’s the point of having N tasks if they are all executed on a single OS thread anyway