Partition-Merge: Distributed Inference and Modularity Optimization