Merge branch release-2019 into master
[alexxy/gromacs.git] / src / gromacs / gmxlib / network.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #ifndef GMX_GMXLIB_NETWORK_H
38 #define GMX_GMXLIB_NETWORK_H
39
40 /*
41  * This module defines the interface of the actual communication routines.
42  */
43
44 #include <stdio.h>
45
46 #include "gromacs/utility/basedefinitions.h"
47 #include "gromacs/utility/gmxmpi.h"
48 #include "gromacs/utility/stringutil.h"
49 #include "gromacs/utility/unique_cptr.h"
50
51 struct t_commrec;
52 struct t_filenm;
53
54 //! Free memory associated with the commrec.
55 void done_commrec(t_commrec *cr);
56
57 //! Convenience alias.
58 using CommrecHandle = gmx::unique_cptr<t_commrec, done_commrec>;
59
60 //! Allocate, initialize and return the commrec.
61 CommrecHandle init_commrec();
62
63 struct t_commrec *reinitialize_commrec_for_this_thread(const t_commrec *cro);
64
65 /* Initialize communication records for thread-parallel simulations.
66    Must be called on all threads before any communication takes place by
67    the individual threads. Copies the original commrec to
68    thread-local versions (a small memory leak results because we don't
69    deallocate the old shared version).  */
70
71 void gmx_fill_commrec_from_mpi(t_commrec            *cr);
72 /* Continues t_commrec construction */
73
74 void gmx_setup_nodecomm(FILE *fplog, struct t_commrec *cr);
75 /* Sets up fast global communication for clusters with multi-core nodes */
76
77 void gmx_barrier(const struct t_commrec *cr);
78 /* Wait till all processes in cr->mpi_comm_mygroup have reached the barrier */
79
80 void gmx_bcast(int nbytes, void *b, const struct t_commrec *cr);
81 /* Broadcast nbytes bytes from the master to cr->mpi_comm_mygroup */
82
83 void gmx_bcast_sim(int nbytes, void *b, const struct t_commrec *cr);
84 /* Broadcast nbytes bytes from the sim master to cr->mpi_comm_mysim */
85
86 void gmx_sumi(int nr, int r[], const struct t_commrec *cr);
87 /* Calculate the global sum of an array of ints */
88
89 void gmx_sumli(int nr, int64_t r[], const struct t_commrec *cr);
90 /* Calculate the global sum of an array of large ints */
91
92 void gmx_sumf(int nr, float r[], const struct t_commrec *cr);
93 /* Calculate the global sum of an array of floats */
94
95 void gmx_sumd(int nr, double r[], const struct t_commrec *cr);
96 /* Calculate the global sum of an array of doubles */
97
98 #if GMX_DOUBLE
99 #define gmx_sum       gmx_sumd
100 #else
101 #define gmx_sum       gmx_sumf
102 #endif
103
104 const char *opt2fn_master(const char *opt, int nfile,
105                           const t_filenm fnm[], t_commrec *cr);
106 /* Return the filename belonging to cmd-line option opt, or NULL when
107  * no such option or not running on master */
108
109 [[ noreturn ]] void
110 gmx_fatal_collective(int f_errno, const char *file, int line,
111                      MPI_Comm comm, gmx_bool bMaster,
112                      gmx_fmtstr const char *fmt, ...) gmx_format(printf, 6, 7);
113 /* As gmx_fatal declared in utility/fatalerror.h,
114  * but only the master process prints the error message.
115  * This should only be called one of the following two situations:
116  * 1) On all nodes in cr->mpi_comm_mysim, with cr!=NULL,dd==NULL.
117  * 2) On all nodes in dd->mpi_comm_all,   with cr==NULL,dd!=NULL.
118  * This will call MPI_Finalize instead of MPI_Abort when possible,
119  * This is useful for handling errors in code that is executed identically
120  * for all processes.
121  */
122
123 //! Make a barrier across all ranks of this simulation
124 void simulationBarrier(const t_commrec *cr);
125
126 #endif