In [ ]:
function parallel(nproc, seed)
srand(seed)
addprocs(nproc)
initialvalues = randn(273, nproc)
@everywhere include(“preparation.jl”)
@everywhere include(“bayes.jl”)
@everywhere include(“loglike.jl”)
estparam = Array(Float64, 273, nproc)
likelihood = Array(Float64, 1, nproc)
result = Array(Any, nproc, 1)
for i in 1:nproc
result[i, 1] = remotecall(optimize, i, loglike, initialvalues[:, i], BFGS())
end
for j in 1:nproc
z = fetch(result[j, 1])
estparam[:, j] = Optim.minimizer(z)
likelihood[1, j] = Optim.minimum(z)
end
writetable(*("estparam", "_$seed", ".txt"), estparam)
writetable(*("likelihood", "_$seed", ".txt"), likelihood)
end
In [8]:
seed = 1
nproc = 2
srand(seed)
initialvalues = randn(273, nproc)
writetable(*("initialvalue", "_$seed", ".txt"), DataFrame(initialvalues))
In [77]:
for i in 1:3
println(*("$i", "a"))
end
In [1]:
using DataFrames
In [4]:
q = DataFrame(randn(2,3))
writetable(*("kei", ".txt"), q)
In [5]:
w = 1
typeof(*("kei","_$w", ".txt"))
Out[5]:
In [79]:
a = readtable("kei.txt")
Out[79]:
In [80]:
Array(a[:, 1])
Out[80]:
In [50]:
a = Array(Any, 3,1)
for i in 1:3
a[i, 1] = remotecall(f, i, i)
end
In [53]:
fetch(a[3,1])
Out[53]:
In [47]:
*("z", "1") =
In [27]:
function f(x)
return (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2
end
Out[27]:
In [30]:
using Optim
result = optimize(f, [0.0, 0.0])
Out[30]:
In [40]:
likelihood = Array(Float64, 1, 3)[1, 2]
Out[40]:
In [35]:
a = Array(Float64, 2, 2)
Out[35]:
In [36]:
a[:, 1] = Optim.minimizer(result)
Out[36]:
In [37]:
a
Out[37]:
In [34]:
Optim.minimum(result)
Out[34]:
In [22]:
a = randn((2,3))
Out[22]:
In [26]:
Array((2,3))
In [24]:
for i in 1:3
println(i)
end
In [23]:
a[:, 2]
Out[23]:
In [41]:
@everywhere function f(x)
return 2*x
end
In [1]:
# ワーカープロセスの追加
# 要するに1はマスタープロセスか
addprocs(2)
Out[1]:
In [43]:
f1 = remotecall(2, f, 3)
Out[43]:
In [44]:
fetch(f1)
Out[44]:
In [8]:
srand(123)
Out[8]:
In [9]:
r1 = remotecall(rand, 1, 2, 2)
Out[9]:
In [10]:
r2 = remotecall(rand, 2, 2, 2)
Out[10]:
In [11]:
r3 = remotecall(rand, 3, 2, 2)
Out[11]:
In [12]:
# ワーカープロセスの数を超えちゃってるから出ない。
r4 = remotecall(rand, 4, 2, 2)
In [13]:
fetch(r1)
Out[13]:
In [14]:
fetch(r2)
Out[14]:
In [15]:
fetch(r3)
Out[15]:
In [18]:
z = @spawnat 2 f(3)
Out[18]:
In [19]:
fetch(z)
Out[19]:
In [20]:
z2 = @spawnat 3 f(3)
fetch(z2)
Out[20]:
In [ ]: