我想并行化函数solveZeros
的计算,用于S中的不同元素。函数如下:
function solveZeros(S)
"""
Solves for zeros of a linear equation for each element in S and returns
a dictionary with arguments k as keys and the solution as item
"""
results = Dict{}()
for (a,b) in S
solution = bisect(a, b)
results[(a,b)] = solution
end
return results
end
function bisect(a,b)
"""
Uses bisection to find the root of the linear function. a is the slope
and b the intercept
"""
low, high = 0, 100
while (high - low) > 1E-2
mid = low + (high - low ) / 2
if abs(linearEquation(a, b, mid)) < 1E-1
return mid
elseif linearEquation(a, b, mid) > 0
high = mid
else
low = mid
end
end
return nothing
end
function linearEquation(a, b, x)
return a * x + b
end
S = Array([(1., -10), (1., -20)])
有人可以解释如何并行化函数solveZeros
的计算吗?这是一个有效的例子。在我的实际计算中,函数solveZero
和bisect
以及linearEqauation
来自不同的模块。如何为并行计算相应地初始化这些函数?