let split job pid goals =
let n = Bag.length goals in
if n <= 1 then Bag.iter (job pid) goals else
let k = ref 0 in
Bag.iter
(fun g ->
let pid_k = { pid with p_part = Some(!k,n) } in
incr k ; job pid_k g)
goals