From d4dc066e332e2d3dacf10d4f0ab3453433e28a39 Mon Sep 17 00:00:00 2001 From: "George G. Vega Yon" Date: Mon, 9 Oct 2023 21:27:20 -0600 Subject: [PATCH] Cleaning fat --- epiworld.hpp | 34 +++++++++++++++++++------------- examples/01-seir/Makefile | 2 +- include/epiworld/agent-bones.hpp | 2 -- include/epiworld/agent-meat.hpp | 5 +---- include/epiworld/virus-bones.hpp | 3 --- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/epiworld.hpp b/epiworld.hpp index a031a8d6a..d483c849b 100644 --- a/epiworld.hpp +++ b/epiworld.hpp @@ -38,7 +38,7 @@ namespace epiworld { #define EPIWORLD_MAXNEIGHBORS 1048576 #endif -#ifdef _OPENMP +#if defined(_OPENMP) || defined(__OPENMP) #include // #else // #define omp_get_thread_num() 0 @@ -305,7 +305,7 @@ struct Action { #define epiexception(a) a #endif -#if defined(EPI_DEBUG_NO_THREAD_ID) && (defined(__OPENMP) || defined(_OPENMP)) +#if defined(EPI_DEBUG_NO_THREAD_ID) || (!defined(__OPENMP) && !defined(_OPENMP)) #define EPI_GET_THREAD_ID() 0 #else #define EPI_GET_THREAD_ID() omp_get_thread_num() @@ -8480,6 +8480,15 @@ inline void Model::update_state() { template inline void Model::mutate_virus() { + // Checking if any virus has mutation + size_t nmutates = 0u; + for (const auto & v: viruses) + if (v->mutation_fun) + nmutates++; + + if (nmutates == 0u) + return; + if (use_queuing) { @@ -10102,8 +10111,6 @@ class Virus { private: Agent * agent = nullptr; - int pos_in_agent = -99; ///< Location in the agent - int agent_exposure_number = -99; std::shared_ptr baseline_sequence = nullptr; std::shared_ptr virus_name = nullptr; @@ -10117,10 +10124,6 @@ class Virus { VirusFun probability_of_death_fun = nullptr; VirusFun incubation_fun = nullptr; - // Setup parameters - std::vector< epiworld_double * > params = {}; - std::vector< epiworld_double > data = {}; - epiworld_fast_int state_init = -99; ///< Change of state when added to agent. epiworld_fast_int state_post = -99; ///< Change of state when removed from agent. epiworld_fast_int state_removed = -99; ///< Change of state when agent is removed @@ -10319,7 +10322,9 @@ inline VirusFun virus_fun_logit( size_t K = coefs_f.size(); epiworld_double res = 0.0; + #if defined(__OPENMP) || defined(_OPENMP) #pragma omp simd reduction(+:res) + #endif for (size_t i = 0u; i < K; ++i) res += agent->operator[](vars.at(i)) * coefs_f.at(i); @@ -11385,7 +11390,9 @@ inline ToolFun tool_fun_logit( size_t K = coefs_f.size(); epiworld_double res = 0.0; + #if defined(__OPENMP) || defined(_OPENMP) #pragma omp simd reduction(+:res) + #endif for (size_t i = 0u; i < K; ++i) res += agent->operator[](vars.at(i)) * coefs_f.at(i); @@ -13093,8 +13100,6 @@ class Agent { std::vector< ToolPtr > tools; epiworld_fast_uint n_tools = 0u; - epiworld_fast_uint action_counter = 0u; - std::vector< Agent * > sampled_agents; size_t sampled_agents_n = 0u; std::vector< size_t > sampled_agents_left; @@ -13655,8 +13660,7 @@ inline Agent::Agent(Agent && p) : state_last_changed(p.state_last_changed), id(p.id), tools(std::move(p.tools)), /// Needs to be adjusted - n_tools(p.n_tools), - action_counter(p.action_counter) + n_tools(p.n_tools) { state = p.state; @@ -13766,8 +13770,6 @@ inline Agent & Agent::operator=( tools[i] = std::make_shared>(*other_agent.tools[i]); tools[i]->set_agent(this, i); } - - action_counter = other_agent.action_counter; return *this; @@ -14989,7 +14991,9 @@ inline std::function*)> globalaction_tool_logit( // Computing the probability using a logit. Uses OpenMP reduction // to sum the coefficients. double p = 0.0; + #if defined(__OPENMP) || defined(_OPENMP) #pragma omp parallel for reduction(+:p) + #endif for (size_t i = 0u; i < coefs.size(); ++i) p += coefs.at(i) * agent(vars[i]); @@ -17952,7 +17956,9 @@ inline ModelSIRLogit::ModelSIRLogit( // Computing recovery probability once double prob = 0.0; + #if defined(__OPENMP) || defined(_OPENMP) #pragma omp simd reduction(+:prob) + #endif for (size_t i = 0u; i < _m->coefs_recover.size(); ++i) prob += p->operator[](i) * _m->coefs_recover[i]; diff --git a/examples/01-seir/Makefile b/examples/01-seir/Makefile index 53a5528e6..7f55b84ed 100755 --- a/examples/01-seir/Makefile +++ b/examples/01-seir/Makefile @@ -1,5 +1,5 @@ main.o: main.cpp - g++ -std=c++11 -Wall -pedantic -g -O2 -mtune=native main.cpp -o main.o + g++ -std=c++14 -Wall -pedantic -fopenmp -g -O2 -mtune=native main.cpp -o main.o README.md: main.o echo "## Example: 01-sir" > README.md && \ echo "" >> README.md && \ diff --git a/include/epiworld/agent-bones.hpp b/include/epiworld/agent-bones.hpp index 9ccb947b3..06bc77ce7 100644 --- a/include/epiworld/agent-bones.hpp +++ b/include/epiworld/agent-bones.hpp @@ -102,8 +102,6 @@ class Agent { std::vector< ToolPtr > tools; epiworld_fast_uint n_tools = 0u; - epiworld_fast_uint action_counter = 0u; - std::vector< Agent * > sampled_agents; size_t sampled_agents_n = 0u; std::vector< size_t > sampled_agents_left; diff --git a/include/epiworld/agent-meat.hpp b/include/epiworld/agent-meat.hpp index c2427f0b7..6bed922b8 100644 --- a/include/epiworld/agent-meat.hpp +++ b/include/epiworld/agent-meat.hpp @@ -27,8 +27,7 @@ inline Agent::Agent(Agent && p) : state_last_changed(p.state_last_changed), id(p.id), tools(std::move(p.tools)), /// Needs to be adjusted - n_tools(p.n_tools), - action_counter(p.action_counter) + n_tools(p.n_tools) { state = p.state; @@ -138,8 +137,6 @@ inline Agent & Agent::operator=( tools[i] = std::make_shared>(*other_agent.tools[i]); tools[i]->set_agent(this, i); } - - action_counter = other_agent.action_counter; return *this; diff --git a/include/epiworld/virus-bones.hpp b/include/epiworld/virus-bones.hpp index 775552931..8397e4539 100644 --- a/include/epiworld/virus-bones.hpp +++ b/include/epiworld/virus-bones.hpp @@ -30,8 +30,6 @@ class Virus { private: Agent * agent = nullptr; - int pos_in_agent = -99; ///< Location in the agent - int agent_exposure_number = -99; std::shared_ptr baseline_sequence = nullptr; std::shared_ptr virus_name = nullptr; @@ -46,7 +44,6 @@ class Virus { VirusFun incubation_fun = nullptr; // Setup parameters - std::vector< epiworld_double * > params = {}; std::vector< epiworld_double > data = {}; epiworld_fast_int state_init = -99; ///< Change of state when added to agent.