From d37e2e43c50982880a613315852bd16b1bf795a4 Mon Sep 17 00:00:00 2001 From: Matthew Craig Date: Wed, 30 Dec 2015 15:55:41 -0600 Subject: [PATCH 1/2] Import stdint --- astroscrappy/utils/imutils.h | 5 +++++ astroscrappy/utils/medutils.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/astroscrappy/utils/imutils.h b/astroscrappy/utils/imutils.h index b4f9ae2..8acf88a 100644 --- a/astroscrappy/utils/imutils.h +++ b/astroscrappy/utils/imutils.h @@ -10,6 +10,11 @@ #ifndef IMUTILS_H_ #define IMUTILS_H_ +/* Including definitions of the standard int types is necesssary for Windows, + * and does no harm on other platforms. + */ +#include + /* Define a bool type because there isn't one built in ANSI C */ typedef uint8_t bool; #define true 1 diff --git a/astroscrappy/utils/medutils.h b/astroscrappy/utils/medutils.h index 3501636..b7aa72b 100644 --- a/astroscrappy/utils/medutils.h +++ b/astroscrappy/utils/medutils.h @@ -10,6 +10,11 @@ #ifndef MEDUTILS_H_ #define MEDUTILS_H_ +/* Including definitions of the standard int types is necesssary for Windows, + * and does no harm on other platforms. + */ +#include + /* Define a bool type because there isn't one built in ANSI C */ typedef uint8_t bool; #define true 1 From 4dcd99f474e00654c0b62c07b96642f72b9188c4 Mon Sep 17 00:00:00 2001 From: Matthew Craig Date: Wed, 30 Dec 2015 15:56:19 -0600 Subject: [PATCH 2/2] Add compiler option for OpenMP on Windows --- astroscrappy/utils/setup_package.py | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/astroscrappy/utils/setup_package.py b/astroscrappy/utils/setup_package.py index b600a5b..8204de5 100644 --- a/astroscrappy/utils/setup_package.py +++ b/astroscrappy/utils/setup_package.py @@ -7,6 +7,8 @@ from distutils.core import Extension from distutils import log +from astropy_helpers import setup_helpers + UTIL_DIR = os.path.relpath(os.path.dirname(__file__)) CODELINES = """ @@ -19,12 +21,22 @@ def check_openmp(): - s = subprocess.Popen([sys.executable], stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - stdout, stderr = s.communicate(CODELINES.encode('utf-8')) - s.wait() - return bool(s.returncode), (stdout, stderr) + if setup_helpers.get_compiler_option() == 'msvc': + # The free version of the Microsoft compilers supports + # OpenMP in MSVC 2008 (python 2.7) and MSVC 2015 (python 3.5+), + # but not MSVC 2010 (python 3.4 and lower). + major, minor = sys.version_info[:2] + has_openmp = not (major == 3 and minor < 5) + # Empty return tuple is to match the alternative check, below. + return has_openmp, ("", "") + else: + # Unix-y compiler, use this check. + s = subprocess.Popen([sys.executable], stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = s.communicate(CODELINES.encode('utf-8')) + s.wait() + return bool(s.returncode), (stdout, stderr) def get_extensions(): @@ -56,10 +68,14 @@ def get_extensions(): has_openmp, outputs = check_openmp() if has_openmp: - ext_med.extra_compile_args.append('-fopenmp') - ext_im.extra_compile_args.append('-fopenmp') - ext_med.extra_link_args = ['-g', '-fopenmp'] - ext_im.extra_link_args = ['-g', '-fopenmp'] + if setup_helpers.get_compiler_option() == 'msvc': + ext_med.extra_compile_args.append('-openmp') + ext_im.extra_compile_args.append('-openmp') + else: + ext_med.extra_compile_args.append('-fopenmp') + ext_im.extra_compile_args.append('-fopenmp') + ext_med.extra_link_args = ['-g', '-fopenmp'] + ext_im.extra_link_args = ['-g', '-fopenmp'] else: log.warn('OpenMP was not found. ' 'astroscrappy will be compiled without OpenMP. '