Restaurant recommendations in Madrid, Barcelona, Lisbon
For Barcelona, I would search the board for the many posts that have recommendations for all types of eating places from tapas/pintxos, everyday simple places, traditional as well as modern Catalan restaurants. Most tapas and pintxos places will be opened in August. Many tradtional and modern Catalan restaurants will be closed parts of August (generally 2 to 3 weeks). My advice is to make a list of places that will interest you, then do a search on the internet if they are open when you are there. Or best telephone the restaurant on those that really interest you. There is no easy way as exact closing changes year to year. Another option is if you are staying in a hotel, have the concierge help you.
Madrid is very, very rough the last two weeks of August (the first two weeks are a bit better). You don't say anything about the types of places you are interested in visiting, but you will find some tapas bars and terrazas open--particularly in touristed areas--also hotel restaurants. The good thing is that half the city is gone and you don't have to compete for a table or a spot at the bar. When I stay in town at this time of year, I don't try to go anywhere out of my way without calling and checking to see if they are open first.
I would imagine that the Mercado de San Miguel will stay open. So that's one decent option.