The implementation here is really hard to understand. It seems to me that you need 

~~~
SparkContext#runJob[T, U: ClassTag](rdd: RDD[T], func: Iterator[T] => U): Array[U]
~~~

to get the sum per partition, then compute partition-wise cumsum on the master, then each partition knows the number to start. Maybe I understand this block wrongly.