Skip to content
Snippets Groups Projects
Commit 17e3d5cf authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Fix the same issue as #646 (MR \!1000) but now in the allocation of extra gpart

parent d9e35276
No related branches found
No related tags found
No related merge requests found
......@@ -158,7 +158,6 @@ void space_allocate_extras(struct space *s, int verbose) {
if (swift_memalign("gparts", (void **)&gparts_new, gpart_align,
sizeof(struct gpart) * size_gparts) != 0)
error("Failed to allocate new gpart data");
const ptrdiff_t delta = gparts_new - s->gparts;
memcpy(gparts_new, s->gparts, sizeof(struct gpart) * s->size_gparts);
swift_free("gparts", s->gparts);
s->gparts = gparts_new;
......@@ -166,23 +165,10 @@ void space_allocate_extras(struct space *s, int verbose) {
/* Update the counter */
s->size_gparts = size_gparts;
/* We now need to reset all the part and spart pointers */
for (size_t i = 0; i < nr_parts; ++i) {
if (s->parts[i].time_bin != time_bin_not_created)
s->parts[i].gpart += delta;
}
for (size_t i = 0; i < nr_sinks; ++i) {
if (s->sinks[i].time_bin != time_bin_not_created)
s->sinks[i].gpart += delta;
}
for (size_t i = 0; i < nr_sparts; ++i) {
if (s->sparts[i].time_bin != time_bin_not_created)
s->sparts[i].gpart += delta;
}
for (size_t i = 0; i < nr_bparts; ++i) {
if (s->bparts[i].time_bin != time_bin_not_created)
s->bparts[i].gpart += delta;
}
/* We now need to correct all the pointers of the other particle arrays */
part_relink_all_parts_to_gparts(gparts_new, s->nr_gparts, s->parts,
s->sinks, s->sparts, s->bparts,
&s->e->threadpool);
}
/* Turn some of the allocated spares into particles we can use */
......
  • Author Owner

    @folkert and @lhausammann.

    That solves the mystery. Taking a ptrdiff_t between two pointers and using this as "delta" in another array is actually a so-called undefined behaviour. GCC implements this as we expect. ICC does not. (And both are correct as the standard does not say what to do)

    This means that extra gpart likely never worked with the intel compiler until now.

  • Author Owner

    @folkert I also pushed the exact same fix to your branch.

  • Contributor

    Hi,

    Thanks for fixing that, I think I would have never been able to figure out. I am a bit surprised that this is undefined.

  • Author Owner

    It's lucky that I had spent days scratching my head about !1000 (merged) in the past and that I remembered. This is really an obscure part of C...

  • Contributor

    Hi Matthieu, thanks for fixing this!

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment