Repository navigation
Replacement of Class Referenced with std::shared_ptr - #541
JanNiklasB wants to merge 53 commits into
Conversation
(intern calls need to be adjusted)
ref_ptr now acts like a normal smart pointer and is able to hold a reference by using ref_ptr(T& obj)
comment previously commented test for now, search fix later
|
Turns out the issue was caused by the |
The following changes are included: - Optional python (now not required to build crpropa) - Limit in secondary samples in tests to limit necessary memory - Some performance adjustments
|
I discussed the modification of I also ran the test with the 1000 max sample limit 1000 times on our cluster to check if I encounter any fails (the test takes about 1ms) , and so far I did not encounter any. |
…' into ReferencedClassRemoval
…_VERSION tag for plugins
…t when writing plugins
|
Hi @JanNiklasB, Thanks for the PR. Out of curiosity: does this affect the performance? I haven't looked into the code in detail (nor do I think I will have time this week, so someone else might want to test it), but something I've noticed is that there seems to be a lot of outdated code in the commit (like deleting Eigen, lenses, etc), probably because you started working on this before 3.3. |
|
Yes, there is a lot of outdated code, I am currently working on migrating the new changes to this PR. |
- Merge CRPropa#569 - Workaround by manually specifying `LD_LIBRARY_PATH` and `CRPropa_INSTALL_PREFIX`
|
This PR is now ready for review! |
JulienDoerner
left a comment
There was a problem hiding this comment.
Hey @JanNiklasB, I think this PR already looks quite good. I have only a couple of minor comments.
| "Replace it with a more appropriate turbulent field model instance."; | ||
| HelicalGridTurbulence::initTurbulence(grid, Brms, lMin, lMax, alpha, seed, | ||
| H); | ||
| << "initTurbulence is deprecated and will be removed in the future. " |
There was a problem hiding this comment.
should we remove this one? It is already long time deprecated?
There was a problem hiding this comment.
oh, I am confused how that is there, I do not remember changing this (it has nothing to do with this PR and must come from an older version or something).
There was a problem hiding this comment.
Yes it is already older and you just applied the style convention. But I noticed it now, and we should remove it.
There was a problem hiding this comment.
We should remove it in another PR, I will set this line as it is in the master currently for now.
| void setPhotonField(ref_ptr<PhotonField> photonField, bool superheavy = false); | ||
|
|
||
| // decide if secondary photons are added to the simulation | ||
| /// decide if secondary photons are added to the simulation |
|
|
||
| /** Merge other maps, add pdfs */ | ||
| void merge(const EmissionMap *other); | ||
| void merge(ref_ptr<const EmissionMap> other); |
There was a problem hiding this comment.
Are those EmissionMap Pointers available in swig?
| * before continuing with the primary candidate if secondariesFirst is set to true | ||
| */ | ||
| void run(SourceInterface* source, size_t count, bool recursive = true, bool secondariesFirst = true, bool waitForSecondaries = true); | ||
| void run(ref_ptr<SourceInterface> source, size_t count, bool recursive = true, bool secondariesFirst = false, bool waitForSecondaries = true); |
There was a problem hiding this comment.
Why are you changing the default behavior of the secondariesFirst flag?
There was a problem hiding this comment.
no reason, this was by mistake during the last merge
| TEST(Candidate, clone){ | ||
| Candidate c( | ||
| nucleusId(1, 1), // id | ||
| 1*keV, // energy |
There was a problem hiding this comment.
Although this test will work as intended, I would suggest using relativistic energies here (e.g. 1 EeV). At the moment, an energy of
| TEST(Candidate, cloneRecursive){ | ||
| Candidate c( | ||
| nucleusId(1, 1), // id | ||
| 1*keV, // energy |
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: "3.3" |
There was a problem hiding this comment.
If I understand the logic correctly, this will test the old CRPropa version 3.3 with the plugin template at this point, not the new plugin with your compatibility check.
There was a problem hiding this comment.
yes, somehow I did not think about this, but yes the plugin template is also set to 3.3 .
Pulling the 3.3 repository manually and installing it should fix it.
|
While doing the performance tests I noticed how slow This is mainly caused by the excessive use of Here are some plots that compare the current PR with the last release, there you can see how much slower the code would get (the code which I used to create these can be found in this codespace.
I want to see if I can find a workaround where we have the same or better performance as with the Referenced class since I really want to get rid of it. If I do not find anything I will close this PR. |
|
I went through possible Ideas together with @JulienDoerner and thought about what I could do to achieve similar performance to the current release:
Option 1 and 2 would require massive amounts of work just to achieve similar performance, since after all, it is always faster to use a raw pointer then any smart pointer since the smart pointer always needs to do at least additional checks. Besides from just removing the
I will make a PR in the next few days for each of those points. @JulienDoerner and I think it would be best to set this PR as a draft again until the next CRPropa call instead of just closing it. As a conclusion, I think this PR shows us that the |



Hi,
as discussed in the workshop I want to replace the
Referencedclass withstd::shared_ptr.Referencedwas used to reference count in crpropa versions that required C++ standards lower then C++11, however since C++11 thestd::shared_ptrtemplate class was introduced as a better manageable smart pointer provided by C++.To properly use
std::shared_ptrinstead ofReferencedsome other general modifications needed to be done:ref_ptrmight be converted into a raw pointer and then back into aref_ptrwhich would cause the reference count of thestd::shared_ptrto not be synced anymore and therefore might cause the unintended deletion of pointers.ref_ptrfor theprocessfunctions. This breaks most plugins, but I provided an easy fix which can just be copy pasted in the README.mdThe following will work the same as before:
ref_ptr<Candidate> c = new Candidate();std::shared_ptrwhen converted toref_ptrin function call)Some other changes include:
Contribute.md)AssocVecbystd::unordered_mapClockbystd::chrono::high_resolution_clockTEST(Candidate, clone)andTEST(Candidate, cloneRecursive).vscodeadded to.gitignore, this is a folder that is automatically generated by Visual Studio Code and should never be committedVersion.h.inso plugins can easily check which code version they building against.I marked this PR as Draft for now (currently CRPropa3.2.1) so it is clear that we only intend to add this after we release CRPropa3.3.0 . Furthermore, with the upcoming #535 and the heavy nuclei PR this PR would only delay the 3.3 release more, so considering that and the required changes to this PR when the mentioned PRs are merged I think a draft PR is the best choice.