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

Dictionary 如何在Julia中并行地将计算结果添加到字典中?,dictionary,parallel-processing,julia,Dictionary,Parallel Processing,Julia,我想为S中的不同元素并行计算函数solveZeros。函数如下所示: 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

我想为S中的不同元素并行计算函数
solveZeros
。函数如下所示:

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)])
函数解算零
"""
为S和返回中的每个元素求解线性方程的零
以参数k为键,以解决方案为项的字典
"""
结果=Dict{}()
对于S中的(a,b)
解=二等分(a,b)
结果[(a,b)]=溶液
结束
返回结果
结束
函数对分(a,b)
"""
使用二分法找到线性函数的根。a是斜率
b拦截
""" 
低,高=0100
而(高-低)>1E-2
中=低+(高-低)/2
如果abs(线性调整(a、b、mid))<1E-1
中途返回
其他线性参数(a、b、mid)>0
高=中
其他的
低=中
结束
结束
一无所获
结束
函数线性化(a、b、x)
返回a*x+b
结束
S=数组([(1.,-10),(1.,-20)])

有人能解释一下如何并行计算函数
solveZeros
?这是一个有效的例子。在我的实际计算中,函数
solveZero
bisect
linearquation
是从不同的模块中提取的。如何对这些函数进行相应的初始化以进行并行计算

未定义
表示您没有
@任何地方
其他地方所需的定义processes@ChrisRackauckas谢谢你的回复!你能建议一种使问题中的计算有效的方法吗?我只需要
@everywhere
正确的定义,并使用
pmap
@chrisrackaukas,因为我修改了问题并加入了一个有效的exmaple。你知道如何解决这个问题吗?你试过我说的吗
@everywhere
函数对分(a,b)
函数线性求值(a,b,x)
前面。然后,您可以将
函数solvezero
设置为
pmap
调用,而不是
for
循环。与其将值推入字典,不如让它返回
k=>v
的成对数组,并在该数组上调用
Dict
。如果明天没有解决方案,我会写一些东西,但没有比这更复杂的了。
没有定义
意味着你没有
@任何地方
其他地方需要的定义processes@ChrisRackauckas谢谢你的回复!你能建议一种使问题中的计算有效的方法吗?我只需要
@everywhere
正确的定义,并使用
pmap
@chrisrackaukas,因为我修改了问题并加入了一个有效的exmaple。你知道如何解决这个问题吗?你试过我说的吗
@everywhere
函数对分(a,b)
函数线性求值(a,b,x)
前面。然后,您可以将
函数solvezero
设置为
pmap
调用,而不是
for
循环。与其将值推入字典,不如让它返回
k=>v
的成对数组,并在该数组上调用
Dict
。如果明天没有解决办法,我会写一些东西,但没有比这更复杂的了。