Distributed optimization for control and learning