Enforce cpus_per_task, ntasks_per_node and memory

Re-order existing code so that per-cpu memory limits will be
enforce with both cpus_per_task and ntasks_per_node limits.