The sfLapply
function is useful because it splits up the input values into one group of tasks for each available worker, which is what the mclapply
function calls prescheduling. This can give much better performance than sfClusterApplyLB
when the tasks don't take long.
Here's an extreme example that demonstrates the advantages of prescheduling:
> system.time(sfLapply(1:100000, sqrt))
user system elapsed
0.148 0.004 0.170
> system.time(sfClusterApplyLB(1:100000, sqrt))
user system elapsed
19.317 1.852 21.222