Skip to content

Commit

Permalink
get rid of prange
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeshrinet committed Apr 20, 2020
1 parent ff93a3b commit 19fc24a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 61 deletions.
33 changes: 16 additions & 17 deletions pyross/deterministic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import numpy as np
cimport numpy as np
cimport cython
from libc.math cimport sqrt
from cython.parallel import prange
cdef double PI = 3.14159265359

DTYPE = np.float
Expand Down Expand Up @@ -52,9 +51,9 @@ cdef class SIR:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa - FM[i]
Expand Down Expand Up @@ -164,9 +163,9 @@ cdef class SIRS:
double [:] iaa = self.iaa
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa + sa[i] + ep*(gIa*Ia[i] + gIs*Is[i])
Expand Down Expand Up @@ -254,9 +253,9 @@ cdef class SEIR:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa - FM[i]
Expand Down Expand Up @@ -416,9 +415,9 @@ cdef class SEI5R:
double [:] mm = self.mm
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j]+fh*Ih[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa + sa[i]
Expand Down Expand Up @@ -516,9 +515,9 @@ cdef class SEAIR:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa - FM[i]
Expand Down Expand Up @@ -626,9 +625,9 @@ cdef class SEAIRQ:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for j in prange(M):
for j in range(M):
bb += beta*CM[i,j]*(Ia[j]+fsa*Is[j])/Ni[j]
aa = bb*S[i]
X[i] = -aa - tS *S[i] - FM[i]
Expand Down Expand Up @@ -716,10 +715,10 @@ cdef class SIkR:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for jj in range(kk):
for j in prange(M):
for j in range(M):
bb += beta*(CM[i,j]*I[j+jj*M])/Ni[j]
aa = bb*S[i]
X[i] = -aa - FM[i]
Expand Down Expand Up @@ -812,10 +811,10 @@ cdef class SEkIkR:
double [:] FM = self.FM
double [:] X = self.drpdt

for i in prange(M, nogil=True):
for i in range(M):
bb=0
for jj in range(kk):
for j in prange(M):
for j in range(M):
bb += beta*(CM[i,j]*I[j+jj*M])/Ni[j]
aa = bb*S[i]
X[i] = -aa - FM[i]
Expand Down
44 changes: 0 additions & 44 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,6 @@
Cython.Compiler.Options.annotate = True


def checkOpenmpSupport():
""" Adapted from https://stackoverflow.com/questions/16549893/programatically-testing-for-openmp-support-from-a-python-setup-script
"""
ompTest = \
r"""
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Thread %d, Total number of threads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
"""
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
os.chdir(tmpdir)

filename = r'test.c'
try:
with open(filename, 'w') as file:
file.write(ompTest)
with open(os.devnull, 'w') as fnull:
result = subprocess.call(['cc', '-fopenmp', filename],
stdout=fnull, stderr=fnull)
except:
print("Failed to test for OpenMP support. Assuming unavailability");
result = -1;
os.chdir(curdir)
shutil.rmtree(tmpdir)
if result == 0:
return True
else:
return False


if checkOpenmpSupport() == True:
ompArgs = ['-fopenmp']
else:
ompArgs = None




setup(
name='PyRoss',
version='1.0.0',
Expand All @@ -60,8 +18,6 @@ def checkOpenmpSupport():
platforms='works on all platforms (eg LINUX, macOS, and Microsoft Windows)',
ext_modules=cythonize([ Extension("pyross/*", ["pyross/*.pyx"],
include_dirs=[numpy.get_include()],
extra_compile_args=ompArgs,
extra_link_args=ompArgs
)],
compiler_directives={"language_level": sys.version_info[0]},
),
Expand Down

0 comments on commit 19fc24a

Please sign in to comment.