Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions VGsim/_BirthDeath.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# distutils: language = c++

cimport cython
from cython.parallel import prange

from libc.math cimport log, floor, abs
from libcpp.vector cimport vector
Expand Down Expand Up @@ -185,9 +186,11 @@ cdef class BirthDeathModel:
@cython.wraparound(False)
@cython.cdivision(True)
cdef void SetEffectiveMigration(self):
cdef Py_ssize_t i, j

for i in range(self.popNum):
self.pm_maxEffectiveMigration[i] = 0.0
for i in range(self.popNum):
for i in prange(self.popNum, nogil=True):
for j in range(self.popNum):
self.pm_effectiveMigration[i,j] = self.pm_migrationRates[i,j]*self.pm.contactDensity[j]/self.pm.sizes[j]+self.pm_migrationRates[j,i]*self.pm.contactDensity[i]/self.pm.sizes[i]
if self.pm_effectiveMigration[i,j] > self.pm_maxEffectiveMigration[j]:
Expand Down Expand Up @@ -497,7 +500,7 @@ cdef class BirthDeathModel:
for j in range(0, iterations):
self.SampleTime()
popId = self.GenerateEvent()
if self.totalRate == 0.0 or self.pm.globalInfectious == 0:
if self.totalRate == 0.0 or self.pm.globalInfectious == 0 or self.events.ptr == 20000000:
break
self.CheckLockdown(popId)
print("Total number of iterations: ", self.events.ptr)
Expand Down
9 changes: 9 additions & 0 deletions VGsim/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

from Cython.Compiler import Options

import sys
import numpy

Options.annotate = True

PACKAGE_NAME = 'VGsim'

# enable openMP on linux, disable on MacOS
if sys.platform == "darwin":
openmp_args = []
else:
openmp_args = ['-fopenmp']


def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
Expand All @@ -20,6 +27,8 @@ def configuration(parent_package='', top_path=None):
'models.pxi', 'fast_choose.pxi'],
language='c++',
include_dirs=[numpy.get_include()],
extra_compile_args=openmp_args,
extra_link_args=openmp_args,
)

return config
Expand Down