Skip to content
Snippets Groups Projects
Commit 2b18a5ec authored by James Willis's avatar James Willis
Browse files

Compute distances and store them as constants.

parent 58e56ba1
Branches
Tags
1 merge request!407Patch vecorised pair interactions
...@@ -287,11 +287,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache( ...@@ -287,11 +287,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
temp = 0; temp = 0;
const struct part *pi = &parts_i[sort_i[first_pi].i]; const struct part *pi = &parts_i[sort_i[first_pi].i];
const float first_di = sort_i[first_pi].d + pi->h * kernel_gamma + dx_max - rshift;
/* Loop through particles in cell j until they are not in range of pi. */ /* Loop through particles in cell j until they are not in range of pi. */
while (temp <= cj->count && while (temp <= cj->count && first_di > sort_j[temp].d)
  • Isn't this causing an array overflow ? When temp == cj->count the second argument is evaluated and sort_j[] is accessed beyond its range. Or is this not happening because I missed some other bit of the logic ?

  • Please register or sign in to reply
(sort_i[first_pi].d + (pi->h * kernel_gamma + dx_max - rshift) >
sort_j[temp].d))
temp++; temp++;
max_index_i[first_pi] = temp; max_index_i[first_pi] = temp;
...@@ -300,10 +299,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache( ...@@ -300,10 +299,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
for (int i = first_pi + 1; i < ci->count; i++) { for (int i = first_pi + 1; i < ci->count; i++) {
temp = max_index_i[i - 1]; temp = max_index_i[i - 1];
pi = &parts_i[sort_i[i].i]; pi = &parts_i[sort_i[i].i];
const float di = sort_i[i].d + pi->h * kernel_gamma + dx_max - rshift;
while (temp <= cj->count && while (temp <= cj->count && di > sort_j[temp].d)
(sort_i[i].d + (pi->h * kernel_gamma + dx_max - rshift) >
sort_j[temp].d))
temp++; temp++;
max_index_i[i] = temp; max_index_i[i] = temp;
...@@ -335,11 +334,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache( ...@@ -335,11 +334,10 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
temp = ci->count - 1; temp = ci->count - 1;
const struct part *pj = &parts_j[sort_j[last_pj].i]; const struct part *pj = &parts_j[sort_j[last_pj].i];
const float last_dj = sort_j[last_pj].d - dx_max - pj->h * kernel_gamma + rshift;
/* Loop through particles in cell i until they are not in range of pj. */ /* Loop through particles in cell i until they are not in range of pj. */
while (temp > 0 && while (temp > 0 && last_dj < sort_i[temp].d)
sort_j[last_pj].d - dx_max - (pj->h * kernel_gamma) <
sort_i[temp].d - rshift)
temp--; temp--;
max_index_j[last_pj] = temp; max_index_j[last_pj] = temp;
...@@ -348,10 +346,9 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache( ...@@ -348,10 +346,9 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
for (int i = last_pj - 1; i >= 0; i--) { for (int i = last_pj - 1; i >= 0; i--) {
temp = max_index_j[i + 1]; temp = max_index_j[i + 1];
pj = &parts_j[sort_j[i].i]; pj = &parts_j[sort_j[i].i];
const float dj = sort_j[i].d - dx_max - (pj->h * kernel_gamma) + rshift;
while (temp > 0 && while (temp > 0 && dj < sort_i[temp].d)
sort_j[i].d - dx_max - (pj->h * kernel_gamma) <
sort_i[temp].d - rshift)
temp--; temp--;
max_index_j[i] = temp; max_index_j[i] = temp;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment