@@ -26,6 +26,30 @@ namespace pfasst
2626 */
2727 namespace config
2828 {
29+ /* *
30+ * Get MPI rank during initialization.
31+ *
32+ * When running without MPI (ie, without using mpirun/mpiexec), returns 0. When running with
33+ * MPI, returns the MPI rank.
34+ *
35+ * If the user is running with MPI and MPI_Init hasn't been called yet, this will return 0. I
36+ * hope this is rare.
37+ */
38+ int get_rank ()
39+ {
40+ #ifdef WITH_MPI
41+ int initialized = 0 , rank = 0 ;
42+ // if we're not running under "mpirun/mpiexec", just assume rank 0.
43+ MPI_Initialized (&initialized);
44+ if (initialized) {
45+ MPI_Comm_rank (MPI_COMM_WORLD, &rank);
46+ }
47+ return rank;
48+ #else
49+ return 0 ;
50+ #endif
51+ }
52+
2953 /* *
3054 * Runtime config options provider.
3155 *
@@ -76,7 +100,7 @@ namespace pfasst
76100 * @param[in] option Name of the command line parameter.
77101 * It is possible to specify a long and optional short option name by comma-separation.
78102 * Short option names are identified by being only a single character.
79- * They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
103+ * They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
80104 * to '`--[LONG]`'.
81105 * @param[in] help help text to be displayed in the help and usage information
82106 */
@@ -90,7 +114,7 @@ namespace pfasst
90114 * @param[in] option Name of the command line parameter.
91115 * It is possible to specify a long and optional short option name by comma-separation.
92116 * Short option names are identified by being only a single character.
93- * They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
117+ * They are automatically parsed as '`-[SHORT]`' by `boost::program_options` in contrast
94118 * to '`--[LONG]`'.
95119 * @param[in] help help text to be displayed in the help and usage information
96120 *
@@ -193,21 +217,11 @@ namespace pfasst
193217 po::store (parsed, options::get_instance ().get_variables_map ());
194218 po::notify (options::get_instance ().get_variables_map ());
195219
196- #ifdef WITH_MPI
197- int initialized = 0 ;
198- MPI_Initialized (&initialized);
199- assert ((bool )initialized);
200- int rank = 0 ;
201- MPI_Comm_rank (MPI_COMM_WORLD, &rank);
202- #endif
203220 if (options::get_instance ().get_variables_map ().count (" help" )) {
204- #ifdef WITH_MPI
205- if (rank == 0 ) {
206- #endif
221+ if (get_rank () == 0 ) {
207222 cout << print_help () << endl;
208- #ifdef WITH_MPI
209223 }
210- # endif
224+
211225 if (exit_on_help) {
212226#ifdef WITH_MPI
213227 MPI_Finalize ();
@@ -263,7 +277,7 @@ namespace pfasst
263277 options::add_option<double >(" Duration" , " tend" , " final time of simulation" );
264278 options::add_option<size_t >(" Duration" , " num_steps" , " number time steps" );
265279 options::add_option<size_t >(" Duration" , " num_iter" , " number of iterations" );
266-
280+
267281 options::add_option<size_t >(" Quadrature" , " num_nodes" , " number of quadrature nodes" );
268282
269283 options::add_option<double >(" Tolerances" , " abs_res_tol" , " absolute residual tolerance" );
0 commit comments