Skip to content
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

Some performance tweak #687

Merged
merged 56 commits into from
Apr 1, 2022
Merged

Some performance tweak #687

merged 56 commits into from
Apr 1, 2022

Conversation

davidhjp01
Copy link
Contributor

@davidhjp01 davidhjp01 commented Mar 2, 2022

Following updates are for further performance improvement:
1.Additional placement of LIBCOSIM_NO_FMI_LOGGING for disabling logging in step_finished_placeholder

  1. Removed step_finished_placeholder and assigned nullptr to the callback pointer.
  2. Now cosim::slave::get_variables does not create cosim::slave::variable_values for each time it's invocation, instead copies data to the argument that is passed to the function.
    • This changes the use of get_variables, see the updated test cases.
  3. In set_variable_cache::modfiy_and_get, std::unordered_map<value_reference, size_t> back_refs_ is used to only update variable values that are subject to modification (via modifier). This avoids unnecessary iteration of all variables in each simulation step.

Copy link
Member

@eidekrist eidekrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a long time since I've looked at this code :) The changes in the fmu.cppclasses LGTM, I've left a comment in slave_simulator.cpp.

values_[i] = iterator->second(values_[i], deltaT);
const auto it = back_refs_.find(ref);
if (it != back_refs_.end()) {
values_[it->second] = entry.second(values_[it->second], deltaT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering about the need for back_refs_. Isn't the array index (it->second here) stored in exposedVariables_.at(ref).arrayIndex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, adjusted accordingly.

src/cosim/fmi/v1/fmu.cpp Outdated Show resolved Hide resolved
@@ -227,14 +227,10 @@ class set_variable_cache
references_.emplace_back(ref);
values_.emplace_back(exposedVariables_.at(ref).lastValue);
}
const auto index = exposedVariables_.at(ref).arrayIndex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are talking performance;
exposedVariables_.at(ref) is called at least two times in this loop. It might make sense to define it as a local variable before line 224.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated accordingly.

Copy link
Member

@restenb restenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

gsl::span<const value_reference> real_variables,
gsl::span<const value_reference> integer_variables,
gsl::span<const value_reference> boolean_variables,
gsl::span<const value_reference> string_variables) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was const removed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it back, I think I removed it in the previous version (but not needed in the final version).

Base automatically changed from parallel-pool to master March 31, 2022 07:12
# Conflicts:
#	include/cosim/slave.hpp
#	src/cosim/slave_simulator.cpp
#	tests/proxyfmu_integration_unittest.cpp
@davidhjp01 davidhjp01 merged commit b7c02da into master Apr 1, 2022
@davidhjp01 davidhjp01 deleted the parallel-pool-opt branch April 1, 2022 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants