The job is to convert the values from the src array and write the new values to the dst array.
When I create ForkJoinTasks in a while loop
val height: Int = 4;
val numTasks: Int = 2;
var tasks = scala.collection.mutable.ListBuffer.empty[ForkJoinTask[Unit]]
val jump: Int = src.height / numTasks
var from: Int = 0;
while (from < height) {
val end: Int = height.min(from + jump);
val t: ForkJoinTask[Unit] = task {
run(src, dst, from, end) // (2,2), (2,1), what is happening?
}
from = end
}
for (t <- tasks.toList) {
t.join()
}
Then strangely, the run function takes the (from, end) arguments value as (2, 2). But If I split it manually into two tasks, then it works normally, as (0,1) and (1,2).
val t1 = task {
run(src, dst, 0, height / 2); // (0, 1)
}
val t2 = task {
run(src, dst, height / 2, height); // (1, 2)
}
t1.join()
t2.join()
I am having hard time to figure out what is going on. This is my very first Scala program, so I might be missing something very trivial. Any comment would be appreciated.
Thank you.