Out on the road its a mixture. But first, are you able to measure your cadence?
I use this as my guide (i.e. I try and keep my cadence within a certain range no matter what the gradient) - if I am able to pedal comfortably at over 80rpm, then its time to change to a bigger gear. If I'm unable to pedal comfortably at 65rpm, its time to go to a smaller gear.
That's my scientific approach. Alternatively, when it starts hurting I change down, and when it feels too easy I change up. But again I'm trying to maintain a constant-ish cadence. Climbing hills obviously takes it out of you as you're climbing them but generally speaking it should only be a short while (minutes) after you've passed the summit before you're able to pedal as normal.
But over that kind of distance you'll need to take your nutrition seriously - keeping your energy levels up will be to key to allowing you to control your cadence.