Manchester United midfielder Michael Carrick has announced he will retire from playing at the end of the season.