function [u,res]=MG_OC(A,f,nu,u,ell,tol,m)
% MG_OC: Multigrid for Laplace-type optimal control problems
%   [u,res]=MG_OC(A,f,nu,u,ell,tol,m) solves the first-order
%   optimality system written in the form Au=f of an l2-regularized
%   (with regularization parameter nu) optimal control problems. It
%   performs at most m V-cycles of a multigrid methods with ell levels
%   until the norm of the residual smaller than the tolerance tol.
%   The output variables are the computed solution u and the vector
%   res, containing the history of the residual norms.

res(1)=norm(f-A*u);
k=0;
while k<=m && res(end)>tol
  k=k+1;
  u=VCycleOC(A,f,nu,u,ell);
  res(k)=norm(f-A*u);
end