more robust ranks_per_node calculation