5e5e5f3d855276c3ab6e01a433652d1a97207829
[alexxy/gromacs.git] / src / gromacs / legacyheaders / 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, 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
38 #ifndef _network_h
39 #define _network_h
40
41
42 /*
43  * This module defines the interface of the actual communication routines.
44  */
45
46 #include <stdio.h>
47
48 #include "../utility/basedefinitions.h"
49 #include "../utility/fatalerror.h"
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 struct gmx_domdec_t;
56 struct gmx_multisim_t;
57 struct t_commrec;
58
59 struct t_commrec *init_commrec(void);
60 /* Allocate, initialize and return the commrec. */
61
62 struct t_commrec *reinitialize_commrec_for_this_thread(const struct t_commrec *cro);
63 /* Initialize communication records for thread-parallel simulations.
64    Must be called on all threads before any communication takes place by
65    the individual threads. Copies the original commrec to
66    thread-local versions (a small memory leak results because we don't
67    deallocate the old shared version).  */
68
69 void gmx_fill_commrec_from_mpi(struct t_commrec *cr);
70 /* Continues t_commrec construction */
71
72 void gmx_setup_nodecomm(FILE *fplog, struct t_commrec *cr);
73 /* Sets up fast global communication for clusters with multi-core nodes */
74
75 void gmx_init_intranode_counters(struct t_commrec *cr);
76 /* Initializes intra-physical-node MPI process/thread counts and ID. */
77
78 void gmx_barrier(const struct t_commrec *cr);
79 /* Wait till all processes in cr->mpi_comm_mygroup have reached the barrier */
80
81 void gmx_bcast(int nbytes, void *b, const struct t_commrec *cr);
82 /* Broadcast nbytes bytes from the master to cr->mpi_comm_mygroup */
83
84 void gmx_bcast_sim(int nbytes, void *b, const struct t_commrec *cr);
85 /* Broadcast nbytes bytes from the sim master to cr->mpi_comm_mysim */
86
87 void gmx_sumi(int nr, int r[], const struct t_commrec *cr);
88 /* Calculate the global sum of an array of ints */
89
90 void gmx_sumli(int nr, gmx_int64_t r[], const struct t_commrec *cr);
91 /* Calculate the global sum of an array of large ints */
92
93 void gmx_sumf(int nr, float r[], const struct t_commrec *cr);
94 /* Calculate the global sum of an array of floats */
95
96 void gmx_sumd(int nr, double r[], const struct t_commrec *cr);
97 /* Calculate the global sum of an array of doubles */
98
99 void gmx_sumi_sim(int nr, int r[], const struct gmx_multisim_t *ms);
100 /* Calculate the sum over the simulations of an array of ints */
101
102 void gmx_sumli_sim(int nr, gmx_int64_t r[], const struct gmx_multisim_t *ms);
103 /* Calculate the sum over the simulations of an array of large ints */
104
105 void gmx_sumf_sim(int nr, float r[], const struct gmx_multisim_t *ms);
106 /* Calculate the sum over the simulations of an array of floats */
107
108 void gmx_sumd_sim(int nr, double r[], const struct gmx_multisim_t *ms);
109 /* Calculate the sum over the simulations of an array of doubles */
110
111 #ifdef GMX_DOUBLE
112 #define gmx_sum       gmx_sumd
113 #define gmx_sum_sim   gmx_sumd_sim
114 #else
115 #define gmx_sum       gmx_sumf
116 #define gmx_sum_sim   gmx_sumf_sim
117 #endif
118
119 gmx_bool gmx_fexist_master(const char *fname, struct t_commrec *cr);
120 /* Return TRUE when fname exists, FALSE otherwise, bcast from master to others */
121
122 void
123 gmx_fatal_collective(int f_errno, const char *file, int line,
124                      const struct t_commrec *cr, struct gmx_domdec_t *dd,
125                      const char *fmt, ...);
126 /* As gmx_fatal declared in utility/fatalerror.h,
127  * but only the master process prints the error message.
128  * This should only be called one of the following two situations:
129  * 1) On all nodes in cr->mpi_comm_mysim, with cr!=NULL,dd==NULL.
130  * 2) On all nodes in dd->mpi_comm_all,   with cr==NULL,dd!=NULL.
131  * This will call MPI_Finalize instead of MPI_Abort when possible,
132  * This is useful for handling errors in code that is executed identically
133  * for all processes.
134  */
135
136 /* This doesn't currently work if enabled (needs some header cleanup). */
137 #ifdef DEBUG_GMX
138 #define debug_gmx() do { FILE *fp = debug ? debug : stderr; \
139                          if (bDebugMode()) { fprintf(fp, "rank=%d, %s  %d\n", gmx_mpi_initialized() ? gmx_node_rank() : -1, __FILE__, __LINE__); } fflush(fp); } while (0)
140 #else
141 #define debug_gmx()
142 #endif
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148
149 #endif  /* _network_h */