Skip to content

Commit

Permalink
remove cached_parent_haplosomes_value_
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Oct 6, 2024
1 parent 2077328 commit eb4dfd0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 48 deletions.
1 change: 0 additions & 1 deletion core/population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ void Population::ResolveSurvivalPhaseMovement(void)
subpop->parent_haplosomes_.resize((size_t)subpop->parent_subpop_size_ * 2);
subpop->parent_individuals_.resize(subpop->parent_subpop_size_);

subpop->cached_parent_haplosomes_value_.reset();
subpop->cached_parent_individuals_value_.reset();
}
}
Expand Down
11 changes: 3 additions & 8 deletions core/species_eidos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2374,17 +2374,12 @@ EidosValue_SP Species::ExecuteMethod_killIndividuals(EidosGlobalStringID p_metho

if (killed_count)
{
// First, clear our haplosome and individual caches in all subpopulations; any subpops involved in
// First, clear our individual caches in all subpopulations; any subpops involved in
// this method would be invalidated anyway so this probably isn't even that much overkill in
// most models. Note that the child haplosomes/individuals caches don't need to be thrown away,
// most models. Note that the child individuals caches don't need to be thrown away,
// because they aren't used in nonWF models and this is a nonWF-only method.
for (auto subpop_pair : population_.subpops_)
{
Subpopulation *subpop = subpop_pair.second;

subpop->cached_parent_haplosomes_value_.reset();
subpop->cached_parent_individuals_value_.reset();
}
subpop_pair.second->cached_parent_individuals_value_.reset();

// Invalidate interactions; we just do this for all subpops, for now, rather than trying to
// selectively invalidate only the subpops involved in the deaths that occurred
Expand Down
42 changes: 6 additions & 36 deletions core/subpopulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ void Subpopulation::GenerateParentsToFit(slim_age_t p_initial_age, double p_sex_
int32_t mutrun_count = chromosome.mutrun_count_;
slim_position_t mutrun_length = chromosome.mutrun_length_;

cached_parent_haplosomes_value_.reset();
cached_parent_individuals_value_.reset();

if (parent_individuals_.size() || parent_haplosomes_.size())
Expand Down Expand Up @@ -3288,7 +3287,6 @@ void Subpopulation::SwapChildAndParentHaplosomes(void)

// Execute the haplosome swap
child_haplosomes_.swap(parent_haplosomes_);
cached_parent_haplosomes_value_.reset();

// Execute a swap of individuals as well; since individuals carry so little baggage, this is mostly important just for moving tag values
child_individuals_.swap(parent_individuals_);
Expand Down Expand Up @@ -3574,7 +3572,6 @@ void Subpopulation::MergeReproductionOffspring(void)
// final cleanup
parent_subpop_size_ += new_count;

cached_parent_haplosomes_value_.reset();
cached_parent_individuals_value_.reset();

nonWF_offspring_haplosomes_.clear();
Expand Down Expand Up @@ -3893,7 +3890,6 @@ void Subpopulation::ViabilitySurvival(std::vector<SLiMEidosBlock*> &p_survival_c
parent_haplosomes_.resize((size_t)parent_subpop_size_ * 2);
parent_individuals_.resize(parent_subpop_size_);

cached_parent_haplosomes_value_.reset();
cached_parent_individuals_value_.reset();
}
}
Expand Down Expand Up @@ -3967,33 +3963,12 @@ EidosValue_SP Subpopulation::GetProperty(EidosGlobalStringID p_property_id)
}
case gID_haplosomes:
{
if (!cached_parent_haplosomes_value_)
{
EidosValue_Object *vec = (new (gEidosValuePool->AllocateChunk()) EidosValue_Object(gSLiM_Haplosome_Class))->reserve(parent_haplosomes_.size());
cached_parent_haplosomes_value_ = EidosValue_SP(vec);

for (auto haplosome_iter : parent_haplosomes_)
vec->push_object_element_no_check_NORR(haplosome_iter);
}

#if DEBUG
{
// check that the cache is correct
const EidosObject * const *vec_direct = cached_parent_haplosomes_value_->ObjectData();
int vec_size = cached_parent_haplosomes_value_->Count();

if (vec_size == (int)parent_haplosomes_.size())
{
for (int i = 0; i < vec_size; ++i)
if (vec_direct[i] != parent_haplosomes_[i])
EIDOS_TERMINATION << "ERROR (Subpopulation::GetProperty): value mismatch in cached_parent_haplosomes_value_." << EidosTerminate();
}
else
EIDOS_TERMINATION << "ERROR (Subpopulation::GetProperty): size mismatch in cached_parent_haplosomes_value_." << EidosTerminate();
}
#endif
EidosValue_Object *vec = (new (gEidosValuePool->AllocateChunk()) EidosValue_Object(gSLiM_Haplosome_Class))->reserve(parent_haplosomes_.size());

return cached_parent_haplosomes_value_;
for (auto haplosome_iter : parent_haplosomes_)
vec->push_object_element_no_check_NORR(haplosome_iter);

return EidosValue_SP(vec);
}
case gID_haplosomesNonNull:
{
Expand Down Expand Up @@ -5789,12 +5764,7 @@ EidosValue_SP Subpopulation::ExecuteMethod_takeMigrants(EidosGlobalStringID p_me
// most models. Note that the child haplosomes/individuals caches don't need to be thrown away,
// because they aren't used in nonWF models and this is a nonWF-only method.
for (auto subpop_pair : population_.subpops_)
{
Subpopulation *subpop = subpop_pair.second;

subpop->cached_parent_haplosomes_value_.reset();
subpop->cached_parent_individuals_value_.reset();
}
subpop_pair.second->cached_parent_individuals_value_.reset();

// Invalidate interactions; we just do this for all subpops, for now, rather than trying to
// selectively invalidate only the subpops involved in the migrations that occurred
Expand Down
5 changes: 2 additions & 3 deletions core/subpopulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ class Subpopulation : public EidosDictionaryUnretained
bool has_null_haplosomes_ = false; // false until a null haplosome is added; NOT set by null haplosomes for sex chromosome sims; use CouldContainNullHaplosomes() to check this flag

std::vector<Haplosome *> parent_haplosomes_; // OWNED: all haplosomes in the parental generation; each individual gets two haplosomes, males are XY (not YX)
EidosValue_SP cached_parent_haplosomes_value_; // cached for the haplosomes property; reset() if changed
slim_popsize_t parent_subpop_size_; // parental subpopulation size
slim_popsize_t parent_first_male_index_ = INT_MAX; // the index of the first male in the parental Haplosome vector (NOT premultiplied by 2!); equal to the number of females
std::vector<Individual *> parent_individuals_; // OWNED: objects representing simulated individuals, each of which has two haplosomes
EidosValue_SP cached_parent_individuals_value_; // cached for the individuals property; self-maintains
double parent_sex_ratio_ = 0.0; // WF only: what sex ratio the parental haplosomes approximate (M:M+F)
double parent_sex_ratio_ = 0.0; // WF only: what sex ratio the parent individuals approximate (M:M+F)

// WF only:
// In WF models, we actually switch to a "child" generation just after offspring generation; this is then the active generation.
Expand All @@ -146,7 +145,7 @@ class Subpopulation : public EidosDictionaryUnretained
slim_popsize_t child_subpop_size_; // child subpopulation size
slim_popsize_t child_first_male_index_ = INT_MAX; // the index of the first male in the child Haplosome vector (NOT premultiplied by 2!); equal to the number of females
std::vector<Individual *> child_individuals_; // OWNED: objects representing simulated individuals, each of which has two haplosomes
double child_sex_ratio_ = 0.0; // what sex ratio the child haplosomes approximate (M:M+F)
double child_sex_ratio_ = 0.0; // what sex ratio the child individuals approximate (M:M+F)

// nonWF only:
// In nonWF models, we place generated offspring into a temporary holding pen, but it is never made the "active generation"
Expand Down

0 comments on commit eb4dfd0

Please sign in to comment.