Made gmxtest.pl rerunning of mdrun more structured

Since a test might require using only one rank after recent changes,
and the default number of OpenMP threads might be too many for a test
case, we need to make multiple attempts to find an mdrun configuration
that works.  Making that a function meant we no longer had to make
explicit local copies of the relevant control variables.

This fixes gmxtest.pl so you can run on a machine with many cores
without having to manually limit things.

Change-Id: I0612ddacf15dc06e752e56711fe09808e1997807