Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects

Fix reading multibunch injection file *-onebunch.h5

Merged frey_m requested to merge AMAS-members/frey_m/codes/src:master into master

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
1721 throw OpalException("ParallelCyclotronTracker::readOneBunchFromFile()",
1722 "No particles in file " + onebunch_m + ".");
1723 }
1719 1724
1720 long numParticles = dataSource.getNumParticles();
1721 1725 size_t numParticlesPerNode = numParticles / Ippl::getNodes();
1722
1726
1723 1727 size_t firstParticle = numParticlesPerNode * Ippl::myNode();
1724 1728 size_t lastParticle = firstParticle + numParticlesPerNode - 1;
1725 1729 if (Ippl::myNode() == Ippl::getNodes() - 1)
1726 1730 lastParticle = numParticles - 1;
1727 1731
1728 1732 numParticles = lastParticle - firstParticle + 1;
1733
1729 1734 PAssert_GE(numParticles, 0l);
  • After the change of numParticles type from long to size_t I get the (valid) compiler warning that this assert is always true.

  • Author Maintainer

    Does the warning tell you a line? I didn't get this.

  • Yes, this line, 1734. The inequality numParticles>=0l will always be true. Not sure if it should be replaced by something else. The compiler full warning:

    home/scratch/OPAL/src/src/Algorithms/ParallelCyclotronTracker.cpp: In member function bool ParallelCyclotronTracker::readOneBunchFromFile(size_t):
    /home/scratch/OPAL/src/ippl/src/Utility/PAssert.h:124:40: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
     #define PAssert_GE(a, b) PAssert_CMP(a >= b, a, b)
                                            ^
    /home/scratch/OPAL/src/ippl/src/Utility/PAssert.h:118:38: note: in definition of macro PAssert_CMP
     #define PAssert_CMP(cmp, a, b) if (!(cmp)) toss_cookies(#cmp, #a, #b, a, b, __F
                                          ^
    /home/scratch/OPAL/src/src/Algorithms/ParallelCyclotronTracker.cpp:1734:5: note: in expansion of macro PAssert_GE
         PAssert_GE(numParticles, 0l);
         ^
  • Author Maintainer

    Either we replace this with PAssert_EQ or we remove my check at line 1720. Actually, I've overseen this additional check ...

  • Developer

    Why not just remove this assertion? It's not needed any more when using an unsigned data type.

  • Up to you. numParticles is redefined in line 1732 (to the number of particles in the node). So in theory it could make sense to check two times. But from the logic I would think that the calculation in line 1732 can't be negative (or have an overflow), so one could remove line 1734 I think.

  • Sure, but if firstParticle > lastParticle it would not end well, which is what the assert used to check.

  • Developer

    Well then we should check that firstparticle <= lastparticle.

  • Developer

    PAssertLE(firstParticle, lastParticle)

  • Author Maintainer

    I removed it (see c6253ca8).

    I can add this check but lastParticle cannot be smaller (equal) than firstParticle

    size_t firstParticle = numParticlesPerNode * Ippl::myNode();
    size_t lastParticle = firstParticle + numParticlesPerNode - 1;
  • Author Maintainer

    So just to be safe 7fc28948

  • Developer

    What if numParticlesPerNode = 0?

  • Author Maintainer

    This would be bad. But still lastParticle cannot be smaller since size_t is unsigned. Since 1 is subtracted, lastParticle would be the maximum value of size_t.

  • Author Maintainer

    So, numParticlesPerNode can only be equal zero if Ippl::getNodes > numParticles. It would be better to check this.

  • Developer

    Or you check PAssert_LT(firstParticle, lastParticle +1)

  • Author Maintainer

    I think this assert is less clear to understand the code. Checking the number of particle and the number of nodes is more clear for code reading, I assume.

  • Agreed. Also to add that PAssertLE should be PAssert_LE (now master doesn't compile).

  • Developer

    But it's valid to have less particles than nodes (however not advisable :) )

  • Author Maintainer

    I agree.

  • In case of heavy collimation, in theory this can happen: unlikely but not forbidden.

  • Author Maintainer

    One could overcome this issue by setting firstParticle = lastParticle = 0 for all ranks > numParticles, but I don't know if H5 is happy about this.

  • Author Maintainer

    @snuverink_j I fixed the underscore bug in the assert. So, the master compiles fine again.

  • Please register or sign in to reply
  • Please register or sign in to reply
    Loading