Hi everyone,
I have a short question regarding the usage of the Threads.@spawn
macro in combination with Threads.@threads
. Say I have code which looks like
some_task = Threads.@spawn begin
some_function_call_1()
some_function_call_2()
end
for rep in reps
#this is the main loop
Threads.@threads for iter in iters
do_main_work(iter)
end
wait(some_task)
some_task = Threads.@spawn begin
some_function_call_1()
some_function_call_2()
end
end
I my naive understanding, the code does the following:
1.) Initializes some_task
on one available thread
2.) Enters the reps
loop
3.) Parallelize main work load (the inner loop) among available threads
4.) Wait for ‘some_task’ to finish
5.) Run some_task
on one available thread.
6.) Continue with next iteration in reps
loop with some_task
still running
I have a few questions regarding this
1.) Does this code actually do what I think it does?
2.) If the respective thread is finished with some_task
and the iters
loop is still running, will the remaining workload be dynamically managed such that this thread does not become idle and can steal some work from the other threads?
I am using the current master branch for this.
Thanks in advance.