Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / mdlib / gmx_omp_nthreads.cpp
index b2a0e46066fb8916675c1fb1c2a2ce9f3bf3a062..6ae2e122ff49fc04a425496b68c8bcee476f3623 100644 (file)
  *  algorithmic module in mdrun. */
 typedef struct
 {
-    int      gnth;          /**< Global num. of threads per PP or PP+PME process/tMPI thread. */
-    int      gnth_pme;      /**< Global num. of threads per PME only process/tMPI thread. */
+    int gnth;     /**< Global num. of threads per PP or PP+PME process/tMPI thread. */
+    int gnth_pme; /**< Global num. of threads per PME only process/tMPI thread. */
 
-    int      nth[emntNR];   /**< Number of threads for each module, indexed with module_nth_t */
-    gmx_bool initialized;   /**< TRUE if the module as been initialized. */
+    int      nth[emntNR]; /**< Number of threads for each module, indexed with module_nth_t */
+    gmx_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.
  *
  *  Indexed with the values of module_nth_t.
  * */
-static const char *modth_env_var[emntNR] =
-{
-    "GMX_DEFAULT_NUM_THREADS should never be set",
-    "GMX_DOMDEC_NUM_THREADS", "GMX_PAIRSEARCH_NUM_THREADS",
-    "GMX_NONBONDED_NUM_THREADS", "GMX_LISTED_FORCES_NUM_THREADS",
-    "GMX_PME_NUM_THREADS", "GMX_UPDATE_NUM_THREADS",
-    "GMX_VSITE_NUM_THREADS",
-    "GMX_LINCS_NUM_THREADS", "GMX_SETTLE_NUM_THREADS"
-};
+static const char* modth_env_var[emntNR] = { "GMX_DEFAULT_NUM_THREADS should never be set",
+                                             "GMX_DOMDEC_NUM_THREADS",
+                                             "GMX_PAIRSEARCH_NUM_THREADS",
+                                             "GMX_NONBONDED_NUM_THREADS",
+                                             "GMX_LISTED_FORCES_NUM_THREADS",
+                                             "GMX_PME_NUM_THREADS",
+                                             "GMX_UPDATE_NUM_THREADS",
+                                             "GMX_VSITE_NUM_THREADS",
+                                             "GMX_LINCS_NUM_THREADS",
+                                             "GMX_SETTLE_NUM_THREADS" };
 
 /** Names of the modules. */
-static const char *mod_name[emntNR] =
-{
-    "default", "domain decomposition", "pair search", "non-bonded",
-    "bonded", "PME", "update", "LINCS", "SETTLE"
-};
+static const char* mod_name[emntNR] = { "default",     "domain decomposition",
+                                        "pair search", "non-bonded",
+                                        "bonded",      "PME",
+                                        "update",      "LINCS",
+                                        "SETTLE" };
 
 /** Number of threads for each algorithmic module.
  *
@@ -92,7 +93,7 @@ static const char *mod_name[emntNR] =
  *  All fields are initialized to 0 which should result in errors if
  *  the init call is omitted.
  * */
-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 }, FALSE };
 
 
 /** Determine the number of threads for module \p mod.
@@ -104,11 +105,10 @@ static omp_module_nthreads_t modth = { 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0}, FALSE}
  *  GMX_*_NUM_THERADS env var is set, case in which its value overrides
  *  the default.
  */
-static void pick_module_nthreads(const gmx::MDLogger &mdlog, int m,
-                                 gmx_bool bSepPME)
+static void pick_module_nthreads(const gmx::MDLogger& mdlog, int m, gmx_bool bSepPME)
 {
-    char      *env;
-    int        nth;
+    charenv;
+    int   nth;
 
     const bool bOMP = GMX_OPENMP;
 
@@ -126,8 +126,7 @@ static void pick_module_nthreads(const gmx::MDLogger &mdlog, int m,
 
         if (!bOMP)
         {
-            gmx_warning("%s=%d is set, but %s is compiled without OpenMP!",
-                        modth_env_var[m], nth,
+            gmx_warning("%s=%d is set, but %s is compiled without OpenMP!", modth_env_var[m], nth,
                         gmx::getProgramContext().displayName());
         }
 
@@ -135,17 +134,19 @@ static void pick_module_nthreads(const gmx::MDLogger &mdlog, int m,
          * OMP_NUM_THREADS also has to be set */
         if (getenv("OMP_NUM_THREADS") == nullptr)
         {
-            gmx_warning("%s=%d is set, the default number of threads also "
-                        "needs to be set with OMP_NUM_THREADS!",
-                        modth_env_var[m], nth);
+            gmx_warning(
+                    "%s=%d is set, the default number of threads also "
+                    "needs to be set with OMP_NUM_THREADS!",
+                    modth_env_var[m], nth);
         }
 
         /* only babble if we are really overriding with a different value */
         if ((bSepPME && m == emntPME && nth != modth.gnth_pme) || (nth != modth.gnth))
         {
-            GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted(
-                    "%s=%d set, overriding the default number of %s threads",
-                    modth_env_var[m], nth, mod_name[m]);
+            GMX_LOG(mdlog.warning)
+                    .asParagraph()
+                    .appendTextFormatted("%s=%d set, overriding the default number of %s threads",
+                                         modth_env_var[m], nth, mod_name[m]);
         }
     }
     else
@@ -158,10 +159,9 @@ static void pick_module_nthreads(const gmx::MDLogger &mdlog, int m,
     gmx_omp_nthreads_set(m, nth);
 }
 
-void gmx_omp_nthreads_read_env(const gmx::MDLogger &mdlog,
-                               int                 *nthreads_omp)
+void gmx_omp_nthreads_read_env(const gmx::MDLogger& mdlog, int* nthreads_omp)
 {
-    char    *env;
+    char*    env;
     gmx_bool bCommandLineSetNthreadsOMP = *nthreads_omp > 0;
     char     buffer[STRLEN];
 
@@ -179,7 +179,11 @@ void gmx_omp_nthreads_read_env(const gmx::MDLogger &mdlog,
 
         if (bCommandLineSetNthreadsOMP && nt_omp != *nthreads_omp)
         {
-            gmx_fatal(FARGS, "Environment variable OMP_NUM_THREADS (%d) and the number of threads requested on the command line (%d) have different values. Either omit one, or set them both to the same value.", nt_omp, *nthreads_omp);
+            gmx_fatal(FARGS,
+                      "Environment variable OMP_NUM_THREADS (%d) and the number of threads "
+                      "requested on the command line (%d) have different values. Either omit one, "
+                      "or set them both to the same value.",
+                      nt_omp, *nthreads_omp);
         }
 
         /* Setting the number of OpenMP threads. */
@@ -187,7 +191,8 @@ void gmx_omp_nthreads_read_env(const gmx::MDLogger &mdlog,
 
         /* Output the results */
         sprintf(buffer,
-                "\nThe number of OpenMP threads was set by environment variable OMP_NUM_THREADS to %d%s\n\n",
+                "\nThe number of OpenMP threads was set by environment variable OMP_NUM_THREADS to "
+                "%d%s\n\n",
                 nt_omp,
                 bCommandLineSetNthreadsOMP ? " (and the command-line setting agreed with that)" : "");
 
@@ -208,18 +213,18 @@ void gmx_omp_nthreads_read_env(const gmx::MDLogger &mdlog,
 /*! \brief Helper function for parsing various input about the number
     of OpenMP threads to use in various modules and deciding what to
     do about it. */
-static void manage_number_of_openmp_threads(const gmx::MDLogger &mdlog,
-                                            const t_commrec     *cr,
+static void manage_number_of_openmp_threads(const gmx::MDLoggermdlog,
+                                            const t_commrec*     cr,
                                             bool                 bOMP,
                                             int                  nthreads_hw_avail,
                                             int                  omp_nthreads_req,
                                             int                  omp_nthreads_pme_req,
-                                            gmx_bool gmx_unused  bThisNodePMEOnly,
-                                            int                  numRanksOnThisNode,
-                                            gmx_bool             bSepPME)
+                                            gmx_bool gmx_unused bThisNodePMEOnly,
+                                            int                 numRanksOnThisNode,
+                                            gmx_bool            bSepPME)
 {
-    int      nth;
-    char    *env;
+    int   nth;
+    charenv;
 
 #if GMX_THREAD_MPI
     /* modth is shared among tMPI threads, so for thread safety, the
@@ -343,7 +348,7 @@ static void manage_number_of_openmp_threads(const gmx::MDLogger &mdlog,
             gmx_omp_set_num_threads(modth.gnth_pme);
         }
         else
-#endif      /* GMX_THREAD_MPI */
+#endif /* GMX_THREAD_MPI */
         {
             gmx_omp_set_num_threads(nth);
         }
@@ -353,18 +358,14 @@ static void manage_number_of_openmp_threads(const gmx::MDLogger &mdlog,
 }
 
 /*! \brief Report on the OpenMP settings that will be used */
-static void
-reportOpenmpSettings(const gmx::MDLogger &mdlog,
-                     const t_commrec     *cr,
-                     gmx_bool             bOMP,
-                     gmx_bool             bSepPME)
+static void reportOpenmpSettings(const gmx::MDLogger& mdlog, const t_commrec* cr, gmx_bool bOMP, gmx_bool bSepPME)
 {
 #if GMX_THREAD_MPI
-    const char *mpi_str = "per tMPI thread";
+    const charmpi_str = "per tMPI thread";
 #else
-    const char *mpi_str = "per MPI process";
+    const charmpi_str = "per MPI process";
 #endif
-    int         nth_min, nth_max, nth_pme_min, nth_pme_max;
+    int nth_min, nth_max, nth_pme_min, nth_pme_max;
 
     /* inform the user about the settings */
     if (!bOMP)
@@ -379,16 +380,16 @@ reportOpenmpSettings(const gmx::MDLogger &mdlog,
         int buf_in[4], buf_out[4];
 
         buf_in[0] = -modth.gnth;
-        buf_in[1] =  modth.gnth;
+        buf_in[1] = modth.gnth;
         buf_in[2] = -modth.gnth_pme;
-        buf_in[3] =  modth.gnth_pme;
+        buf_in[3] = modth.gnth_pme;
 
         MPI_Allreduce(buf_in, buf_out, 4, MPI_INT, MPI_MAX, cr->mpi_comm_mysim);
 
         nth_min     = -buf_out[0];
-        nth_max     =  buf_out[1];
+        nth_max     = buf_out[1];
         nth_pme_min = -buf_out[2];
-        nth_pme_max =  buf_out[3];
+        nth_pme_max = buf_out[3];
     }
     else
 #endif
@@ -402,54 +403,49 @@ reportOpenmpSettings(const gmx::MDLogger &mdlog,
 
     if (nth_max == nth_min)
     {
-        GMX_LOG(mdlog.warning).appendTextFormatted(
-                "Using %d OpenMP thread%s %s",
-                nth_min, nth_min > 1 ? "s" : "",
-                cr->nnodes > 1 ? mpi_str : "");
+        GMX_LOG(mdlog.warning)
+                .appendTextFormatted("Using %d OpenMP thread%s %s", nth_min, nth_min > 1 ? "s" : "",
+                                     cr->nnodes > 1 ? mpi_str : "");
     }
     else
     {
-        GMX_LOG(mdlog.warning).appendTextFormatted(
-                "Using %d - %d OpenMP threads %s",
-                nth_min, nth_max, mpi_str);
+        GMX_LOG(mdlog.warning).appendTextFormatted("Using %d - %d OpenMP threads %s", nth_min, nth_max, mpi_str);
     }
 
     if (bSepPME && (nth_pme_min != nth_min || nth_pme_max != nth_max))
     {
         if (nth_pme_max == nth_pme_min)
         {
-            GMX_LOG(mdlog.warning).appendTextFormatted(
-                    "Using %d OpenMP thread%s %s for PME",
-                    nth_pme_min, nth_pme_min > 1 ? "s" : "",
-                    cr->nnodes > 1 ? mpi_str : "");
+            GMX_LOG(mdlog.warning)
+                    .appendTextFormatted("Using %d OpenMP thread%s %s for PME", nth_pme_min,
+                                         nth_pme_min > 1 ? "s" : "", cr->nnodes > 1 ? mpi_str : "");
         }
         else
         {
-            GMX_LOG(mdlog.warning).appendTextFormatted(
-                    "Using %d - %d OpenMP threads %s for PME",
-                    nth_pme_min, nth_pme_max, mpi_str);
+            GMX_LOG(mdlog.warning)
+                    .appendTextFormatted("Using %d - %d OpenMP threads %s for PME", nth_pme_min,
+                                         nth_pme_max, mpi_str);
         }
     }
     GMX_LOG(mdlog.warning);
 }
 
-void gmx_omp_nthreads_init(const gmx::MDLogger &mdlog, t_commrec *cr,
-                           int nthreads_hw_avail,
-                           int numRanksOnThisNode,
-                           int omp_nthreads_req,
-                           int omp_nthreads_pme_req,
-                           gmx_bool bThisNodePMEOnly)
+void gmx_omp_nthreads_init(const gmx::MDLogger& mdlog,
+                           t_commrec*           cr,
+                           int                  nthreads_hw_avail,
+                           int                  numRanksOnThisNode,
+                           int                  omp_nthreads_req,
+                           int                  omp_nthreads_pme_req,
+                           gmx_bool             bThisNodePMEOnly)
 {
-    gmx_bool   bSepPME;
+    gmx_bool bSepPME;
 
     const bool bOMP = GMX_OPENMP;
 
     bSepPME = (thisRankHasDuty(cr, DUTY_PP) != thisRankHasDuty(cr, DUTY_PME));
 
-    manage_number_of_openmp_threads(mdlog, cr, bOMP,
-                                    nthreads_hw_avail,
-                                    omp_nthreads_req, omp_nthreads_pme_req,
-                                    bThisNodePMEOnly, numRanksOnThisNode, bSepPME);
+    manage_number_of_openmp_threads(mdlog, cr, bOMP, nthreads_hw_avail, omp_nthreads_req,
+                                    omp_nthreads_pme_req, bThisNodePMEOnly, numRanksOnThisNode, bSepPME);
 #if GMX_THREAD_MPI
     /* Non-master threads have to wait for the OpenMP management to be
      * done, so that code elsewhere that uses OpenMP can be certain
@@ -476,8 +472,7 @@ int gmx_omp_nthreads_get(int mod)
     }
 }
 
-void
-gmx_omp_nthreads_set(int mod, int nthreads)
+void gmx_omp_nthreads_set(int mod, int nthreads)
 {
     /* Catch an attempt to set the number of threads on an invalid
      * OpenMP module. */