cleanup and allocations
parent
dd144a199a
commit
c89e2967ba
|
@ -142,25 +142,24 @@ int main()
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
BLT_TRACE("Total Allocations: %ld times with a total of %s", blt::gp::tracker.getAllocations(),
|
BLT_TRACE("Total Allocations: %ld times with a total of %s", blt::gp::tracker.getAllocations(),
|
||||||
blt::byte_convert_t(blt::gp::tracker.getAllocatedBytes()).convert_to_nearest_type().to_pretty_string().c_str());
|
blt::byte_convert_t(blt::gp::tracker.getAllocatedBytes()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
auto crossover_calls = blt::gp::crossover_calls.get_calls();
|
auto crossover_calls_v = blt::gp::crossover_calls.get_calls();
|
||||||
auto crossover_allocations = blt::gp::crossover_allocations.get_calls();
|
auto crossover_allocations_v = blt::gp::crossover_allocations.get_calls();
|
||||||
auto mutation_calls = blt::gp::mutation_calls.get_calls();
|
auto mutation_calls_v = blt::gp::mutation_calls.get_calls();
|
||||||
auto mutation_allocation = blt::gp::mutation_allocations.get_calls();
|
auto mutation_allocations_v = blt::gp::mutation_allocations.get_calls();
|
||||||
auto reproduction_calls = blt::gp::reproduction_calls.get_calls();
|
auto reproduction_calls_v = blt::gp::reproduction_calls.get_calls();
|
||||||
auto reproduction_allocation = blt::gp::reproduction_allocations.get_calls();
|
auto reproduction_allocations_v = blt::gp::reproduction_allocations.get_calls();
|
||||||
BLT_TRACE("Total Crossover Calls: %ld", crossover_calls);
|
BLT_TRACE("Total Crossover Calls: %ld Bytes %s", crossover_calls_v, blt::byte_convert_t(blt::gp::crossover_calls.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
BLT_TRACE("Total Mutation Calls: %ld", mutation_calls);
|
BLT_TRACE("Total Mutation Calls: %ld Bytes %s", mutation_calls_v, blt::byte_convert_t(blt::gp::mutation_calls.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
BLT_TRACE("Total Reproduction Calls: %ld", reproduction_calls);
|
BLT_TRACE("Total Reproduction Calls: %ld Bytes %s", reproduction_calls_v, blt::byte_convert_t(blt::gp::reproduction_calls.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
BLT_TRACE("Total Crossover Allocations: %ld", crossover_allocations);
|
BLT_TRACE("Total Crossover Allocations: %ld Bytes %s", crossover_allocations_v, blt::byte_convert_t(blt::gp::crossover_allocations.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
BLT_TRACE("Total Mutation Allocations: %ld", mutation_allocation);
|
BLT_TRACE("Total Mutation Allocations: %ld Bytes %s", mutation_allocations_v, blt::byte_convert_t(blt::gp::mutation_allocations.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
BLT_TRACE("Total Reproduction Allocations: %ld", reproduction_allocation);
|
BLT_TRACE("Total Reproduction Allocations: %ld Bytes %s", reproduction_allocations_v, blt::byte_convert_t(blt::gp::reproduction_allocations.get_value()).convert_to_nearest_type().to_pretty_string().c_str());
|
||||||
|
|
||||||
BLT_TRACE("Percent Crossover calls allocate? %lf%%",
|
BLT_TRACE("Percent Crossover calls allocate? %lf%%",
|
||||||
static_cast<double>(crossover_allocations) / static_cast<double>(crossover_calls == 0 ? 1 : crossover_calls) * 100);
|
static_cast<double>(crossover_allocations_v) / static_cast<double>(crossover_calls_v == 0 ? 1 : crossover_calls_v) * 100);
|
||||||
BLT_TRACE("Percent Mutation calls allocate? %lf%%",
|
BLT_TRACE("Percent Mutation calls allocate? %lf%%",
|
||||||
static_cast<double>(mutation_allocation) / static_cast<double>(mutation_calls == 0 ? 1 : mutation_calls) * 100);
|
static_cast<double>(mutation_allocations_v) / static_cast<double>(mutation_calls_v == 0 ? 1 : mutation_calls_v) * 100);
|
||||||
BLT_TRACE("Percent Reproduction calls allocate? %lf%%",
|
BLT_TRACE("Percent Reproduction calls allocate? %lf%%",
|
||||||
static_cast<double>(reproduction_allocation) / static_cast<double>(reproduction_calls == 0 ? 1 : reproduction_calls) * 100);
|
static_cast<double>(reproduction_allocations_v) / static_cast<double>(reproduction_calls_v == 0 ? 1 : reproduction_calls_v) * 100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -362,10 +362,6 @@ namespace blt::gp
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
auto gen_alloc = blt::gp::tracker.start_measurement();
|
auto gen_alloc = blt::gp::tracker.start_measurement();
|
||||||
#endif
|
#endif
|
||||||
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
|
||||||
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
|
||||||
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
|
||||||
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
|
||||||
// should already be empty
|
// should already be empty
|
||||||
thread_helper.next_gen_left.store(config.population_size, std::memory_order_release);
|
thread_helper.next_gen_left.store(config.population_size, std::memory_order_release);
|
||||||
(*thread_execution_service)(0);
|
(*thread_execution_service)(0);
|
||||||
|
@ -378,10 +374,6 @@ namespace blt::gp
|
||||||
|
|
||||||
void next_generation()
|
void next_generation()
|
||||||
{
|
{
|
||||||
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
|
||||||
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
|
||||||
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
|
||||||
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
|
||||||
std::swap(current_pop, next_pop);
|
std::swap(current_pop, next_pop);
|
||||||
current_generation++;
|
current_generation++;
|
||||||
}
|
}
|
||||||
|
@ -406,6 +398,10 @@ namespace blt::gp
|
||||||
current_pop = config.pop_initializer.get().generate(
|
current_pop = config.pop_initializer.get().generate(
|
||||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
||||||
next_pop = population_t(current_pop);
|
next_pop = population_t(current_pop);
|
||||||
|
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
||||||
|
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
||||||
|
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
||||||
|
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
||||||
if (eval_fitness_now)
|
if (eval_fitness_now)
|
||||||
evaluate_fitness_internal();
|
evaluate_fitness_internal();
|
||||||
}
|
}
|
||||||
|
@ -434,6 +430,10 @@ namespace blt::gp
|
||||||
current_pop = config.pop_initializer.get().generate(
|
current_pop = config.pop_initializer.get().generate(
|
||||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
||||||
next_pop = population_t(current_pop);
|
next_pop = population_t(current_pop);
|
||||||
|
BLT_ASSERT_MSG(current_pop.get_individuals().size() == config.population_size,
|
||||||
|
("cur pop size: " + std::to_string(current_pop.get_individuals().size())).c_str());
|
||||||
|
BLT_ASSERT_MSG(next_pop.get_individuals().size() == config.population_size,
|
||||||
|
("next pop size: " + std::to_string(next_pop.get_individuals().size())).c_str());
|
||||||
if (config.threads == 1)
|
if (config.threads == 1)
|
||||||
{
|
{
|
||||||
BLT_INFO("Starting with single thread variant!");
|
BLT_INFO("Starting with single thread variant!");
|
||||||
|
@ -593,7 +593,7 @@ namespace blt::gp
|
||||||
auto index = config.elites + begin;
|
auto index = config.elites + begin;
|
||||||
tree_t& c1 = next_pop.get_individuals()[index].tree;
|
tree_t& c1 = next_pop.get_individuals()[index].tree;
|
||||||
tree_t* c2 = nullptr;
|
tree_t* c2 = nullptr;
|
||||||
if (index + 1 < end)
|
if (begin + 1 < end)
|
||||||
c2 = &next_pop.get_individuals()[index + 1].tree;
|
c2 = &next_pop.get_individuals()[index + 1].tree;
|
||||||
begin += func(args, crossover_selection, mutation_selection, reproduction_selection, c1, c2);
|
begin += func(args, crossover_selection, mutation_selection, reproduction_selection, c1, c2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ namespace blt::gp
|
||||||
} while (!config.crossover.get().apply(program, *p1, *p2, c1, *c2));
|
} while (!config.crossover.get().apply(program, *p1, *p2, c1, *c2));
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
tracker.stop_measurement(state);
|
tracker.stop_measurement(state);
|
||||||
crossover_calls.call();
|
crossover_calls.call(state.getAllocatedByteDifference());
|
||||||
if (state.getAllocationDifference() != 0)
|
if (state.getAllocationDifference() != 0)
|
||||||
crossover_allocations.call(state.getAllocatedByteDifference());
|
crossover_allocations.call(state.getAllocatedByteDifference());
|
||||||
#endif
|
#endif
|
||||||
|
@ -122,7 +122,7 @@ namespace blt::gp
|
||||||
} while (!config.mutator.get().apply(program, *p, c1));
|
} while (!config.mutator.get().apply(program, *p, c1));
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
tracker.stop_measurement(state);
|
tracker.stop_measurement(state);
|
||||||
mutation_calls.call();
|
mutation_calls.call(state.getAllocatedByteDifference());
|
||||||
if (state.getAllocationDifference() != 0)
|
if (state.getAllocationDifference() != 0)
|
||||||
{
|
{
|
||||||
mutation_allocations.call(state.getAllocatedByteDifference());
|
mutation_allocations.call(state.getAllocatedByteDifference());
|
||||||
|
@ -141,7 +141,7 @@ namespace blt::gp
|
||||||
c1 = reproduction_selection.select(program, current_pop);
|
c1 = reproduction_selection.select(program, current_pop);
|
||||||
#ifdef BLT_TRACK_ALLOCATIONS
|
#ifdef BLT_TRACK_ALLOCATIONS
|
||||||
tracker.stop_measurement(state);
|
tracker.stop_measurement(state);
|
||||||
reproduction_calls.call();
|
reproduction_calls.call(state.getAllocatedByteDifference());
|
||||||
if (state.getAllocationDifference() != 0)
|
if (state.getAllocationDifference() != 0)
|
||||||
{
|
{
|
||||||
reproduction_allocations.call(state.getAllocatedByteDifference());
|
reproduction_allocations.call(state.getAllocatedByteDifference());
|
||||||
|
|
2
lib/blt
2
lib/blt
|
@ -1 +1 @@
|
||||||
Subproject commit 79e080cfd34fb47342f67f19b95ffa27efb0f715
|
Subproject commit ab482f1a1c5782bd3501428f26c02f0bb4729946
|
Loading…
Reference in New Issue