Discretize and optimize approaches for PDE-based optimization problems