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

Repeat call of gmse_apply causes crash #47

Closed
bradduthie opened this issue Nov 29, 2018 · 2 comments
Closed

Repeat call of gmse_apply causes crash #47

bradduthie opened this issue Nov 29, 2018 · 2 comments
Assignees
Labels
bug Bugs to address in GMSE code To do Things to do to improve GMSE

Comments

@bradduthie
Copy link
Member

The unresolved problem

As discovered by @jeremycusack -- if the function gmse_apply is called repeatedly with the same old_list, then R will crash. The code below replicates the crash.

sim1 <- gmse_apply(get_res = "Full");
sim2 <- gmse_apply(get_res = "Full", old_list = sim1);
sim3 <- gmse_apply(get_res = "Full", old_list = sim1);

The problem is a bit perplexing because the crash happens even if sim2 is removed and gc() called before running the third line above. The problem also does not occur if alternate functions are run in gmse_apply, which leads me to believe that the issue is with C. Specifically, it appears that the cause of the crash is related to the resource function.

The reason that the crash occurs is that the old_list is somehow modified in the process of running gmse_apply. Specifically, the sim$PARAS[33] is updated to the new resource model. I will figure out how to stop this from happening.

A temporary workaround fix

Here is a way to avoid the crash; it should be emphasised that this is really only needed if gmse_apply needs to be called with the exact same old_list. The crash will not occur if the old list differs among calls to gmse_apply, as typically will occur within a loop where the output is constantly being updated and the new gmse_apply call pulling results in from the most recent call. The workaround requires copying sim1 into two separate objects, saving each of those two objects, deleting all three objects, then reloading the two copied objects. Below is a successful example.

sim1  <- gmse_apply(get_res = "Full");
sim1a <- sim1;
sim1b <- sim1;
save(sim1a, sim1b, file = "sims.RData");
rm(sim1);
rm(sim1a);
rm(sim1b);
invisible(gc()); # Garbage collect to remove all junk
load("sims.RData");
sim2 <- gmse_apply(get_res = "Full", old_list = sim1a);
sim3 <- gmse_apply(get_res = "Full", old_list = sim1b);

Now we have successfully created a sim2 and sim3 run from the same old_list. Note that we can recover sim1 by just defining sim1 <- sim1a.

@bradduthie bradduthie added bug Bugs to address in GMSE code To do Things to do to improve GMSE labels Nov 29, 2018
@bradduthie bradduthie self-assigned this Nov 29, 2018
@bradduthie bradduthie changed the title Repeate call of gmse_apply causes crash Repeat call of gmse_apply causes crash Nov 29, 2018
@bradduthie
Copy link
Member Author

It appears that the problem needs to be solved in C. I think this goes back to me reading in PARAS differently than I have been. I think that if I resolve Issue #46 this will fix this issue too.

bradduthie added a commit that referenced this issue Dec 1, 2018
…-- submitting to CRAN should now be easier, as it will be possible to increase the length of the PARAS vector
@bradduthie
Copy link
Member Author

bradduthie commented Dec 1, 2018

With the commit 26a1d9f7e7180bae4e77b6aa1779baf1554831b7, this issue is now resolved and a new GMSE version has been created. See previous commits leading up to this version to note the changes made to four C files. The bug was caused by a memory management issue in C, where C updated an old vector of parameter values, but it should have been copying the vector and creating a new one. I am now closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs to address in GMSE code To do Things to do to improve GMSE
Projects
None yet
Development

No branches or pull requests

1 participant