Millions of people have cast ballots in snap general election called by Prime Minister Pedro Sanchez.