1 /* -*- c++ -*- ----------------------------------------------------------
2    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3    https://www.lammps.org/, Sandia National Laboratories
4    Steve Plimpton, sjplimp@sandia.gov
5 
6    Copyright (2003) Sandia Corporation.  Under the terms of Contract
7    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8    certain rights in this software.  This software is distributed under
9    the GNU General Public License.
10 
11    See the README file in the top-level LAMMPS directory.
12 ------------------------------------------------------------------------- */
13 
14 #ifndef LMP_COMM_H
15 #define LMP_COMM_H
16 
17 #include "pointers.h"    // IWYU pragma: export
18 
19 namespace LAMMPS_NS {
20 
21 class Comm : protected Pointers {
22  public:
23   int style;     // comm pattern: 0 = 6-way stencil, 1 = irregular tiling
24   int layout;    // LAYOUT_UNIFORM = equal-sized bricks
25                  // LAYOUT_NONUNIFORM = logical bricks, but diff sizes via LB
26                  // LAYOUT_TILED = general tiling, due to RCB LB
27   enum { LAYOUT_UNIFORM, LAYOUT_NONUNIFORM, LAYOUT_TILED };
28   int mode;    // 0 = single cutoff, 1 = multi-collection cutoff, 2 = multiold-type cutoff
29   enum { SINGLE, MULTI, MULTIOLD };
30 
31   int me, nprocs;               // proc info
32   int ghost_velocity;           // 1 if ghost atoms have velocity, 0 if not
33   double cutghost[3];           // cutoffs used for acquiring ghost atoms
34   double cutghostuser;          // user-specified ghost cutoff (mode == SINGLE)
35   double *cutusermulti;         // per collection user ghost cutoff (mode == MULTI)
36   double *cutusermultiold;      // per type user ghost cutoff (mode == MULTIOLD)
37   int ncollections;             // # of collections known by comm, used to test if # has changed
38   int ncollections_cutoff;      // # of collections stored b cutoff/multi
39   int recv_from_partition;      // recv proc layout from this partition
40   int send_to_partition;        // send my proc layout to this partition
41                                 // -1 if no recv or send
42   int other_partition_style;    // 0 = recv layout dims must be multiple of
43                                 //     my layout dims
44 
45   int nthreads;    // OpenMP threads per MPI process
46 
47   // public settings specific to layout = UNIFORM, NONUNIFORM
48 
49   int procgrid[3];                     // procs assigned in each dim of 3d grid
50   int user_procgrid[3];                // user request for procs in each dim
51   int myloc[3];                        // which proc I am in each dim
52   int procneigh[3][2];                 // my 6 neighboring procs, 0/1 = left/right
53   double *xsplit, *ysplit, *zsplit;    // fractional (0-1) sub-domain sizes
54   int ***grid2proc;                    // which proc owns i,j,k loc in 3d grid
55 
56   // public settings specific to layout = TILED
57 
58   int rcbnew;              // 1 if just reset by rebalance, else 0
59   double mysplit[3][2];    // fractional (0-1) bounds of my sub-domain
60   double rcbcutfrac;       // fractional RCB cut by this proc
61   int rcbcutdim;           // dimension of RCB cut
62 
63   // methods
64 
65   Comm(class LAMMPS *);
66   virtual ~Comm();
67   // NOTE: copy_arrays is called from a constructor and must not be made virtual
68   void copy_arrays(class Comm *);
69   virtual void init();
70   void modify_params(int, char **);
71 
72   void set_processors(int, char **);              // set 3d processor grid attributes
73   virtual void set_proc_grid(int outflag = 1);    // setup 3d grid of procs
74 
75   double get_comm_cutoff();    // determine communication cutoff
76 
77   virtual void setup() = 0;                        // setup 3d comm pattern
78   virtual void forward_comm(int dummy = 0) = 0;    // forward comm of atom coords
79   virtual void reverse_comm() = 0;                 // reverse comm of forces
80   virtual void exchange() = 0;                     // move atoms to new procs
81   virtual void borders() = 0;                      // setup list of atoms to comm
82 
83   // forward/reverse comm from a Pair, Fix, Compute, Dump
84 
85   virtual void forward_comm_pair(class Pair *) = 0;
86   virtual void reverse_comm_pair(class Pair *) = 0;
87   virtual void forward_comm_fix(class Fix *, int size = 0) = 0;
88   virtual void reverse_comm_fix(class Fix *, int size = 0) = 0;
89   virtual void reverse_comm_fix_variable(class Fix *) = 0;
90   virtual void forward_comm_compute(class Compute *) = 0;
91   virtual void reverse_comm_compute(class Compute *) = 0;
92   virtual void forward_comm_dump(class Dump *) = 0;
93   virtual void reverse_comm_dump(class Dump *) = 0;
94 
95   // forward comm of an array
96   // exchange of info on neigh stencil
97   // set processor mapping options
98 
99   virtual void forward_comm_array(int, double **) = 0;
100   virtual int exchange_variable(int, double *, double *&) = 0;
101 
102   // map a point to a processor, based on current decomposition
103 
coord2proc_setup()104   virtual void coord2proc_setup() {}
105   virtual int coord2proc(double *, int &, int &, int &);
106 
107   // partition a global regular grid by proc sub-domains
108 
109   void partition_grid(int, int, int, double, int &, int &, int &, int &, int &, int &);
110 
111   // memory usage
112 
113   virtual double memory_usage() = 0;
114 
115   // non-virtual functions common to all Comm styles
116 
117   void ring(int, int, void *, int, void (*)(int, char *, void *), void *, void *, int self = 1);
118   int rendezvous(int, int, char *, int, int, int *,
119                  int (*)(int, char *, int &, int *&, char *&, void *), int, char *&, int, void *,
120                  int statflag = 0);
121 
122   // extract data useful to other classes
123 
extract(const char *,int &)124   virtual void *extract(const char *, int &) { return nullptr; }
125 
126  protected:
127   int bordergroup;    // only communicate this group in borders
128 
129   int triclinic;                   // 0 if domain is orthog, 1 if triclinic
130   int map_style;                   // non-0 if global->local mapping is done
131   int comm_x_only, comm_f_only;    // 1 if only exchange x,f in for/rev comm
132 
133   int size_forward;    // # of per-atom datums in forward comm
134   int size_reverse;    // # of datums in reverse comm
135   int size_border;     // # of datums in forward border comm
136 
137   int maxforward, maxreverse;     // max # of datums in forward/reverse comm
138   int maxexchange;                // max size of one exchanged atom
139   int maxexchange_atom;           // contribution to maxexchange from AtomVec
140   int maxexchange_fix;            // static contribution to maxexchange from Fixes
141   int maxexchange_fix_dynamic;    // 1 if a fix has a dynamic contribution
142   int bufextra;                   // augment send buf size for an exchange atom
143 
144   int gridflag;        // option for creating 3d grid
145   int mapflag;         // option for mapping procs to 3d grid
146   char xyz[4];         // xyz mapping of procs to 3d grid
147   char *customfile;    // file with custom proc map
148   char *outfile;       // proc grid/map output file
149 
150   int otherflag;            // 1 if this partition dependent on another
151   int other_style;          // style of dependency
152   int other_procgrid[3];    // proc layout of another partition
153   int other_coregrid[3];    // core layout of another partition
154   int ncores;               // # of cores per node
155   int coregrid[3];          // 3d grid of cores within a node
156   int user_coregrid[3];     // user request for cores in each dim
157   int multi_reduce;         // 1 if multi cutoff is intra-collection cutoff
158 
159   void init_exchange();
160   int rendezvous_irregular(int, char *, int, int, int *,
161                            int (*)(int, char *, int &, int *&, char *&, void *), int, char *&, int,
162                            void *, int);
163   int rendezvous_all2all(int, char *, int, int, int *,
164                          int (*)(int, char *, int &, int *&, char *&, void *), int, char *&, int,
165                          void *, int);
166   void rendezvous_stats(int, int, int, int, int, int, bigint);
167 
168  public:
169   enum { MULTIPLE };
170 };
171 
172 }    // namespace LAMMPS_NS
173 
174 #endif
175 
176 /* ERROR/WARNING messages:
177 
178 E: Illegal ... command
179 
180 Self-explanatory.  Check the input script syntax and compare to the
181 documentation for the command.  You can use -echo screen as a
182 command-line option when running LAMMPS to see the offending line.
183 
184 E: Invalid group in comm_modify command
185 
186 Self-explanatory.
187 
188 E: Comm_modify group != atom_modify first group
189 
190 Self-explanatory.
191 
192 E: Use cutoff/multi keyword to set cutoff in multi mode
193 
194 Mode is multi so cutoff keyword cannot be used.
195 
196 E: Invalid cutoff in comm_modify command
197 
198 Specified cutoff must be >= 0.0.
199 
200 E: Use cutoff keyword to set cutoff in single mode
201 
202 Mode is single so cutoff/multi keyword cannot be used.
203 
204 E: Use cutoff/bytype in mode multi only
205 
206 Mode is single so cutoff/bytype keyword cannot be used.
207 
208 E: Cannot set cutoff/multi before simulation box is defined
209 
210 Self-explanatory.
211 
212 E: Specified processors != physical processors
213 
214 The 3d grid of processors defined by the processors command does not
215 match the number of processors LAMMPS is being run on.
216 
217 E: Cannot use processors part command without using partitions
218 
219 See the command-line -partition switch.
220 
221 E: Invalid partitions in processors part command
222 
223 Valid partitions are numbered 1 to N and the sender and receiver
224 cannot be the same partition.
225 
226 E: Sending partition in processors part command is already a sender
227 
228 Cannot specify a partition to be a sender twice.
229 
230 E: Receiving partition in processors part command is already a receiver
231 
232 Cannot specify a partition to be a receiver twice.
233 
234 E: Processors grid numa and map style are incompatible
235 
236 Using numa for gstyle in the processors command requires using
237 cart for the map option.
238 
239 E: Processors part option and grid style are incompatible
240 
241 Cannot use gstyle numa or custom with the part option.
242 
243 E: Bad grid of processors
244 
245 The 3d grid of processors defined by the processors command does not
246 match the number of processors LAMMPS is being run on.
247 
248 E: Processor count in z must be 1 for 2d simulation
249 
250 Self-explanatory.
251 
252 E: Cannot use multi/tiered communication with Newton off
253 
254 Self-explanatory.
255 
256 E: Cannot put data on ring from nullptr pointer
257 
258 W: Communication cutoff is 0.0. No ghost atoms will be generated. Atoms may get lost.
259 
260 The communication cutoff defaults to the maximum of what is inferred from pair and
261 bond styles (will be zero, if none are defined) and what is specified via
262 "comm_modify cutoff" (defaults to 0.0).  If this results to 0.0, no ghost atoms will
263 be generated and LAMMPS may lose atoms or use incorrect periodic images of atoms in
264 interaction lists.  To avoid, either define pair style zero with a suitable cutoff
265 or use comm_modify cutoff.
266 
267 W: Communication cutoff is shorter than a bond length based estimate. This may lead to errors.
268 
269 Since LAMMPS stores topology data with individual atoms, all atoms comprising
270 a bond, angle, dihedral or improper must be present on any sub-domain that
271 "owns" the atom with the information, either as a local or a ghost atom. The
272 communication cutoff is what determines up to what distance from a sub-domain
273 boundary ghost atoms are created.  The communication cutoff is by default the
274 largest non-bonded cutoff plus the neighbor skin distance, but for short or
275 non-bonded cutoffs and/or long bonds, this may not be sufficient. This warning
276 indicates that there is an increased risk of a simulation stopping unexpectedly
277 because of Bond/Angle/Dihedral/Improper atoms missing.  It can be silenced by
278 manually setting the communication cutoff via comm_modify cutoff.  However,
279 since the heuristic used to determine the estimate is not always accurate, it
280 is not changed automatically and the warning may be ignored depending on the
281 specific system being simulated.
282 
283 UNDOCUMENTED
284 
285 U: OMP_NUM_THREADS environment is not set.
286 
287 This environment variable must be set appropriately to use the
288 OPENMP package.
289 
290 */
291