improve #462 and #417

merged three all_reduce into a single one