Made gromacs work again without MPI
[alexxy/gromacs.git] / src / gromacs / gmxlib / network.h
index e690525d68760ecfab263fc68b236b3e1f45c178..3ac723afd7b7c9834c2eb78f1428bea3b308952d 100644 (file)
@@ -3,7 +3,8 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/gmxmpi.h"
+#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/unique_cptr.h"
 
-struct gmx_multisim_t;
 struct t_commrec;
 struct t_filenm;
 
-struct t_commrec *init_commrec(void);
-/* Allocate, initialize and return the commrec. */
+//! Free memory associated with the commrec.
+void done_commrec(t_commrec* cr);
 
-void done_commrec(t_commrec *cr);
-/* Free memory associated with the commrec. */
+//! Convenience alias.
+using CommrecHandle = gmx::unique_cptr<t_commrec, done_commrec>;
 
-struct t_commrec *reinitialize_commrec_for_this_thread(const t_commrec *cro);
+//! Allocate, initialize and return the commrec.
+CommrecHandle init_commrec(MPI_Comm communicator);
+
+struct t_commrec* reinitialize_commrec_for_this_thread(const t_commrec* cro);
 
 /* Initialize communication records for thread-parallel simulations.
    Must be called on all threads before any communication takes place by
@@ -64,62 +69,56 @@ struct t_commrec *reinitialize_commrec_for_this_thread(const t_commrec *cro);
    thread-local versions (a small memory leak results because we don't
    deallocate the old shared version).  */
 
-void gmx_fill_commrec_from_mpi(t_commrec            *cr);
+void gmx_fill_commrec_from_mpi(t_commreccr);
 /* Continues t_commrec construction */
 
-void gmx_setup_nodecomm(FILE *fplog, struct t_commrec *cr);
+void gmx_setup_nodecomm(FILE* fplog, struct t_commrec* cr);
 /* Sets up fast global communication for clusters with multi-core nodes */
 
-void gmx_barrier(const struct t_commrec *cr);
-/* Wait till all processes in cr->mpi_comm_mygroup have reached the barrier */
-
-void gmx_bcast(int nbytes, void *b, const struct t_commrec *cr);
-/* Broadcast nbytes bytes from the master to cr->mpi_comm_mygroup */
-
-void gmx_bcast_sim(int nbytes, void *b, const struct t_commrec *cr);
-/* Broadcast nbytes bytes from the sim master to cr->mpi_comm_mysim */
-
-void gmx_sumi(int nr, int r[], const struct t_commrec *cr);
-/* Calculate the global sum of an array of ints */
+//! Wait until all processes in communicator have reached the barrier
+void gmx_barrier(MPI_Comm communicator);
 
-void gmx_sumli(int nr, gmx_int64_t r[], const struct t_commrec *cr);
-/* Calculate the global sum of an array of large ints */
-
-void gmx_sumf(int nr, float r[], const struct t_commrec *cr);
-/* Calculate the global sum of an array of floats */
-
-void gmx_sumd(int nr, double r[], const struct t_commrec *cr);
-/* Calculate the global sum of an array of doubles */
-
-void gmx_sumi_sim(int nr, int r[], const struct gmx_multisim_t *ms);
-/* Calculate the sum over the simulations of an array of ints */
+/*! Broadcast nbytes bytes from the master to communicator
+ *
+ * Can be called with a single rank or without MPI
+ */
+void gmx_bcast(int nbytes, void* b, MPI_Comm communicator);
 
-void gmx_sumli_sim(int nr, gmx_int64_t r[], const struct gmx_multisim_t *ms);
-/* Calculate the sum over the simulations of an array of large ints */
+/*! Calculate the global sum of an array of ints
+ *
+ * Can be called with a single rank or without MPI
+ */
+void gmx_sumi(int nr, int r[], const struct t_commrec* cr);
 
-void gmx_sumf_sim(int nr, float r[], const struct gmx_multisim_t *ms);
-/* Calculate the sum over the simulations of an array of floats */
+/*! Calculate the global sum of an array of floats
+ *
+ * Can be called with a single rank or without MPI
+ */
+void gmx_sumf(int nr, float r[], const struct t_commrec* cr);
 
-void gmx_sumd_sim(int nr, double r[], const struct gmx_multisim_t *ms);
-/* Calculate the sum over the simulations of an array of doubles */
+/*! Calculate the global sum of an array of doubles
+ *
+ * Can be called with a single rank or without MPI
+ */
+void gmx_sumd(int nr, double r[], const struct t_commrec* cr);
 
 #if GMX_DOUBLE
-#define gmx_sum       gmx_sumd
-#define gmx_sum_sim   gmx_sumd_sim
+#    define gmx_sum gmx_sumd
 #else
-#define gmx_sum       gmx_sumf
-#define gmx_sum_sim   gmx_sumf_sim
+#    define gmx_sum gmx_sumf
 #endif
 
-const char *opt2fn_master(const char *opt, int nfile,
-                          const t_filenm fnm[], t_commrec *cr);
+const char* opt2fn_master(const char* opt, int nfile, const t_filenm fnm[], t_commrec* cr);
 /* Return the filename belonging to cmd-line option opt, or NULL when
  * no such option or not running on master */
 
-void
-gmx_fatal_collective(int f_errno, const char *file, int line,
-                     MPI_Comm comm, gmx_bool bMaster,
-                     const char *fmt, ...);
+[[noreturn]] void gmx_fatal_collective(int                    f_errno,
+                                       const char*            file,
+                                       int                    line,
+                                       MPI_Comm               comm,
+                                       gmx_bool               bMaster,
+                                       gmx_fmtstr const char* fmt,
+                                       ...) gmx_format(printf, 6, 7);
 /* As gmx_fatal declared in utility/fatalerror.h,
  * but only the master process prints the error message.
  * This should only be called one of the following two situations: