如何在Julia中并行地将字典计算结果添加到字典中?

时间:2017-06-06 09:04:45

标签: dictionary parallel-processing julia

我想并行化函数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的计算吗?这是一个有效的例子。在我的实际计算中,函数solveZerobisect以及linearEqauation来自不同的模块。如何为并行计算相应地初始化这些函数?

0 个答案:

没有答案