A General Theory of Optimal p-Cyclic SOR