cg_m added, template structure changed for linear solver