Block stochastic gradient iteration for convex and nonconvex optimization