You guys are misunderstanding the ending...
You guys are misunderstanding the ending.
It's not about making the movie darker or more tragic just for the sake of it.
The ending is didactic. Meaning, it has a very explicit message it wants to impart to the viewer.
And that message is, "Never give up. Because the light at the end of the tunnel may be right around the corner."
It's essentially an uplifting message which is delivered to us through a horrible tragedy. If only David had held out hope for just a minute longer, everyone would have been saved.
The fact that he felt there was only one solution to the problem (killing everyone to spare them) was the cause of the tragedy. In essence, the movie is anti-suicide and implies that an end to misery and new beginning of happiness exists if one is strong enough to hold out for it.
I don't see how so many of you missed this...