Efficient and Programmable Machine Learning on Distributed Shared Memory via Static Analysis