I am trying to write the function that launches multithreaded processes and then pins the threads to the core.
The stripped down version looks like
using Distributed, ThreadPinning function add_pinned_workers(nw::Int, nt::Int, coress) worker_list = addprocs(nw, exeflags=["--threads=$nt", "--project=$(Base.active_project())"]) @sync for wid in worker_list @spawnat wid ThreadPinning.pinthreads(worker_list[wid-1]) end end
Now, on a 8 core machine I can, for example, run
add_pinned_workers(2,4, [[0,1,2,3],[4,5,6,7]]). However, this code does not execute, because
ThreadPinning is not loaded on the newly added processes:
KeyError: key ThreadPinning [811555cd-349b-4f26-b7bc-1f208b848042] not found
Essentially, I need somehow to add
ThreadPinning to the freshly spawned workers in the same function call. I have tried adding something like
using ThreadPinning inside the function, but it is not allowed:
ERROR: LoadError: syntax: “using” expression not at top level
So, how to actually use “using” inside a function? Or do something similar in effect?