From 25051fad3eb8988b2ed41a607120c99b7da2deca Mon Sep 17 00:00:00 2001 From: wvpm <24685035+wvpm@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:57:28 +0100 Subject: Process provinces in parallel --- src/openvic-simulation/map/MapInstance.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/openvic-simulation/map') diff --git a/src/openvic-simulation/map/MapInstance.cpp b/src/openvic-simulation/map/MapInstance.cpp index 28bf189..d53ae0a 100644 --- a/src/openvic-simulation/map/MapInstance.cpp +++ b/src/openvic-simulation/map/MapInstance.cpp @@ -1,5 +1,7 @@ #include "MapInstance.hpp" +#include + #include "openvic-simulation/history/ProvinceHistory.hpp" #include "openvic-simulation/map/MapDefinition.hpp" #include "openvic-simulation/utility/Logger.hpp" @@ -161,9 +163,15 @@ void MapInstance::update_gamestate(const Date today, DefineManager const& define } void MapInstance::map_tick(const Date today) { - for (ProvinceInstance& province : province_instances.get_items()) { - province.province_tick(today); - } + std::vector& provinces = province_instances.get_items(); + std::for_each( + std::execution::par, + provinces.begin(), + provinces.end(), + [today](ProvinceInstance& province) -> void { + province.province_tick(today); + } + ); } void MapInstance::initialise_for_new_game( @@ -171,8 +179,14 @@ void MapInstance::initialise_for_new_game( DefineManager const& define_manager ) { update_gamestate(today, define_manager); - for (ProvinceInstance& province : province_instances.get_items()) { - province.initialise_rgo(); - province.province_tick(today); - } + std::vector& provinces = province_instances.get_items(); + std::for_each( + std::execution::par, + provinces.begin(), + provinces.end(), + [today](ProvinceInstance& province) -> void { + province.initialise_rgo(); + province.province_tick(today); + } + ); } \ No newline at end of file -- cgit v1.2.3-56-ga3b1