# Exceeding the "memory pool" in WSM

GROUPS:
 Eric Smith 1 Vote I know there are much larger systems simulated than the one I have, so this should be an easy question:I have a network of about 200 "Short Pipes" and 200 "Point Volumes" from the Media library. It runs just fine if I cut that down to about 100 each. But I'm getting this error in Simulation Center in the Simulation Log Assertion failed: (current_state.char_buffer_ptr + n < NR_CHAR_ELEMENTS), function char_alloc, file /Users/jenkins/workspace/Kernel-5.0.X/label/OSX/MCOpenModelica/c_runtime/memory_pool.c, line 181. Looking at the memory pool header file it looks like NR_CHAR_ELEMENTS is a hardcoded limit designed for 1998 computers. Is there a place to increase this or change my code to avoid the error?
7 months ago
16 Replies
 Neil Singer 2 Votes Eric,You may have to wait for the people in Sweden to help you out on this but I took a quick look at the memory_pool.h file in WSM and that value is set to 20,000,000. It would surprise me if you could legitimately exceed that -- it must be some kind of bug.You can find the file on a mac by showing the contents of the SystemModeler app and going to Contents->include. You can certainly try increasing it (although a backup copy would be a great idea!). I would try to look at the source with view->Generated Source Code to find the line that is causing the trouble and see if you can figure out what is going on. It is strange to me that you are even using anything that involve CHAR elements in a model of pipes.RegardsNeil
7 months ago
 Neil, 20,000,000 is in the header file and I definitely don't have that many outputs. Thanks for finding the header file. It doesn't look like the c file is in the directory though, so I can't see what line 181 is in "memory_pool.c"
7 months ago
 Patrik Ekenberg 2 Votes Hi Eric,I realize you might not want to share the full model, but could you tell me if the attached model is roughly similar to what you are trying to model? I tried to reconstruct it from your description and I am not able to reproduce the error even with 300 pipes. Attachments:
7 months ago
 Eric Smith 1 Vote Patrik, there's nothing proprietary here. Just some simple test cases at this point. I've attached the two files you'd need. The file that I'm talking about is "MultipleSectionNetwork.mo" the only non-Media library file that it relies on is "DryGasPipeline.TwoPort" Attachments:
7 months ago
 I ran your code and got the same error from my code. Something must be strange with my install. I'm running on a Mac. Since I have a network license and Parallels, let me try on Windows. I'll report back soon.
7 months ago
 The model worked fine in Windows. Would you be able to check if there is an issue with the Mac version in general or if it's a setting on my computer? I'm running macOS High Sierra 10.13.2, Kaby Lake 2.8 GHz i7
7 months ago
7 months ago
 I tried to run it on my mac but you are missing some models:PipeOnePipe.MediumCan you post the entire package zipped?Regards
7 months ago
 Neil, the site wouldn't let me upload a zip file. I added the two files (not sure why "OnePipe" was needed).Alternatively, run Patrik's code. I hit the same problem with it, but his doesn't rely on my custom components. Attachments:
7 months ago
 Neil Singer 1 Vote Patrik,It appears that there is a bug in the Mac version of WSM. I get the same error as Eric running your posted code (PipeVolumeSystem). It appears that a hard path is burned into the code because there is no user "Jenkins" on my machine (nor presumably on Eric's). I am even running it on the WSM version (the number of which I emailed you yesterday) and it crashes./Users/jenkins/workspace/Kernel-ci/label/OSX/SystemModeler/Kernel/cruntime/memorypool.c, line 181.If I manually build the program it builds but does not run -- it throws the error at runtime. My guess is that there is an error in one of the Library files that overflows on such a large _init.sim file. Using 200 runs but 300 fails. The file reference must be embedded inside the library. I hope that helps.Regards
7 months ago
 Thanks for confirming, Neil. Patrik, would you be able to send me a build with the patch? What's a rough timeframe to get this fixed? Thanks, Eric
7 months ago
 Patrik Ekenberg 1 Vote Hi Eric,We believe we have narrowed down the cause of the issue. To put it shortly, the issue seems to be caused by an excessive amount of potential assert messages that are being prepared (a few for each of the pipe sections). When they contain dynamic information from the model, such as:  assert(p >= 0.0, "Pressure (= " + String(p) + " Pa) of medium \"" + mediumName + "\" is negative\n(Temperature = " + String(T) + " K)"); These currently need to be pre-allocated. We are currently working on a fix to avoid this. I'll let you know when I have a rough time-frame. A fix that can be applied in the mean time would be to make a slightly modified copy of the medium model, where all assert strings are constants, like:  assert(p >= 0.0, "Pressure of medium is negative"); I could help you with that. Is Modelica.Media.Air.SimpleAir the medium you are looking to use in your test models?Regards, Patrik
7 months ago
 Interesting Patrik, nice work finding that. SimpleAir would be fine if you want to send a patched medium file.If there is a good regex expression I could use, please send that as well. I’ll make copies of the other media I want to use and do a regex find-replace in a text editor.Please keep me in the loop on a more permanent fix.