Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. Analysis & Postprocessing
  4. Memory issues when exporting large multiport simulations

Memory issues when exporting large multiport simulations

Scheduled Pinned Locked Moved Analysis & Postprocessing
3 Posts 2 Posters 484 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PeterStijnmanP Offline
    PeterStijnmanP Offline
    PeterStijnman
    wrote on last edited by
    #1

    As the title states I currently have issues with exporting large multiport simulations. After about 9 out of 16 ports my memory is full and the python script crashes. I tried calling the garbage collection manually, but this does not free any memory. Does someone know a solution to free allocated memory in sim4life (version 3.4)?

    Cheers!

    1 Reply Last reply
    0
    • SylvainS Offline
      SylvainS Offline
      Sylvain
      ZMT
      wrote on last edited by
      #2

      Hi Peter, the short answer is that you can't free this allocated memory. This is a known issue with Sim4Life's Python API. What happens is that the postprocessing algorithms instantiated by the Python functions create some C++ data objects to hold the actual bulk of the data: the same memory blocks can be accessed by Sim4Life's C++ code, or by the user's Python script. Unfortunately, deleting the Python objects does not always deallocate the C++ data objects. This can result in memory leaks, similar to what you described.

      The workaround is to not allocate too much memory in the first place, by reusing existing algorithms instead of creating new ones. It is possible to only change the inputs of an algorithm and update it. Here is an example that exports the E fields of each port of a multiport simulation as Matlab files, but only allocate memory for one port:

      	# Creating the analysis pipeline
      	# Adding a new EmMultiPortSimulationExtractor
      	simulation = document.AllSimulations["Patch Antenna - Multiport"]
      	em_multi_port_simulation_extractor = simulation.Results()
      
      	#Create the postprocessing pipeline once
      	output_port = em_multi_port_simulation_extractor.Outputs[0]
      	# Adding a new EmPortSimulationExtractor
      	em_port_simulation_extractor = analysis.extractors.EmPortSimulationExtractor(inputs=[output_port])
      	em_port_simulation_extractor.UpdateAttributes()
      	document.AllAlgorithms.Add(em_port_simulation_extractor)
      
      	# Adding a new EmSensorExtractor
      	em_sensor_extractor = em_port_simulation_extractor["Overall Field"]
      
      	document.AllAlgorithms.Add(em_sensor_extractor)
      
      	# Adding a new MatlabExporter
      	inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
      	matlab_exporter = analysis.exporters.MatlabExporter(inputs=inputs)
      	matlab_exporter.UpdateAttributes()
      	document.AllAlgorithms.Add(matlab_exporter)
      		
      		
      	# Update the postprocessing pipeline for each port
      	for i, output_port in enumerate(em_multi_port_simulation_extractor.Outputs):
      		em_port_simulation_extractor.raw.SetInputConnection(0, output_port.raw) # this is the main "trick"
      		em_port_simulation_extractor.UpdateAttributes()
      
      		inputs = [em_sensor_extractor.Outputs["EM E(x,y,z,f0)"]]
      		matlab_exporter.FileName = u"D:\\temp\\ExportedData_{}.mat".format(i)
      		print matlab_exporter.FileName
      		matlab_exporter.UpdateAttributes()
      		matlab_exporter.Update()
      1 Reply Last reply
      1
      • PeterStijnmanP Offline
        PeterStijnmanP Offline
        PeterStijnman
        wrote on last edited by
        #3

        Okay awesome, I think this will do the trick :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Search