Skip to content

Commit

Permalink
slight changes to PYFFTW_AVAILABLE mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfougeron committed May 28, 2024
1 parent 412a8c0 commit 1f2070b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
4 changes: 2 additions & 2 deletions choreo/cython/_NBodySyst.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ try:
except:
MKL_FFT_AVAILABLE = False

from choreo.cython.optional_pyfftw cimport pyfftw, PYFFTW_AVAILABLE
from choreo.cython.optional_pyfftw import p_pyfftw
from choreo.cython.optional_pyfftw cimport pyfftw
from choreo.cython.optional_pyfftw import p_pyfftw, PYFFTW_AVAILABLE

cdef int USE_SCIPY_FFT = 0
cdef int USE_MKL_FFT = 1
Expand Down
3 changes: 2 additions & 1 deletion choreo/cython/optional_pyfftw_False.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cimport choreo.cython.pyfftw_fake as pyfftw
import choreo.cython.pyfftw_fake as p_pyfftw
cdef bint PYFFTW_AVAILABLE = False
PYFFTW_AVAILABLE = False

2 changes: 1 addition & 1 deletion choreo/cython/optional_pyfftw_True.pyx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cimport pyfftw
import pyfftw as p_pyfftw
cdef bint PYFFTW_AVAILABLE = True
PYFFTW_AVAILABLE = False
33 changes: 19 additions & 14 deletions choreo/find_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import choreo.scipy_plus
from choreo.cython._ActionSym import ActionSym

import warnings
from choreo.cython.optional_pyfftw import PYFFTW_AVAILABLE
if PYFFTW_AVAILABLE:
import pyfftw

def Find_Choreo(
*,
geodim,
Expand Down Expand Up @@ -925,15 +930,15 @@ def Check_Duplicates(NBS, segmpos, params, hash_dict, action_dict, store_folder,

return False, None

try:
import pyfftw
def wisdom_filename_divide(filename):
root, ext = os.path.splitext(filename)
return [root+"_"+prec+ext for prec in ['d','f','l']]

def wisdom_filename_divide(filename):
root, ext = os.path.splitext(filename)
return [root+"_"+prec+ext for prec in ['d','f','l']]

def Load_wisdom_file(DP_Wisdom_file):

def Load_wisdom_file(DP_Wisdom_file):

if not(PYFFTW_AVAILABLE):
warnings.warn("The package pyfftw could not be loaded. Please check your local install.")
else:
wis_list = []

for i, filename in enumerate(wisdom_filename_divide(DP_Wisdom_file)):
Expand All @@ -946,14 +951,14 @@ def Load_wisdom_file(DP_Wisdom_file):

wis_list.append(wis)

pyfftw.import_wisdom(wis_list)

def Write_wisdom_file(DP_Wisdom_file):
pyfftw.import_wisdom(wis_list)

def Write_wisdom_file(DP_Wisdom_file):
if not(PYFFTW_AVAILABLE):
warnings.warn("The package pyfftw could not be loaded. Please check your local install.")
else:
wis = pyfftw.export_wisdom()

for i, filename in enumerate(wisdom_filename_divide(DP_Wisdom_file)):
with open(filename, 'wb') as f:
f.write(wis[i])

except:
pass
36 changes: 17 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@

break

# extra_compile_args_std = ["-O0","-march=native", "-fopenmp", "-lm", *ignore_warnings_args]
# extra_compile_args_safe = ["-O0", "-fopenmp", "-lm", *ignore_warnings_args]
# extra_link_args = ["-fopenmp", "-lm",]
extra_compile_args_std = ["-O0","-march=native", "-fopenmp", "-lm", *ignore_warnings_args]
extra_compile_args_safe = ["-O0", "-fopenmp", "-lm", *ignore_warnings_args]
extra_link_args = ["-fopenmp", "-lm",]

extra_compile_args_std = ["-Ofast", "-march=native", "-fopenmp", "-lm", "-flto", *ignore_warnings_args]
extra_compile_args_safe = ["-O3", "-fopenmp", "-lm", "-flto", *ignore_warnings_args]
extra_link_args = ["-fopenmp", "-lm", "-flto", *ignore_warnings_args]
# extra_compile_args_std = ["-Ofast", "-march=native", "-fopenmp", "-lm", "-flto", *ignore_warnings_args]
# extra_compile_args_safe = ["-O3", "-fopenmp", "-lm", "-flto", *ignore_warnings_args]
# extra_link_args = ["-fopenmp", "-lm", "-flto", *ignore_warnings_args]

cython_extnames.append("choreo.cython.funs_parallel")
cython_safemath_needed.append(False)
Expand All @@ -130,13 +130,11 @@
pyfftw_pxd_str = """
cimport pyfftw
import pyfftw as p_pyfftw
cdef bint PYFFTW_AVAILABLE
"""
else:
pyfftw_pxd_str = """
cimport choreo.cython.pyfftw_fake as pyfftw
import choreo.cython.pyfftw_fake as p_pyfftw
cdef bint PYFFTW_AVAILABLE
"""
with open("choreo/cython/optional_pyfftw.pxd", "w") as text_file:
text_file.write(pyfftw_pxd_str)
Expand All @@ -156,17 +154,17 @@
}

#### Profiler only ####
# profile_compiler_directives = {
# 'profile': True,
# 'linetrace': True,
# 'binding': True,
# }
# compiler_directives.update(profile_compiler_directives)
# profile_define_macros = [
# ('CYTHON_TRACE', '1') ,
# ('CYTHON_TRACE_NOGIL', '1') ,
# ]
# define_macros.extend(profile_define_macros)
profile_compiler_directives = {
'profile': True,
'linetrace': True,
'binding': True,
}
compiler_directives.update(profile_compiler_directives)
profile_define_macros = [
('CYTHON_TRACE', '1') ,
('CYTHON_TRACE_NOGIL', '1') ,
]
define_macros.extend(profile_define_macros)

include_dirs = [
numpy.get_include() ,
Expand Down

0 comments on commit 1f2070b

Please sign in to comment.