Skip to content

Commit

Permalink
Moved randseed to former location, added randseed calls to ST_grid.c
Browse files Browse the repository at this point in the history
Issue #256. Moving the randseed calls to before RunGrid() was resulting in different behavior with the same seed. To remedy this I have moved calls to randseed back to their former location, and added separate randseed calls in ST_grid.c in the equivalent location right after Plot_Initialize().
  • Loading branch information
Chandler Haukap committed Apr 10, 2019
1 parent ed2bc25 commit 97a6d4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 14 additions & 0 deletions ST_grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ extern SW_SITE SW_Site;
extern SW_VEGPROD SW_VegProd;
extern SW_WEATHER SW_Weather;
extern pcg32_random_t grid_rng; //this file's unique random number generator
extern pcg32_random_t environs_rng;
extern pcg32_random_t mortality_rng;
extern pcg32_random_t resgroups_rng;
extern pcg32_random_t species_rng;
extern pcg32_random_t grid_rng;
extern pcg32_random_t markov_rng;

//This is Rgroup structure pointer that will read rgroup disturbance value, will be used in
// grid disturbance
Expand Down Expand Up @@ -455,6 +461,14 @@ void runGrid(void)
parm_Initialize(iter);

Plot_Initialize();

RandSeed(Globals.randseed, &environs_rng);
RandSeed(Globals.randseed, &mortality_rng);
RandSeed(Globals.randseed, &resgroups_rng);
RandSeed(Globals.randseed, &species_rng);
RandSeed(Globals.randseed, &grid_rng);
RandSeed(Globals.randseed, &markov_rng);

if (iter > 1)
_free_grid_globals(); //frees the memory from when we called _load_grid_globals() last time... (doesn't need to be called on the first iteration because the memory hasn't been allocated yet)

Expand Down
14 changes: 7 additions & 7 deletions ST_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ int main(int argc, char **argv) {

printf("STEPWAT init_args() executed successfully \n");

RandSeed(Globals.randseed, &environs_rng);
RandSeed(Globals.randseed, &mortality_rng);
RandSeed(Globals.randseed, &resgroups_rng);
RandSeed(Globals.randseed, &species_rng);
RandSeed(Globals.randseed, &grid_rng);
RandSeed(Globals.randseed, &markov_rng);

if (UseGrid == TRUE) {
runGrid();
return 0;
Expand Down Expand Up @@ -208,6 +201,13 @@ int main(int argc, char **argv) {

Plot_Initialize();

RandSeed(Globals.randseed, &environs_rng);
RandSeed(Globals.randseed, &mortality_rng);
RandSeed(Globals.randseed, &resgroups_rng);
RandSeed(Globals.randseed, &species_rng);
RandSeed(Globals.randseed, &grid_rng);
RandSeed(Globals.randseed, &markov_rng);

Globals.currIter = iter;

if (storeAllIterations) {
Expand Down

0 comments on commit 97a6d4c

Please sign in to comment.