Skip to content

Commit e2f66c2

Browse files
committed
speed up by removing some divisions
1 parent 82b4944 commit e2f66c2

2 files changed

Lines changed: 27 additions & 21 deletions

File tree

src/measure/rdf.cu

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace
3636
{
3737
__global__ void gpu_find_rdf_ON1(
3838
const int N,
39-
const RDF::RDF_Para rdf_para,
39+
const RDF::RDF_Para para,
4040
const Box box,
4141
const int* __restrict__ cell_counts,
4242
const int* __restrict__ cell_count_sum,
@@ -95,21 +95,21 @@ __global__ void gpu_find_rdf_ON1(
9595
double z12 = z[n2] - z1;
9696
apply_mic(box, x12, y12, z12);
9797
const double d2 = x12 * x12 + y12 * y12 + z12 * z12;
98-
if (d2 > rdf_para.rc_square) {
98+
if (d2 > para.rc_square) {
9999
continue;
100100
}
101-
for (int w = 0; w < rdf_para.num_bins; w++) {
102-
double r_low = (w*rdf_para.dr) * (w*rdf_para.dr);
103-
double r_up = ((w+1)*rdf_para.dr) * ((w+1)*rdf_para.dr);
104-
double r_mid_sqaure = ((w+0.5)*rdf_para.dr) * ((w+0.5)*rdf_para.dr);
105-
double dV = r_mid_sqaure * 4 * rdf_PI * rdf_para.dr;
101+
for (int w = 0; w < para.num_bins; w++) {
102+
double r_low = (w * para.dr) * (w * para.dr);
103+
double r_up = ((w + 1) * para.dr) * ((w + 1) * para.dr);
104+
double r_mid_sqaure = ((w + 0.5) * para.dr) * ((w + 0.5) * para.dr);
105+
double dV = r_mid_sqaure * 4 * rdf_PI * para.dr;
106106
if (d2 > r_low && d2 <= r_up) {
107-
atomicAdd(&rdf_[w * rdf_para.num_RDFs + 0], 1 / (N * (N/rdf_para.volume) * dV));
107+
atomicAdd(&rdf_[w * para.num_RDFs + 0], 1 / (N * para.density_global * dV));
108108
int count = 1;
109-
for (int a = 0; a < rdf_para.num_types; ++a) {
110-
for (int b = a; b < rdf_para.num_types; ++b) {
111-
if(type[n1] == rdf_para.type_index[a] && type[n2] == rdf_para.type_index[b]) {
112-
atomicAdd(&rdf_[w * rdf_para.num_RDFs + count], 1 / (rdf_para.num_atoms[a] * (rdf_para.num_atoms[b]/rdf_para.volume) * dV));
109+
for (int a = 0; a < para.num_types; ++a) {
110+
for (int b = a; b < para.num_types; ++b) {
111+
if(type[n1] == para.type_index[a] && type[n2] == para.type_index[b]) {
112+
atomicAdd(&rdf_[w * para.num_RDFs + count], 1 / (para.num_atoms[a] * para.density_type[b] * dV));
113113
}
114114
++count;
115115
}
@@ -194,6 +194,10 @@ void RDF::process(
194194
}
195195

196196
rdf_para.volume = box.get_volume();
197+
rdf_para.density_global = atom.number_of_atoms / rdf_para.volume;
198+
for (int t = 0; t < rdf_para.num_types; ++ t) {
199+
rdf_para.density_type[t] = rdf_para.num_atoms[t] / rdf_para.volume;
200+
}
197201
find_rdf(box, atom.type, integrate.type >= 31 ? atom.position_beads[0] : atom.position_per_atom);
198202
}
199203

src/measure/rdf.cuh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ class RDF : public Property
2727
public:
2828

2929
struct RDF_Para {
30-
int num_types; // number of atom types in model.xyz
31-
int num_RDFs; // 1 + (num_type * (num_types + 1)) / 2
32-
int num_bins; // number of bins in the RDFs
33-
double volume; // volume could change during NPT simulations
34-
double rc; // cutoff for RDF calculation
35-
double rc_square; // rc * rc
36-
double dr; // rc / num_bins
37-
int type_index[89]; // map of atom type from model.xyz to nep.txt
38-
int num_atoms[89]; // number of atoms for each atom type
30+
int num_types; // number of atom types in model.xyz
31+
int num_RDFs; // 1 + (num_type * (num_types + 1)) / 2
32+
int num_bins; // number of bins in the RDFs
33+
double volume; // volume could change during NPT simulations
34+
double rc; // cutoff for RDF calculation
35+
double rc_square; // rc * rc
36+
double dr; // rc / num_bins
37+
int type_index[89]; // map of atom type from model.xyz to nep.txt
38+
int num_atoms[89]; // number of atoms for each atom type
39+
double density_global; // N/volume
40+
double density_type[89]; // num_atoms[89]/volume
3941
};
4042

4143
virtual void preprocess(

0 commit comments

Comments
 (0)