Skip to content

Commit 63872c6

Browse files
fix SplitThreads indexnig
1 parent 173b3df commit 63872c6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/ensemble/basic_ensemble_solve.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,26 @@ end
182182

183183
function solve_batch(prob,alg,::EnsembleSplitThreads,I,pmap_batch_size,kwargs...)
184184
wp=CachingPool(workers())
185+
N = nworkers()
186+
batch_size = length(I)÷N
185187
batch_data = let
186-
pmap(wp,1:nprocs(),batch_size=pmap_batch_size) do i
187-
thread_monte(prob,I,alg,i,kwargs...)
188+
pmap(wp,1:N,batch_size=pmap_batch_size) do i
189+
if i == N
190+
I_local = I[(batch_size*(i-1)+1):end]
191+
else
192+
I_local = I[(batch_size*(i-1)+1):(batch_size*i)]
193+
end
194+
thread_monte(prob,I_local,alg,i,kwargs...)
188195
end
189196
end
190197
_batch_data = vector_batch_data_to_arr(batch_data)
191198
end
192199

193200
function thread_monte(prob,I,alg,procid,kwargs...)
194-
start = I[1]+(procid-1)*length(I)
195-
stop = I[1]+procid*length(I)-1
196-
portion = start:stop
197-
batch_data = Vector{Any}(undef,length(portion))
201+
batch_data = Vector{Any}(undef,length(I))
202+
@show I
198203
let
199-
Threads.@threads for i in portion
204+
Threads.@threads for i in I
200205
iter = 1
201206
new_prob = prob.prob_func(deepcopy(prob.prob),i,iter)
202207
rerun = true

0 commit comments

Comments
 (0)