I have been working to parallelize a function which reads in an input of polynomials and outputs their roots. The polynomials are in the form of a matrix with columns being each polynomial. It works perfectly fine calling directly, but I get strange behaviour once I use pmap.
using Distributed
@everywhere begin
using PolynomialRoots
end
addprocs(2)
@everywhere global test = ones(Int64, 10,10)
@everywhere begin
function polyRootS(n)
q=test[:,n]
r = roots(q) # provides poly roots from a vector input
return r
end
end
function parPolyRoots()
pmap(x->polyRootS(x) ? error("failed") : x, 1:10; on_error=identity)
end
for i in 1:10
r = polyRootS(i)
println(r)
end
parPolyRoots()
As far as I have read pmap should in effect just be parallelizing the loop when calling polyRootS yet I instead get the outputs:
ComplexF64[0.30901699437494734 + 0.9510565162951534im, 0.8090169943749473 - 0.587785252292473im, -0.8090169943749473 - 0.587785252292473im, -0.8090169943749475 + 0.587785252292473im, 0.8090169943749475 + 0.5877852522924731im, 0.30901699437494745 - 0.9510565162951535im, -1.0 - 7.671452424696258e-18im, -0.30901699437494734 - 0.9510565162951536im, -0.3090169943749474 + 0.9510565162951536im]
for my test matrix and
TypeError(:if, "", Bool, ComplexF64[0.30901699437494734 + 0.9510565162951534im, 0.8090169943749473 - 0.587785252292473im, -0.8090169943749473 - 0.587785252292473im, -0.8090169943749475 + 0.587785252292473im, 0.8090169943749475 + 0.5877852522924731im, 0.30901699437494745 - 0.9510565162951535im, -1.0 - 7.671452424696258e-18im, -0.30901699437494734 - 0.9510565162951536im, -0.3090169943749474 + 0.9510565162951536im])
for my pmap function call. So I am quite puzzled. If someone could point me to some different documentation for pmap and or a few examples that would be especially helpful.
A different question, can I start an @everything begin end statement and cover my defined functions, data, and packages at once or is it best practice to individually isolate them?
Using Julia 1.6.1 in VSCode with Julia extension. Running on Win10 with Intel i5.