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

Update GunnsRosesTiming.cpp - memory management and the use of null p… #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexTodorov11
Copy link

Replacing manual memory management with std::unique_ptr for automatic deallocation, eliminating unnecessary null pointer checks. A division-by-zero risk in update() was also addressed by adding a safeguard.

  • Using raw pointers (network) risks memory leaks. Switching to std::unique_ptr would be safer.
  • N /= step in update() risks dividing by zero if step is zero.
  • Lack of try-catch blocks may lead to crashes if exceptions occur.
  • In dumpIslands(), vector size should be checked before accessing elements to avoid out-of-bounds errors.
  • Missing error handling during GPU/CPU mode transitions could lead to issues.

…ointers

Replacing manual memory management with std::unique_ptr for automatic deallocation, eliminating unnecessary null pointer checks. A division-by-zero risk in update() was also addressed by adding a safeguard.
Copy link
Contributor

@jasonlharvey jasonlharvey left a comment

Choose a reason for hiding this comment

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

Thanks for the submission! I have some changes & questions, please address my review comments and resubmit. See the submission guidelines wiki: https://github.com/nasa/gunns/wiki/Open-Source-Submission-Guidelines#how-to-submit-changes. Please reference issue #132 in your commit messages. Thanks!

if (N_STEPS <= step) {
storePotentials();
// dumpA();
Copy link
Contributor

Choose a reason for hiding this comment

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

I want to keep these 2 'dump' calls in, and commented out, so that we can uncomment them for debugging. Please restore these lines and resubmit. If you want, you can add a comment like "these are for debugging, uncomment as needed", etc.

if (errCheck) {
double error = 0.0;
for (unsigned int i=0; i<5; ++i) {
error += std::fabs(gpuPotentials[i] - cpuPotentials[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change to std::abs and resubmit. We're trying to adhere to a new coding standard that explicitly uses the standard library namespace for all such math functions.

if (errCheck) {
double error = 0.0;
for (unsigned int i=0; i<5; ++i) {
error += std::fabs(gpuSparsePotentials[i] - cpuPotentials[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change to std::abs and resubmit. We're trying to adhere to a new coding standard that explicitly uses the standard library namespace for all such math functions.

printf("\nTerminating sim:\n");
exec_terminate("", ""); // from Trick's exec_proto.h, tell Trick to kill the sim
Copy link
Contributor

Choose a reason for hiding this comment

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

We need this to terminate the sim. Please restore this line and resubmit.

printf("\nTerminating sim:\n");
exec_terminate("", ""); // from Trick's exec_proto.h, tell Trick to kill the sim
delete network; // Deallocate the network
step = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of these additions 169 - 176? We are terminating the sim, nothing more needs to be done.

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.

2 participants