Remove short-circuit logic for OpenMP setup
authorMark Abraham <mark.j.abraham@gmail.com>
Tue, 26 Oct 2021 15:00:26 +0000 (15:00 +0000)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 26 Oct 2021 15:00:26 +0000 (15:00 +0000)
This is only called once during mdrun setup, and it is not a problem
to call it multiple times. (Thread safety is assured separately.)
It's necessary to call it multiple times, e.g. from test binaries or
API-driven simulations.

Having removed the short-circuit logic, there was no use for the
member variable that recorded whether initialization had taken place,
so it is removed.

Closes #4152

src/gromacs/mdlib/gmx_omp_nthreads.cpp
src/gromacs/mdlib/gmx_omp_nthreads.h

index 91c72b198ae66334547acf63d9f1e0bcabe142c0..44d0f79ed4935e85b1ddf1a8737fc00aac35441b 100644 (file)
@@ -62,7 +62,6 @@ typedef struct
     int gnth_pme; /**< Global num. of threads per PME only process/tMPI thread. */
 
     gmx::EnumerationArray<ModuleMultiThread, int> nth; /**< Number of threads for each module, indexed with module_nth_t */
-    bool initialized; /**< TRUE if the module as been initialized. */
 } omp_module_nthreads_t;
 
 /** Names of environment variables to set the per module number of threads.
@@ -108,7 +107,7 @@ static const char* enumValueToString(ModuleMultiThread enumValue)
  *  the init call is omitted.
  * */
 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
-static omp_module_nthreads_t modth = { 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, FALSE };
+static omp_module_nthreads_t modth = { 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
 
 
 /** Determine the number of threads for module \p mod.
@@ -260,14 +259,6 @@ static void manage_number_of_openmp_threads(const gmx::MDLogger& mdlog,
     GMX_UNUSED_VALUE(cr);
 #endif
 
-    if (modth.initialized)
-    {
-        /* Just return if the initialization has already been
-           done. This could only happen if gmx_omp_nthreads_init() has
-           already been called. */
-        return;
-    }
-
     /* With full OpenMP support (verlet scheme) set the number of threads
      * per process / default:
      * - 1 if not compiled with OpenMP or
@@ -374,8 +365,6 @@ static void manage_number_of_openmp_threads(const gmx::MDLogger& mdlog,
             gmx_omp_set_num_threads(nth);
         }
     }
-
-    modth.initialized = TRUE;
 }
 
 /*! \brief Report on the OpenMP settings that will be used */
index 1b87c113b65e72d4956288807bed00c039074895..6a140679b32a64caecaa7ea35e95c49f860c940d 100644 (file)
@@ -71,7 +71,7 @@ enum class ModuleMultiThread : int
  *
  * It is compatible with tMPI, thread-safety is ensured (for the features
  * available with tMPI).
- * This function should caled only once during the initialization of mdrun. */
+ * This function should be called only once during the initialization of mdrun. */
 void gmx_omp_nthreads_init(const gmx::MDLogger& fplog,
                            t_commrec*           cr,
                            int                  nthreads_hw_avail,