Skip to content
Snippets Groups Projects

Hashmap fixes

Merged Pedro Gonnet requested to merge hashmap_fixes into master
1 unresolved thread

Adds functionality to grow a hashmap, can be used to pre-allocate elements when the final size is known.

Fixes overflows on re-hashing, although I'm not too sure how to test this in practice.

Implements #587 (closed).

Edited by Matthieu Schaller

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
322 353
323 354 /* Loop around, trying to find our place in the world. */
324 355 while (!element) {
325 hashmap_grow(m);
356 hashmap_grow(m, 0);
  • Looking through the FOF code it seems hard to come up with an educated guess about the sizes of either of the two maps we use.

    Could we nevertheless start them with a generic size of 1000 or so? That will basically cost nothing memory-wise but will make us skip the initial growth phase.

  • I ran the EAGLE-25 on 32 MPI ranks triggering FOF every 500 steps in 10 separate runs and they all completed succesfully. I think this is all fine.

    Maybe @pdraper has other tests to suggest?

  • Author Developer

    to be safe, could you add a debug message to make sure the overflow actually happens?

  • I did:

    diff --git a/src/hashmap.c b/src/hashmap.c
    index 3ebf927..e8fc11f 100644
    --- a/src/hashmap.c
    +++ b/src/hashmap.c
    @@ -309,6 +309,9 @@ void hashmap_grow(hashmap_t *m, size_t new_size) {
                  If this happens, store the offending element in the strays buffer
                  for now. */
               else {
    +
    +           message("HASHMAP OVERFLOW");
    +
                 /* (Re)allocate strays buffer? */
                 if (strays_count == strays_size) {
                   hashmap_element_t *temp_buff;
    @@ -338,10 +341,15 @@ void hashmap_grow(hashmap_t *m, size_t new_size) {
       /* If we have any strays, add them back to the hashmap. This will inevitably
          trigger a rehashing, but that's not our problem. */
       if (strays_count) {
    +
    +    message("HASHMAP STRAY ELIMINATION");
    +
         for (size_t k = 0; k < strays_count; k++) {
           hashmap_put(m, strays[k].key, strays[k].value);
         }
         swift_free("hashmap_strays", strays);
    +
    +    message("HASHMAP DEALT WITH ALL STRAYS");
       }
     }
    

    It happened twice in all my runs. We survived in both cases.

  • I had a development branch that I thought tripped over this problem more frequently, but that doesn't seem to happen now! Since you've managed anyway, all looks good to go I guess.

  • All good for me unless @nnrw56 wants to pick up on my suggestion above to initialise the hash maps to 1000 or so.

  • Matthieu Schaller changed the description

    changed the description

  • Matthieu Schaller changed milestone to %Paris

    changed milestone to %Paris

  • Any last words on this from anyone?

  • mentioned in commit a3c1cc83

  • Please register or sign in to reply
    Loading