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 /* ----------------------------------------------------------------------
15    Contributing author: Axel Kohlmeyer (Temple U)
16 ------------------------------------------------------------------------- */
17 
18 #ifndef LMP_THR_DATA_H
19 #define LMP_THR_DATA_H
20 
21 #include "timer.h"    // IWYU pragma: export
22 
23 namespace LAMMPS_NS {
24 
25 // per thread data accumulators
26 // there should be one instance
27 // of this class for each thread.
28 class ThrData {
29   friend class FixOMP;
30   friend class ThrOMP;
31 
32  public:
33   ThrData(int tid, class Timer *t);
~ThrData()34   ~ThrData()
35   {
36     delete _timer;
37     _timer = nullptr;
38   };
39 
40   void check_tid(int);                     // thread id consistency check
get_tid()41   int get_tid() const { return _tid; };    // our thread id.
42 
43   // inline wrapper, to make this more efficient
44   // when per-thread timers are off
timer(enum Timer::ttype flag)45   void timer(enum Timer::ttype flag)
46   {
47     if (_timer) _stamp(flag);
48   };
49   double get_time(enum Timer::ttype flag);
50 
51   // erase accumulator contents and hook up force arrays
52   void init_force(int, double **, double **, double *, double *, double *);
53 
54   // give access to per-thread offset arrays
get_f()55   double **get_f() const { return _f; };
get_torque()56   double **get_torque() const { return _torque; };
get_de()57   double *get_de() const { return _de; };
get_drho()58   double *get_drho() const { return _drho; };
59 
60   // setup and erase per atom arrays
61   void init_adp(int, double *, double **, double **);    // ADP (+ EAM)
62   void init_eam(int, double *);                          // EAM
63   void init_eim(int, double *, double *);                // EIM (+ EAM)
64 
65   void init_pppm(int, class Memory *);
66   void init_pppm_disp(int, class Memory *);
67 
68   // access methods for arrays that we handle in this class
get_lambda()69   double **get_lambda() const { return _lambda; };
get_mu()70   double **get_mu() const { return _mu; };
get_D_values()71   double *get_D_values() const { return _D_values; };
get_fp()72   double *get_fp() const { return _fp; };
get_rho()73   double *get_rho() const { return _rho; };
get_rhoB()74   double *get_rhoB() const { return _rhoB; };
get_rho1d()75   void *get_rho1d() const { return _rho1d; };
get_drho1d()76   void *get_drho1d() const { return _drho1d; };
get_rho1d_6()77   void *get_rho1d_6() const { return _rho1d_6; };
get_drho1d_6()78   void *get_drho1d_6() const { return _drho1d_6; };
79 
80  private:
81   double eng_vdwl;           // non-bonded non-coulomb energy
82   double eng_coul;           // non-bonded coulomb energy
83   double eng_bond;           // bond energy
84   double eng_angle;          // angle energy
85   double eng_dihed;          // dihedral energy
86   double eng_imprp;          // improper energy
87   double eng_kspce;          // kspace energy
88   double virial_pair[6];     // virial contribution from non-bonded
89   double virial_bond[6];     // virial contribution from bonds
90   double virial_angle[6];    // virial contribution from angles
91   double virial_dihed[6];    // virial contribution from dihedrals
92   double virial_imprp[6];    // virial contribution from impropers
93   double virial_kspce[6];    // virial contribution from kspace
94   double *eatom_pair;
95   double *eatom_bond;
96   double *eatom_angle;
97   double *eatom_dihed;
98   double *eatom_imprp;
99   double *eatom_kspce;
100   double **vatom_pair;
101   double **vatom_bond;
102   double **vatom_angle;
103   double **vatom_dihed;
104   double **vatom_imprp;
105   double **vatom_kspce;
106   double **cvatom_pair;
107   double **cvatom_angle;
108   double **cvatom_dihed;
109   double **cvatom_imprp;
110 
111   // per thread segments of various force or similar arrays
112 
113   // these are maintained by atom styles
114   double **_f;
115   double **_torque;
116   double *_erforce;
117   double *_de;
118   double *_drho;
119 
120   // these are maintained by individual pair styles
121   double **_mu, **_lambda;      // ADP (+ EAM)
122   double *_rhoB, *_D_values;    // CDEAM (+ EAM)
123   double *_rho;                 // EAM
124   double *_fp;                  // EIM (+ EAM)
125 
126   // this is for pppm/omp
127   void *_rho1d;
128   void *_drho1d;
129   // this is for pppm/disp/omp
130   void *_rho1d_6;
131   void *_drho1d_6;
132   // my thread id
133   const int _tid;
134   // timer info
135   int _timer_active;
136   class Timer *_timer;
137 
138  private:
139   void _stamp(enum Timer::ttype flag);
140 
141  public:
142   // compute global per thread virial contribution from global forces and positions
143   void virial_fdotr_compute(double **, int, int, int);
144 
145   double memory_usage();
146 
147   // disabled default methods
148  private:
ThrData()149   ThrData() : _tid(-1), _timer(nullptr){};
150 };
151 
152 ////////////////////////////////////////////////////////////////////////
153 //  helper functions operating on data replicated for thread support  //
154 ////////////////////////////////////////////////////////////////////////
155 // generic per thread data reduction for continuous arrays of nthreads*nmax size
156 void data_reduce_thr(double *, int, int, int, int);
157 }    // namespace LAMMPS_NS
158 #endif
159