-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove strcat_alloc() #4020
Labels
Comments
Shouldn't it first be discussed if a string log is really the best way to report back from the tuning? |
I would be fine with a logger or a printf. Also, there are 2 memory leaks with the tuning code, but that shouldn't surprise anyone... diff --git a/src/core/electrostatics_magnetostatics/p3m.cpp b/src/core/electrostatics_magnetostatics/p3m.cpp
index 70918abbc..139cf58d5 100644
--- a/src/core/electrostatics_magnetostatics/p3m.cpp
+++ b/src/core/electrostatics_magnetostatics/p3m.cpp
@@ -1140,4 +1140,12 @@ int p3m_adaptive_tune(char **log) {
time_best);
*log = strcat_alloc(*log, b);
+ constexpr size_t N = 500*1024*1024;
+ char buffer[N];
+ for (size_t i = 0; i < N; ++i)
+ buffer[i] = '\n';
+ buffer[N-1] = '\0';
+ printf("(allocating %.0f MB in the core)\n", sizeof(buffer) / 1024. / 1024.);
+ *log = strcat_alloc(*log, buffer);
+ (*log)[0] = '\0';
return ES_OK;
} import os, psutil, espressomd.electrostatics
process = psutil.Process(os.getpid())
ram = lambda: print(f'{process.memory_info().rss / 1024. / 1024.:.0f} MB')
system = espressomd.System(box_l=3*[1], time_step=0.01)
system.part.add(pos=[[0,0,0],[1,0,0]], q=[-1,1])
ram() # should print 88 MB
p3m = espressomd.electrostatics.P3M(prefactor=1.0, accuracy=1e-2)
system.actors.add(p3m) # start tuning
ram() # should print 98 MB Output:
|
kodiakhq bot
added a commit
that referenced
this issue
Dec 23, 2020
Fixes #4020 Description of changes: - replaced manual string `char*` construct with `std::printf` - introduced verbose parameter to touched tuning functions and interfaces - removed `utils/strcat_alloc.hpp` with unit tests - added missing `handle_errors` call in p3m_gpu_init
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Utils::strcat_alloc()
appends a C-string to a char array with manual memory management. This utility function is one of the last consumers of the ESPResSo manual memory management toolset (#2900), the others being EK and LB that are currently being rewritten in the waLBerla branch.Here is a typical use of
Utils::strcat_alloc()
:The same can be achieved with a
std::string
:Affected files:
p3m.cpp
,p3m-dipolar.cpp
,mmm1d.cpp
to remove calls toUtils::strcat_alloc()
, andelectrostatics.pxd
,magnetostatics.pxd
to replacechar ** log
bystring &log
fromlibcpp.string
. After that, the utility function and its unit test can be removed.The
sprintf()
statements do not need to be modified. They have two modernstd::string
equivalents, but they cannot be used out-of-the-box:std::format
is a C++20 feature,boost::format
uses a different syntax. Anyway, thesesprintf()
calls are found in functions that are probably going to be rewritten in Python in the future, so further beautification isn't worth it.The text was updated successfully, but these errors were encountered: