Skip to content

Commit

Permalink
Cleaning fat
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Oct 10, 2023
1 parent 0e1fbf3 commit d4dc066
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
34 changes: 20 additions & 14 deletions epiworld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace epiworld {
#define EPIWORLD_MAXNEIGHBORS 1048576
#endif

#ifdef _OPENMP
#if defined(_OPENMP) || defined(__OPENMP)
#include <omp.h>
// #else
// #define omp_get_thread_num() 0
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -8480,6 +8480,15 @@ inline void Model<TSeq>::update_state() {
template<typename TSeq>
inline void Model<TSeq>::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)
{

Expand Down Expand Up @@ -10102,8 +10111,6 @@ class Virus {
private:

Agent<TSeq> * agent = nullptr;
int pos_in_agent = -99; ///< Location in the agent
int agent_exposure_number = -99;

std::shared_ptr<TSeq> baseline_sequence = nullptr;
std::shared_ptr<std::string> virus_name = nullptr;
Expand All @@ -10117,10 +10124,6 @@ class Virus {
VirusFun<TSeq> probability_of_death_fun = nullptr;
VirusFun<TSeq> 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
Expand Down Expand Up @@ -10319,7 +10322,9 @@ inline VirusFun<TSeq> 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);

Expand Down Expand Up @@ -11385,7 +11390,9 @@ inline ToolFun<TSeq> 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);

Expand Down Expand Up @@ -13093,8 +13100,6 @@ class Agent {
std::vector< ToolPtr<TSeq> > tools;
epiworld_fast_uint n_tools = 0u;

epiworld_fast_uint action_counter = 0u;

std::vector< Agent<TSeq> * > sampled_agents;
size_t sampled_agents_n = 0u;
std::vector< size_t > sampled_agents_left;
Expand Down Expand Up @@ -13655,8 +13660,7 @@ inline Agent<TSeq>::Agent(Agent<TSeq> && 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;
Expand Down Expand Up @@ -13766,8 +13770,6 @@ inline Agent<TSeq> & Agent<TSeq>::operator=(
tools[i] = std::make_shared<Tool<TSeq>>(*other_agent.tools[i]);
tools[i]->set_agent(this, i);
}

action_counter = other_agent.action_counter;

return *this;

Expand Down Expand Up @@ -14989,7 +14991,9 @@ inline std::function<void(Model<TSeq>*)> 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]);

Expand Down Expand Up @@ -17952,7 +17956,9 @@ inline ModelSIRLogit<TSeq>::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];

Expand Down
2 changes: 1 addition & 1 deletion examples/01-seir/Makefile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
2 changes: 0 additions & 2 deletions include/epiworld/agent-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class Agent {
std::vector< ToolPtr<TSeq> > tools;
epiworld_fast_uint n_tools = 0u;

epiworld_fast_uint action_counter = 0u;

std::vector< Agent<TSeq> * > sampled_agents;
size_t sampled_agents_n = 0u;
std::vector< size_t > sampled_agents_left;
Expand Down
5 changes: 1 addition & 4 deletions include/epiworld/agent-meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ inline Agent<TSeq>::Agent(Agent<TSeq> && 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;
Expand Down Expand Up @@ -138,8 +137,6 @@ inline Agent<TSeq> & Agent<TSeq>::operator=(
tools[i] = std::make_shared<Tool<TSeq>>(*other_agent.tools[i]);
tools[i]->set_agent(this, i);
}

action_counter = other_agent.action_counter;

return *this;

Expand Down
3 changes: 0 additions & 3 deletions include/epiworld/virus-bones.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class Virus {
private:

Agent<TSeq> * agent = nullptr;
int pos_in_agent = -99; ///< Location in the agent
int agent_exposure_number = -99;

std::shared_ptr<TSeq> baseline_sequence = nullptr;
std::shared_ptr<std::string> virus_name = nullptr;
Expand All @@ -46,7 +44,6 @@ class Virus {
VirusFun<TSeq> 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.
Expand Down

0 comments on commit d4dc066

Please sign in to comment.