How to set parallel parameters very easily, where the function needs to use other packages. Using LinearAlgebra as an example, I want to set an isparfor parameter and package it into a function:
At present, if you want to use parallelism, you must set it in the Main main function file like this
if isparfor==1 #1 parallel, 0 not parallel
Preformatted textusing Distributed
addprocs(4)
@everywhere using LinearAlgebra
fun1
else
using Linear Algebra
fun1
end
I want to make this into a function, but the using must be at the first level, but other parallel processes must use other packages. Is there a good way to pack the parallel parameter using package into a function or module,
so that the call only needs
funparfor(1) enables parallel
funparfor(0) does not enable parallel!
The desired function is similar to the following
using Distributed
function funparfor(isparfor)
if isparfor ==0
addprocs(4)
@everywhere using LinearAlgebra
fun1
else
using Linear Algebra
fun1
end