job_coordinator: improve the check for the end of a stage
job_coordinator: add the last_stage_task call to the can_finish

Previously, we were using the 'and' operator which does not short-circuit and
evaluates the (potentially expensive) last_stage_task function.
With this commit, we only call this function when there is no running tasks.
job_coordinator: combine the maybe_submit_tasks call and get_grouping_lists

It will be named submit_concurrent_tasks.
job_coordinator: avoid extra tries to submit tasks for non-concurrent stages

When a stage is not concurrent, we do not want the extra overhead of creating
the inputs and create the pending tasks. Instead, we'd like to wait until the
stage finishes and then create the tasks of the next stage.
Merge pull request #564 from pooya/jc_perf

Improve the performance of job coordinator