    

 ## On this page

  

 

 # Fast Execution 

 Last update: 16.07.2025 

Tweak performance of SoS during script exection.

-- deactivate graphics (save memory and cpu time when loading large FEM meshes)

-- this must be done before loading a reference mesh!

local old_state = sos.sceneManager():setGraphicsEnabled(false)

sos.sceneManager():setGraphicsEnabled(old_state) -- restore state



-- reduce level of graphics (save memory and cpu time when loading large FEM meshes)

-- this must be done before loading a reference mesh!

local old_state = sos.sceneManager():setGraphicsSlicingEnabled(false)

--sos.sceneManager().setGraphicsSlicingEnabled(old_state) -- restore state





-- deactivate command file logging (for autosave) which saves time when processing script files, e.g. in for-loops over n-1000 items:

local old_state = sos.useCommandLogFile(false)

for i=1,1e6 do

 local b = 6*i; -- do something

end

sos.useCommandLogFile(old_state) -- restore state



-- define the maximum number of CPU threads to be used in parallelized algorithms

-- reduction of CPU time may also reduce the RAM usage

sos.setMaxNumThreads(2) -- maximum 2 threads

sos.setMaxNumThreads(0) -- default: either the OpenMP system setting (e.g. as set in environment variable ) or all CPU cores



-- reduce log level (if number of messages reduce performance)

sos.setLogLevel(1) -- only error messages

sos.setLogLevel(3) -- default



-- load FEM meshes from an SDB file without creating information for closest point projection (e.g. FEM mesh topology) saves time:

sdbfile = sos.currentScriptPath() .. "/../lsdyna/metal_forming__eroded_elements/sos_demo.sdb"

local success_code,err_info = pcall( function()

 local settings = sos.LoadDataBaseSettings(sdbfile);

 settings.create_reference_mesh = false

 sos.loadDataBase(sos.database(), settings);

end );



 print("ERROR: The requested optimized code does only work in batch mode. ")

 print("Redo action with non-optimized settings")

 local settings = sos.LoadDataBaseSettings(sdbfile);

 sos.loadDataBase(sos.database(), settings);

end





print("Terminate script with success.")