Closed VOD555 closed 6 years ago
We should have a separate function that figures out how the trajectory is split. Then we can call this function. We can also test this function separately.
Maybe there's a simple algebraic way to do it. Otherwise I would do for
M
trajectory frames in the trajectoryN
processes0 ≤ i N-1
process numberm[i]
number of frames for process i
m[i] = M // N # initial frames for block i
r = M % N # remaining frames 0 ≤ r < N
for i in range(r):
m[i] += 1 # distribute the remaining frames over the first r blocks
which can be written more succinctly as
m = np.ones(N) * M//N
m += (np.arange(N) < M%N)
For the M=5
, N=4
example this should give m = [2, 1, 1, 1]
.
Expected behaviour
Each block should be assigned trajectories.
Actual behaviour
Fail to assign trajectory to the last block when the number of total frames meets some condition.
Code to reproduce the behaviour
Whre
XTC_MEMPROT
is a trajectory which has 5 frames. It works when n= 1,2,3. If n=4, it will give an error:Which is caused by the empty list returned from the last block.
To explain why the result from the last block is empty, we should first look at
parallel.py
. The lengh of the trajectory assigned to each block is determined bybsize = int(np.ceil(n_frames / float(n_blocks)))
.If n_frames=5 and n_blocks=4, bsize=2, and the four blocks will be assiged 2, 2 , 1, 0 frames. No frame is assigned to the last one.
This issue happens when (a-1)n_blocks < n_frames <= a(n_blocks-1) for all possitive integer a < n_blocks.