This is a fix of a really inefficient implementation of how Material and ThermalScattering are linked together during problem setup. The issue is that in MCNP_Problem:
for data_input in self.data_inputs:
data_input.update_pointers(self.data_inputs)
This in itself isn't an issue; this is just an O(N) operator, and it's necessary.
But inside of both Material and ThermalScattering there was:
def update_pointers(self, data_innputs):
for data_input in data_inputs:
...
So this effectively became:
for data_input_1 in data_inputs:
for data_input_2 in data_inputs:
...
This is an O(N2) operation. Yikes!
To fix this, I changed:
Removed all code from Material.update_values
Move all linking to ThermalScattering.update_value
Use problem.materials hashing as much as possible to perform the linking operation.
This changes the benchmark run time from 424 seconds to 26 second, a speed up of 398 seconds, or 93%.
Description
This is a fix of a really inefficient implementation of how
Material
andThermalScattering
are linked together during problem setup. The issue is that inMCNP_Problem
:This in itself isn't an issue; this is just an O(N) operator, and it's necessary.
But inside of both
Material
andThermalScattering
there was:So this effectively became:
This is an O(N2) operation. Yikes!
To fix this, I changed:
Material.update_values
ThermalScattering.update_value
problem.materials
hashing as much as possible to perform the linking operation.This changes the benchmark run time from 424 seconds to 26 second, a speed up of 398 seconds, or 93%.
The old profiling of the benchmark test:
With the vast majority of the costliest operations all being in
montepy.data_inputs.Material
, withupdate_pointers
taking > 250 seconds.After this change the new profiling is:
Now this operation takes 1.5 seconds.
Fixes #510
Checklist