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