From 5f77917fbe149fb2d5097b6c867ca6cc6c1000c1 Mon Sep 17 00:00:00 2001 From: Michael Lee Rilee Date: Sun, 19 Sep 2021 04:46:13 +0000 Subject: [PATCH 1/3] Initial commit. --- pystare/PySTARE.cpp | 20 +++++++++++--------- setup.py | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pystare/PySTARE.cpp b/pystare/PySTARE.cpp index f524ecf..350070c 100644 --- a/pystare/PySTARE.cpp +++ b/pystare/PySTARE.cpp @@ -12,6 +12,8 @@ #include +#include + // Info const char* stare_version() { return STARE_version(); } @@ -25,22 +27,22 @@ void _from_latlon(double* lat, int len_lat, double * lon, int len_lon, int64_t* void _from_latlon2D(double* lat, int lalen1, int lalen2, double* lon, int lolen1, int lolen2, int64_t* indices, int len1, int len2, int level, bool adapt_resolution) { - int n; static EmbeddedLevelNameEncoding lj; // Use this to get the mask - int lvl; - + int64_t not_levelMask = ~lj.levelMaskSciDB; + for (int i=0; i=1.20.0'] -STARE_LIB_DIRS = [os.environ.get('STARE_LIB_DIR', '/usr/local/lib')] -STARE_INCLUDE_DIRS = [os.environ.get('STARE_INCLUDE_DIR', '/usr/local/include')] +STARE_LIB_DIRS = [os.environ.get('STARE_LIB_DIR', '/home/jovyan/users_conda_envs/work/lib')] +STARE_INCLUDE_DIRS = [os.environ.get('STARE_INCLUDE_DIR','/home/jovyan/users_conda_envs/work/include')] if os.environ.get('PYTHON_INCLUDE_DIRS') is None: PYTHON_INCLUDE_DIRS = [] @@ -30,8 +30,8 @@ sources=['pystare/PySTARE.i', 'pystare/PySTARE.cpp'], depends=['pystare/PySTARE.h'], swig_opts=['-modern', '-c++'], - extra_compile_args=['-std=c++11'], - libraries=['STARE'], + extra_compile_args=['-std=c++11','-fopenmp'], + libraries=['STARE','gomp'], library_dirs=STARE_LIB_DIRS, # Location of libSTARE.a include_dirs=INCLUDE_DIRS, # Location of STARE.h language='c++') From 962c953de7ae1d65d1d4b2de4c09aa475225b5ad Mon Sep 17 00:00:00 2001 From: Michael Rilee Date: Sun, 19 Sep 2021 18:15:44 -0400 Subject: [PATCH 2/3] Added an install time OpenMP checker to setup.py. --- setup.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index bb4ad72..7751102 100644 --- a/setup.py +++ b/setup.py @@ -18,20 +18,79 @@ STARE_LIB_DIRS = [os.environ.get('STARE_LIB_DIR', '/home/jovyan/users_conda_envs/work/lib')] STARE_INCLUDE_DIRS = [os.environ.get('STARE_INCLUDE_DIR','/home/jovyan/users_conda_envs/work/include')] -if os.environ.get('PYTHON_INCLUDE_DIRS') is None: - PYTHON_INCLUDE_DIRS = [] -else: - PYTHON_INCLUDE_DIRS = os.environ.get('PYTHON_INCLUDE_DIRS').split(':') +PYTHON_INCLUDE_DIRS = [] if os.environ.get('PYTHON_INCLUDE_DIRS') is None else os.environ.get('PYTHON_INCLUDE_DIRS').split(':') INCLUDE_DIRS = STARE_INCLUDE_DIRS + PYTHON_INCLUDE_DIRS + [numpy.get_include()] +EXTRA_COMPILE_ARGS=['-std=c++11'] +LIBRARIES=['STARE'] + +######### +### Just to get started... +### Check for OpenMP -- cf. https://stackoverflow.com/questions/16549893/programatically-testing-for-openmp-support-from-a-python-setup-script +import os, tempfile, subprocess, shutil + +CC = 'cc' if os.environ.get('CC') is None else os.environ.get("CC") +OMP_CFLAGS = '-fopenmp' if os.environ.get('OMP_CFLAGS') is None else os.environ.get("OMP_CFLAGS") +OMP_INCLUDE_DIR = None if os.environ.get('OMP_INCLUDE_DIR') is None else os.environ.get('OMP_INCLUDE_DIR') +OMP_LIB_DIR = None if os.environ.get('OMP_LIB_DIR') is None else os.environ.get('OMP_LIB_DIR') +OMP_LIBRARY = 'gomp' if os.environ.get('OMP_LIBRARY') is None else os.environ.get('OMP_LIBRARY') + +OMP_LDFLAGS = [] if OMP_LIB_DIR is None else ['-L'+OMP_LIB_DIR] +OMP_LDFLAGS = OMP_LDFLAGS + ['-l'+OMP_LIBRARY] + +OMP_CFLAGS = OMP_CFLAGS.split(' ') if OMP_INCLUDE_DIR is None else ['-I'+OMP_INCLUDE_DIR] + OMP_CFLAGS.split(' ') + +TEST_FLAGS = OMP_CFLAGS + OMP_LDFLAGS + +# see http://openmp.org/wp/openmp-compilers/ +omp_test = \ +r""" +#include +#include +int main() { +#pragma omp parallel +printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads()); +} +""" + +def check_for_openmp(): + tmpdir = tempfile.mkdtemp() + curdir = os.getcwd() + os.chdir(tmpdir) + + filename = r'test.c' + with open(filename, 'w') as file: + file.write(omp_test) + with open(os.devnull, 'w') as fnull: + FLAGS= (' '.join(TEST_FLAGS)).split(' ') + CMD=[CC] + FLAGS + [filename] + # print('CMD: ',CMD) + result = subprocess.call(CMD,stdout=fnull,stderr=fnull) + # print(os.listdir('.')) + if result == 0: + result = subprocess.call(['./a.out'],stdout=fnull,stderr=fnull) + os.chdir(curdir) + #clean up + shutil.rmtree(tmpdir) + + return result + +if check_for_openmp() == 0: + print('OpenMP found. Adding build options.') + EXTRA_COMPILE_ARGS = EXTRA_COMPILE_ARGS + OMP_CFLAGS + OMP_LDFLAGS + LIBRARIES = LIBRARIES + [OMP_LIBRARY] +else: + print('OpenMP not found. Continuing...') + +######## pystare = Extension(name='pystare._core', sources=['pystare/PySTARE.i', 'pystare/PySTARE.cpp'], depends=['pystare/PySTARE.h'], swig_opts=['-modern', '-c++'], - extra_compile_args=['-std=c++11','-fopenmp'], - libraries=['STARE','gomp'], + extra_compile_args=EXTRA_COMPILE_ARGS, + libraries=LIBRARIES, library_dirs=STARE_LIB_DIRS, # Location of libSTARE.a include_dirs=INCLUDE_DIRS, # Location of STARE.h language='c++') From dad30d72414d1ad27ed2acfb86d7fc4039a20368 Mon Sep 17 00:00:00 2001 From: Michael Rilee Date: Sun, 19 Sep 2021 18:18:00 -0400 Subject: [PATCH 3/3] Changed default lib to omp, not gomp. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7751102..9631132 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,7 @@ OMP_CFLAGS = '-fopenmp' if os.environ.get('OMP_CFLAGS') is None else os.environ.get("OMP_CFLAGS") OMP_INCLUDE_DIR = None if os.environ.get('OMP_INCLUDE_DIR') is None else os.environ.get('OMP_INCLUDE_DIR') OMP_LIB_DIR = None if os.environ.get('OMP_LIB_DIR') is None else os.environ.get('OMP_LIB_DIR') -OMP_LIBRARY = 'gomp' if os.environ.get('OMP_LIBRARY') is None else os.environ.get('OMP_LIBRARY') +OMP_LIBRARY = 'omp' if os.environ.get('OMP_LIBRARY') is None else os.environ.get('OMP_LIBRARY') OMP_LDFLAGS = [] if OMP_LIB_DIR is None else ['-L'+OMP_LIB_DIR] OMP_LDFLAGS = OMP_LDFLAGS + ['-l'+OMP_LIBRARY]