Skip to content
Permalink
Browse files

core: non_bonded: Allocate less memory

  • Loading branch information...
fweik committed Aug 12, 2019
1 parent de7bfe8 commit d284e1f8143ffdf9c1ecbdded33218cbe501de07
@@ -220,13 +220,13 @@ void realloc_ia_params(int nsize) {
if (nsize <= max_seen_particle_type)
return;

auto new_params = std::vector<IA_parameters>(nsize * nsize);
auto new_params = std::vector<IA_parameters>(nsize * (nsize + 1) / 2);

/* if there is an old field, move entries */
for (int i = 0; i < max_seen_particle_type; i++)
for (int j = 0; j < max_seen_particle_type; j++) {
new_params[i * nsize + j] =
std::move(ia_params[i * max_seen_particle_type + j]);
for (int j = i; j < max_seen_particle_type; j++) {
new_params.at(Utils::upper_triangular(i, j, nsize)) =
std::move(*get_ia_param(i, j));
}

max_seen_particle_type = nsize;
@@ -335,11 +335,11 @@ extern double min_global_cut;
* @return Pointer to interaction parameters for the type pair.
* */
inline IA_parameters *get_ia_param(int i, int j) {
assert(i >= 0 && i <= max_seen_particle_type);
assert(j >= 0 && j <= max_seen_particle_type);
assert(i >= 0 && i < max_seen_particle_type);
assert(j >= 0 && j < max_seen_particle_type);

return &ia_params[Utils::upper_triangular(std::min(i, j), std::max(i, j),
max_seen_particle_type + 1)];
max_seen_particle_type)];
}

/** Get interaction parameters between particle sorts i and j.

0 comments on commit d284e1f

Please sign in to comment.
You can’t perform that action at this time.