如何收集julia多线程运行后的计算结果

一、julia的多进程PMAP会自动返回计算的结果集,但是多线程则没有这个自动功能

#多进程的计算结果处理

results = pmap(fn,items)  #执行多进程,计算结构储存在results变量里面

for result in results   #计算结果逐个处理
      ......
end

二、多线程涉及原子操作,对于计算结果,如果直接定义一个list,用push!()来收集的话,你会发现收集到的结果集是混乱的,数量不足,这涉及到写的原子操作。

【1】如果每一次计算要输出大量数据,可以用IO操作,把数据存到本地,后续再读取进行处理
【2】如果每次计算要输出相同结构的数组(Array2),提前定义一个一维数组(result),数组的每一个值都是一个固定大小的数组(与Array2同形),多线程计算的时候,每个值经计算后,把计算结果数据写到result数组对应的序号位置里面。
【3】同理,当计算结果为dataframe时,我们提前定义一串dataframe组成的数组,每个线程计算完毕,回写计算结果到指定的地方,覆盖原来的dataframe。
【4】传值的时候,把输入包装成[index,value]的格式,处理完成后,直接回写计算结果到index位置的结果数组里面。

三、每一次的计算结果为一个array,用多线程进行多次计算,并收集计算结果,验证是否正确

using DataFrames

function my_fn(items)
    return (idx = items[1],ary = [items[1],items[2],items[2] * 6])
end

function test()
    a = rand(9000)  #输入1
    items = [[idx,item] for (idx,item) in zip(1:length(a),a)] #输入2
    result = [Array{Any}(undef,3) for i in 1:length(a)] #用于结果的保存
    
    items |> display
    result |> display
    
    Threads.@threads for x in items
    #for x in items
        res = my_fn(x)
        idx = round(Int64,res.idx)
        result[idx] = res.ary
    end
    
    result |> display
    df = DataFrame()
    df.a = a
    df[!,:a1] .= 0.0
    df[!,:a2] .= 0.0
    df[!,:a3] .= 0.0
    for (i,r) in zip(1:length(result),eachrow(df))
        r.a1 = result[i][1]
        r.a2 = result[i][2]
        r.a3 = result[i][3]
    end
    df |> display
    (df.a == df.a2)  |> display
end

test()

[out]

9000-element Array{Array{Float64,1},1}:
 [1.0, 0.070816232858125]
 [2.0, 0.7853029984149891]
 [3.0, 0.7210179200415938]
 [4.0, 0.6981532249270992]
 [5.0, 0.3480588007300216]
 [6.0, 0.9018409131741212]
 [7.0, 0.9751606776407826]
 [8.0, 0.9197465832681542]
 [9.0, 0.2259475070832464]
 [10.0, 0.20112552323415334]
 [11.0, 0.46591547485691565]
 [12.0, 0.5345097038593318]
 [13.0, 0.6768969926845438]
 ⋮
 [8989.0, 0.07825019863405136]
 [8990.0, 0.22229848459039636]
 [8991.0, 0.7785638083457678]
 [8992.0, 0.2849360457567198]
 [8993.0, 0.6758274067512697]
 [8994.0, 0.5370345216834027]
 [8995.0, 0.3360797278108958]
 [8996.0, 0.5362633226154412]
 [8997.0, 0.8545612885488223]
 [8998.0, 0.7897580081587134]
 [8999.0, 0.6986728663571047]
 [9000.0, 0.39289722732425036]
9000-element Array{Array{Any,1},1}:
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 ⋮
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
 [#undef, #undef, #undef]
9000-element Array{Array{Any,1},1}:
 [1.0, 0.070816232858125, 0.42489739714874997]
 [2.0, 0.7853029984149891, 4.711817990489934]
 [3.0, 0.7210179200415938, 4.326107520249563]
 [4.0, 0.6981532249270992, 4.188919349562595]
 [5.0, 0.3480588007300216, 2.0883528043801296]
 [6.0, 0.9018409131741212, 5.411045479044727]
 [7.0, 0.9751606776407826, 5.850964065844696]
 [8.0, 0.9197465832681542, 5.518479499608925]
 [9.0, 0.2259475070832464, 1.3556850424994784]
 [10.0, 0.20112552323415334, 1.20675313940492]
 [11.0, 0.46591547485691565, 2.795492849141494]
 [12.0, 0.5345097038593318, 3.207058223155991]
 [13.0, 0.6768969926845438, 4.0613819561072635]
 ⋮
 [8989.0, 0.07825019863405136, 0.46950119180430816]
 [8990.0, 0.22229848459039636, 1.3337909075423782]
 [8991.0, 0.7785638083457678, 4.671382850074607]
 [8992.0, 0.2849360457567198, 1.709616274540319]
 [8993.0, 0.6758274067512697, 4.054964440507618]
 [8994.0, 0.5370345216834027, 3.2222071301004163]
 [8995.0, 0.3360797278108958, 2.0164783668653747]
 [8996.0, 0.5362633226154412, 3.217579935692647]
 [8997.0, 0.8545612885488223, 5.127367731292933]
 [8998.0, 0.7897580081587134, 4.73854804895228]
 [8999.0, 0.6986728663571047, 4.1920371981426285]
 [9000.0, 0.39289722732425036, 2.357383363945502]
9,000 rows × 4 columns

a   a1  a2  a3
Float64 Float64 Float64 Float64
1   0.0708162   1.0 0.0708162   0.424897
2   0.785303    2.0 0.785303    4.71182
3   0.721018    3.0 0.721018    4.32611
4   0.698153    4.0 0.698153    4.18892
5   0.348059    5.0 0.348059    2.08835
6   0.901841    6.0 0.901841    5.41105
7   0.975161    7.0 0.975161    5.85096
8   0.919747    8.0 0.919747    5.51848
9   0.225948    9.0 0.225948    1.35569
10  0.201126    10.0    0.201126    1.20675
11  0.465915    11.0    0.465915    2.79549
12  0.53451 12.0    0.53451 3.20706
13  0.676897    13.0    0.676897    4.06138
14  0.547771    14.0    0.547771    3.28663
15  0.13939 15.0    0.13939 0.836339
16  0.665156    16.0    0.665156    3.99094
17  0.482515    17.0    0.482515    2.89509
18  0.619771    18.0    0.619771    3.71863
19  0.143206    19.0    0.143206    0.859238
20  0.814113    20.0    0.814113    4.88468
21  0.554832    21.0    0.554832    3.32899
22  0.837221    22.0    0.837221    5.02333
23  0.197084    23.0    0.197084    1.1825
24  0.204748    24.0    0.204748    1.22849
25  0.559978    25.0    0.559978    3.35987
26  0.09934 26.0    0.09934 0.59604
27  0.600058    27.0    0.600058    3.60035
28  0.16271 28.0    0.16271 0.976262
29  0.898825    29.0    0.898825    5.39295
30  0.266727    30.0    0.266727    1.60036
⋮   ⋮   ⋮   ⋮   ⋮
true

四、多线程,返回dataframe的收集,验证是否正确收集

using DataFrames
using Statistics

function my_fn(items)
    df = DataFrame()
    df[!,:id] = [items[1] for i in 1:10]
    df[!,:sum] .= sum(df.id)
    return (idx = items[1],df = df)
end

function test2()
    a = rand(500)  #输入1
    items = [[idx,item] for (idx,item) in zip(1:length(a),a)] #输入2
    result = [DataFrame() for i in 1:length(a)] #用于结果的保存
    
    items |> display
    result |> display
    
    Threads.@threads for x in items
    #for x in items
        res = my_fn(x)
        idx = round(Int64,res.idx)
        result[idx] = res.df
    end
    
    result
end

df = test2()

[out]

500-element Array{Array{Float64,1},1}:
 [1.0, 0.7141339538704334]
 [2.0, 0.2751614187241258]
 [3.0, 0.1276095685802059]
 [4.0, 0.7487211080799028]
 [5.0, 0.04502993862700588]
 [6.0, 0.5677883943419717]
 [7.0, 0.5153946483331102]
 [8.0, 0.27481996153220933]
 [9.0, 0.6156652757688648]
 [10.0, 0.20966088095430346]
 [11.0, 0.09966629409893724]
 [12.0, 0.21085954429893516]
 [13.0, 0.9787876607926493]
 ⋮
 [489.0, 0.4815375335767591]
 [490.0, 0.39904159650432214]
 [491.0, 0.01315641762397557]
 [492.0, 0.3227240777954996]
 [493.0, 0.5284580981245499]
 [494.0, 0.911554332297341]
 [495.0, 0.750858934405203]
 [496.0, 0.5565927834214723]
 [497.0, 0.19888221960592078]
 [498.0, 0.565409358573782]
 [499.0, 0.41314073181624766]
 [500.0, 0.6128912616155733]
500-element Array{DataFrame,1}:
 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 ⋮
 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame

 0×0 DataFrame
500-element Array{DataFrame,1}:
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 1.0     │ 10.0    │
│ 2   │ 1.0     │ 10.0    │
│ 3   │ 1.0     │ 10.0    │
│ 4   │ 1.0     │ 10.0    │
│ 5   │ 1.0     │ 10.0    │
│ 6   │ 1.0     │ 10.0    │
│ 7   │ 1.0     │ 10.0    │
│ 8   │ 1.0     │ 10.0    │
│ 9   │ 1.0     │ 10.0    │
│ 10  │ 1.0     │ 10.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 2.0     │ 20.0    │
│ 2   │ 2.0     │ 20.0    │
│ 3   │ 2.0     │ 20.0    │
│ 4   │ 2.0     │ 20.0    │
│ 5   │ 2.0     │ 20.0    │
│ 6   │ 2.0     │ 20.0    │
│ 7   │ 2.0     │ 20.0    │
│ 8   │ 2.0     │ 20.0    │
│ 9   │ 2.0     │ 20.0    │
│ 10  │ 2.0     │ 20.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 3.0     │ 30.0    │
│ 2   │ 3.0     │ 30.0    │
│ 3   │ 3.0     │ 30.0    │
│ 4   │ 3.0     │ 30.0    │
│ 5   │ 3.0     │ 30.0    │
│ 6   │ 3.0     │ 30.0    │
│ 7   │ 3.0     │ 30.0    │
│ 8   │ 3.0     │ 30.0    │
│ 9   │ 3.0     │ 30.0    │
│ 10  │ 3.0     │ 30.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 4.0     │ 40.0    │
│ 2   │ 4.0     │ 40.0    │
│ 3   │ 4.0     │ 40.0    │
│ 4   │ 4.0     │ 40.0    │
│ 5   │ 4.0     │ 40.0    │
│ 6   │ 4.0     │ 40.0    │
│ 7   │ 4.0     │ 40.0    │
│ 8   │ 4.0     │ 40.0    │
│ 9   │ 4.0     │ 40.0    │
│ 10  │ 4.0     │ 40.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 5.0     │ 50.0    │
│ 2   │ 5.0     │ 50.0    │
│ 3   │ 5.0     │ 50.0    │
│ 4   │ 5.0     │ 50.0    │
│ 5   │ 5.0     │ 50.0    │
│ 6   │ 5.0     │ 50.0    │
│ 7   │ 5.0     │ 50.0    │
│ 8   │ 5.0     │ 50.0    │
│ 9   │ 5.0     │ 50.0    │
│ 10  │ 5.0     │ 50.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 6.0     │ 60.0    │
│ 2   │ 6.0     │ 60.0    │
│ 3   │ 6.0     │ 60.0    │
│ 4   │ 6.0     │ 60.0    │
│ 5   │ 6.0     │ 60.0    │
│ 6   │ 6.0     │ 60.0    │
│ 7   │ 6.0     │ 60.0    │
│ 8   │ 6.0     │ 60.0    │
│ 9   │ 6.0     │ 60.0    │
│ 10  │ 6.0     │ 60.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 7.0     │ 70.0    │
│ 2   │ 7.0     │ 70.0    │
│ 3   │ 7.0     │ 70.0    │
│ 4   │ 7.0     │ 70.0    │
│ 5   │ 7.0     │ 70.0    │
│ 6   │ 7.0     │ 70.0    │
│ 7   │ 7.0     │ 70.0    │
│ 8   │ 7.0     │ 70.0    │
│ 9   │ 7.0     │ 70.0    │
│ 10  │ 7.0     │ 70.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 8.0     │ 80.0    │
│ 2   │ 8.0     │ 80.0    │
│ 3   │ 8.0     │ 80.0    │
│ 4   │ 8.0     │ 80.0    │
│ 5   │ 8.0     │ 80.0    │
│ 6   │ 8.0     │ 80.0    │
│ 7   │ 8.0     │ 80.0    │
│ 8   │ 8.0     │ 80.0    │
│ 9   │ 8.0     │ 80.0    │
│ 10  │ 8.0     │ 80.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 9.0     │ 90.0    │
│ 2   │ 9.0     │ 90.0    │
│ 3   │ 9.0     │ 90.0    │
│ 4   │ 9.0     │ 90.0    │
│ 5   │ 9.0     │ 90.0    │
│ 6   │ 9.0     │ 90.0    │
│ 7   │ 9.0     │ 90.0    │
│ 8   │ 9.0     │ 90.0    │
│ 9   │ 9.0     │ 90.0    │
│ 10  │ 9.0     │ 90.0    │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 10.0    │ 100.0   │
│ 2   │ 10.0    │ 100.0   │
│ 3   │ 10.0    │ 100.0   │
│ 4   │ 10.0    │ 100.0   │
│ 5   │ 10.0    │ 100.0   │
│ 6   │ 10.0    │ 100.0   │
│ 7   │ 10.0    │ 100.0   │
│ 8   │ 10.0    │ 100.0   │
│ 9   │ 10.0    │ 100.0   │
│ 10  │ 10.0    │ 100.0   │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 11.0    │ 110.0   │
│ 2   │ 11.0    │ 110.0   │
│ 3   │ 11.0    │ 110.0   │
│ 4   │ 11.0    │ 110.0   │
│ 5   │ 11.0    │ 110.0   │
│ 6   │ 11.0    │ 110.0   │
│ 7   │ 11.0    │ 110.0   │
│ 8   │ 11.0    │ 110.0   │
│ 9   │ 11.0    │ 110.0   │
│ 10  │ 11.0    │ 110.0   │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 12.0    │ 120.0   │
│ 2   │ 12.0    │ 120.0   │
│ 3   │ 12.0    │ 120.0   │
│ 4   │ 12.0    │ 120.0   │
│ 5   │ 12.0    │ 120.0   │
│ 6   │ 12.0    │ 120.0   │
│ 7   │ 12.0    │ 120.0   │
│ 8   │ 12.0    │ 120.0   │
│ 9   │ 12.0    │ 120.0   │
│ 10  │ 12.0    │ 120.0   │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 13.0    │ 130.0   │
│ 2   │ 13.0    │ 130.0   │
│ 3   │ 13.0    │ 130.0   │
│ 4   │ 13.0    │ 130.0   │
│ 5   │ 13.0    │ 130.0   │
│ 6   │ 13.0    │ 130.0   │
│ 7   │ 13.0    │ 130.0   │
│ 8   │ 13.0    │ 130.0   │
│ 9   │ 13.0    │ 130.0   │
│ 10  │ 13.0    │ 130.0   │
 ⋮
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 489.0   │ 4890.0  │
│ 2   │ 489.0   │ 4890.0  │
│ 3   │ 489.0   │ 4890.0  │
│ 4   │ 489.0   │ 4890.0  │
│ 5   │ 489.0   │ 4890.0  │
│ 6   │ 489.0   │ 4890.0  │
│ 7   │ 489.0   │ 4890.0  │
│ 8   │ 489.0   │ 4890.0  │
│ 9   │ 489.0   │ 4890.0  │
│ 10  │ 489.0   │ 4890.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 490.0   │ 4900.0  │
│ 2   │ 490.0   │ 4900.0  │
│ 3   │ 490.0   │ 4900.0  │
│ 4   │ 490.0   │ 4900.0  │
│ 5   │ 490.0   │ 4900.0  │
│ 6   │ 490.0   │ 4900.0  │
│ 7   │ 490.0   │ 4900.0  │
│ 8   │ 490.0   │ 4900.0  │
│ 9   │ 490.0   │ 4900.0  │
│ 10  │ 490.0   │ 4900.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 491.0   │ 4910.0  │
│ 2   │ 491.0   │ 4910.0  │
│ 3   │ 491.0   │ 4910.0  │
│ 4   │ 491.0   │ 4910.0  │
│ 5   │ 491.0   │ 4910.0  │
│ 6   │ 491.0   │ 4910.0  │
│ 7   │ 491.0   │ 4910.0  │
│ 8   │ 491.0   │ 4910.0  │
│ 9   │ 491.0   │ 4910.0  │
│ 10  │ 491.0   │ 4910.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 492.0   │ 4920.0  │
│ 2   │ 492.0   │ 4920.0  │
│ 3   │ 492.0   │ 4920.0  │
│ 4   │ 492.0   │ 4920.0  │
│ 5   │ 492.0   │ 4920.0  │
│ 6   │ 492.0   │ 4920.0  │
│ 7   │ 492.0   │ 4920.0  │
│ 8   │ 492.0   │ 4920.0  │
│ 9   │ 492.0   │ 4920.0  │
│ 10  │ 492.0   │ 4920.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 493.0   │ 4930.0  │
│ 2   │ 493.0   │ 4930.0  │
│ 3   │ 493.0   │ 4930.0  │
│ 4   │ 493.0   │ 4930.0  │
│ 5   │ 493.0   │ 4930.0  │
│ 6   │ 493.0   │ 4930.0  │
│ 7   │ 493.0   │ 4930.0  │
│ 8   │ 493.0   │ 4930.0  │
│ 9   │ 493.0   │ 4930.0  │
│ 10  │ 493.0   │ 4930.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 494.0   │ 4940.0  │
│ 2   │ 494.0   │ 4940.0  │
│ 3   │ 494.0   │ 4940.0  │
│ 4   │ 494.0   │ 4940.0  │
│ 5   │ 494.0   │ 4940.0  │
│ 6   │ 494.0   │ 4940.0  │
│ 7   │ 494.0   │ 4940.0  │
│ 8   │ 494.0   │ 4940.0  │
│ 9   │ 494.0   │ 4940.0  │
│ 10  │ 494.0   │ 4940.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 495.0   │ 4950.0  │
│ 2   │ 495.0   │ 4950.0  │
│ 3   │ 495.0   │ 4950.0  │
│ 4   │ 495.0   │ 4950.0  │
│ 5   │ 495.0   │ 4950.0  │
│ 6   │ 495.0   │ 4950.0  │
│ 7   │ 495.0   │ 4950.0  │
│ 8   │ 495.0   │ 4950.0  │
│ 9   │ 495.0   │ 4950.0  │
│ 10  │ 495.0   │ 4950.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 496.0   │ 4960.0  │
│ 2   │ 496.0   │ 4960.0  │
│ 3   │ 496.0   │ 4960.0  │
│ 4   │ 496.0   │ 4960.0  │
│ 5   │ 496.0   │ 4960.0  │
│ 6   │ 496.0   │ 4960.0  │
│ 7   │ 496.0   │ 4960.0  │
│ 8   │ 496.0   │ 4960.0  │
│ 9   │ 496.0   │ 4960.0  │
│ 10  │ 496.0   │ 4960.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 497.0   │ 4970.0  │
│ 2   │ 497.0   │ 4970.0  │
│ 3   │ 497.0   │ 4970.0  │
│ 4   │ 497.0   │ 4970.0  │
│ 5   │ 497.0   │ 4970.0  │
│ 6   │ 497.0   │ 4970.0  │
│ 7   │ 497.0   │ 4970.0  │
│ 8   │ 497.0   │ 4970.0  │
│ 9   │ 497.0   │ 4970.0  │
│ 10  │ 497.0   │ 4970.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 498.0   │ 4980.0  │
│ 2   │ 498.0   │ 4980.0  │
│ 3   │ 498.0   │ 4980.0  │
│ 4   │ 498.0   │ 4980.0  │
│ 5   │ 498.0   │ 4980.0  │
│ 6   │ 498.0   │ 4980.0  │
│ 7   │ 498.0   │ 4980.0  │
│ 8   │ 498.0   │ 4980.0  │
│ 9   │ 498.0   │ 4980.0  │
│ 10  │ 498.0   │ 4980.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 499.0   │ 4990.0  │
│ 2   │ 499.0   │ 4990.0  │
│ 3   │ 499.0   │ 4990.0  │
│ 4   │ 499.0   │ 4990.0  │
│ 5   │ 499.0   │ 4990.0  │
│ 6   │ 499.0   │ 4990.0  │
│ 7   │ 499.0   │ 4990.0  │
│ 8   │ 499.0   │ 4990.0  │
│ 9   │ 499.0   │ 4990.0  │
│ 10  │ 499.0   │ 4990.0  │
 10×2 DataFrame
│ Row │ id      │ sum     │
│     │ Float64 │ Float64 │
├─────┼─────────┼─────────┤
│ 1   │ 500.0   │ 5000.0  │
│ 2   │ 500.0   │ 5000.0  │
│ 3   │ 500.0   │ 5000.0  │
│ 4   │ 500.0   │ 5000.0  │
│ 5   │ 500.0   │ 5000.0  │
│ 6   │ 500.0   │ 5000.0  │
│ 7   │ 500.0   │ 5000.0  │
│ 8   │ 500.0   │ 5000.0  │
│ 9   │ 500.0   │ 5000.0  │
│ 10  │ 500.0   │ 5000.0  │

验证收集到的结果

for (idx,item) in zip(1:length(df),df)
    println("====")
    begin idx - item[1,:id] end |> println    
end
println("输出0.0则为计算正确,序号对得上")

[out]

====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
====
0.0
输出0.0则为计算正确,序号对得上

【遇到的问题】
在线程中调用pycall引入的numpy,talib等包的函数时,直接死机,不知道什么原因,talib和numpy应该用到多线程,不知道具体什么原因,以后查资料看吧。

你可能感兴趣的:(如何收集julia多线程运行后的计算结果)