From dbe016f443cf6065519f7200ffdd004f419aae84 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Keck <Jean-Baptiste.Keck@imag.fr>
Date: Thu, 12 Jan 2017 10:43:04 +0100
Subject: [PATCH] debug build

---
 CMakeLists.txt                                |  8 +++----
 cmake/FindFFTW.cmake                          | 20 ++++++++--------
 cmake/hysop_tests.cmake                       |  1 +
 hysop/__init__.py.in                          | 10 ++------
 .../tests/test_directional_advection.py       | 23 +++++++++++--------
 .../tests/test_directional_stretching.py      | 13 +++++++----
 hysop/gpu/tools.py                            | 20 ++++++++--------
 setup.py.in                                   | 22 ++++--------------
 8 files changed, 55 insertions(+), 62 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4db57300a..1ac6c73b3 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -384,11 +384,9 @@ if(USE_FORTRAN)
   endif()
 endif()
 
-if(USE_CXX OR USE_FORTRAN)
+if(USE_FORTRAN)
   add_subdirectory(src)
-  get_directory_property(FORTRAN_INCLUDE_DIRS
-    DIRECTORY ${CMAKE_SOURCE_DIR}/src
-    DEFINITION INCLUDE_DIRECTORIES)
+  set(FORTRAN_INCLUDE_DIRS ${FFTW_INCLUDE_DIRS})
 endif()
 
 if(USE_CXX)
@@ -471,7 +469,7 @@ if(USE_CXX)
             set(HYSOP_CXX_LIBRARY_BUNDLE "${CMAKE_CURRENT_BINARY_DIR}/libcpp2hysop_bundle.so")
             add_custom_target(cpp2hysop_bundle
                 DEPENDS wheel
-                COMMAND cp `find ${CMAKE_CURRENT_BINARY_DIR}/build -name _${CPP_2_HYSOP}.so` ${HYSOP_CXX_LIBRARY_BUNDLE}
+                COMMAND cp `find ${CMAKE_CURRENT_BINARY_DIR}/build -name ${CPP_2_HYSOP}.so` ${HYSOP_CXX_LIBRARY_BUNDLE}
                 WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
                 COMMENT "Copy swig c++ library to link")
             set(HYSOP_CXX_LIBRARY ${HYSOP_CXX_LIBRARY_BUNDLE})
diff --git a/cmake/FindFFTW.cmake b/cmake/FindFFTW.cmake
index 544a35159..454e4d717 100644
--- a/cmake/FindFFTW.cmake
+++ b/cmake/FindFFTW.cmake
@@ -26,23 +26,23 @@
 # == Defined variables ==
 #
 #   FFTW_FOUND - will be set to true if and only if all required components and their dependencies were found
-#   FFTW_INCLUDE_DIRS - all FFTW include directories
-#   FFTW_LIBRARY_DIRS - all FFTW library directories
-#   FFTW_LIBRARIES - all FFTW libraries
-#   FFTW_DEFINES - all FFTW defines
+#   FFTW_INCLUDE_DIRS  - all FFTW include directories
+#   FFTW_LIBRARY_DIRS  - all FFTW library directories
+#   FFTW_LIBRARIES     - all FFTW libraries
+#   FFTW_DEFINES       - all FFTW defines
 #   FTTW_COMPILE_FLAGS - all FFTW compile flags (currently only used for quadfloat fftw)
 #
 #   For each required or optional component, this package defines:
 #  		COMPONENT_FOUND   - will be set to true the component and its dependencies were found, else false
 #  		COMPONENT_DEFINES - all COMPONENT defines (-DFFTW_HAS_COMPONENT)
 #
-#  		COMPONENT_INCLUDE_DIRS - COMPONENT and its dependancies include directories
-#  		COMPONENT_LIBRARY_DIRS - COMPONENT and its dependancies library directories
-#  		COMPONENT_LIBRARIES    - COMPONENT and its dependancies libraries
+#  		COMPONENT_INCLUDE_DIRS - COMPONENT and its dependencies include directories
+#  		COMPONENT_LIBRARY_DIRS - COMPONENT and its dependencies library directories
+#  		COMPONENT_LIBRARIES    - COMPONENT and its dependencies libraries
 #
-#  		COMPONENT_INCLUDE_DIR - COMPONENT include directory
-#  		COMPONENT_LIBRARY_DIR - COMPONENT library directory
-#  		COMPONENT_LIBRARY     - COMPONENT library
+#  		COMPONENT_INCLUDE_DIR  - COMPONENT include directory
+#  		COMPONENT_LIBRARY_DIR  - COMPONENT library directory
+#  		COMPONENT_LIBRARY      - COMPONENT library
 #
 #   where COMPONENT is equal to <input component name> transformed with the following rules:
 #       * uppercased
diff --git a/cmake/hysop_tests.cmake b/cmake/hysop_tests.cmake
index 09f38645b..db5b29852 100755
--- a/cmake/hysop_tests.cmake
+++ b/cmake/hysop_tests.cmake
@@ -67,6 +67,7 @@ set(py_src_dirs
 # If GPU is on, we add test_XXX.py files of hysop/gpu directory
 if(WITH_GPU)
   list(APPEND py_src_dirs gpu)
+  list(APPEND py_src_dirs codegen)
 endif()
 
 # Copy the OpenCL sources files to build dir (required since only python files are copied by setup.py)
diff --git a/hysop/__init__.py.in b/hysop/__init__.py.in
index 681a00065..d37c43a2c 100755
--- a/hysop/__init__.py.in
+++ b/hysop/__init__.py.in
@@ -20,6 +20,8 @@ __DEBUG__          = "@DEBUG@"   in ["2", "3"]
 __KERNEL_DEBUG__   = "@DEBUG@"   in ["4", "3"]
 __PROFILE__        = "@PROFILE@" in ["0", "1"]
 
+__ENABLE_LONG_TESTS__ = "@ENABLE_LONG_TESTS@" is "ON"
+
 # OpenCL
 __DEFAULT_PLATFORM_ID__ = @OPENCL_DEFAULT_OPENCL_PLATFORM_ID@
 __DEFAULT_DEVICE_ID__   = @OPENCL_DEFAULT_OPENCL_DEVICE_ID@
@@ -40,13 +42,6 @@ from hysop.tools.parameters import MPIParams, Discretization
 import hysop.mpi
 # Problem
 from hysop.problem.problem import Problem
-# Solver
-# import particular_solvers.basic
-# ## #import particular_solvers.gpu
-# ParticleSolver = particular_solvers.basic.ParticleSolver
-# ## #GPUParticleSolver = particular_solvers.gpu.GPUParticleSolver
-## from tools.explore_hardware import explore
-
 
 __all__ = ['Box', 'Field', 'Discretization',
            'IOParams', 'Simulation', 'MPIParams', 'Problem', 'IO']
@@ -70,7 +65,6 @@ if __VERBOSE__:
             msg_start += ' with ' + str(mpi.main_size) + ' mpi process(es).'
             print msg_start
             print msg_io
-
     else:
         print msg_start
         print msg_io
diff --git a/hysop/codegen/kernels/tests/test_directional_advection.py b/hysop/codegen/kernels/tests/test_directional_advection.py
index 577e3b4e0..2ee9440a3 100644
--- a/hysop/codegen/kernels/tests/test_directional_advection.py
+++ b/hysop/codegen/kernels/tests/test_directional_advection.py
@@ -1,6 +1,7 @@
 
 import copy, math
 
+from hysop import __ENABLE_LONG_TESTS__
 from hysop.gpu import cl
 from hysop.constants import np, BoundaryCondition
 from hysop.codegen.base.test import _test_mesh_info , _test_typegen
@@ -10,7 +11,9 @@ from hysop.codegen.kernels.directional_advection import DirectionalAdvectionKern
 class TestDirectionalAdvection(object):
 
     @classmethod
-    def setup_class(cls,enable_error_plots=False):
+    def setup_class(cls,
+            enable_extra_tests=__ENABLE_LONG_TESTS__,
+            enable_error_plots=False):
         typegen = _test_typegen('double','dec')
         dtype = np.float64
 
@@ -66,7 +69,7 @@ class TestDirectionalAdvection(object):
 								hostbuf=host_buffers_init['no_ghosts']['u']),
                     'pos':   cl.Buffer(ctx, flags=mf.WRITE_ONLY  | mf.COPY_HOST_PTR, 
 								hostbuf=host_buffers_init['no_ghosts']['pos']),
-                    'dbg0': cl.Buffer(ctx, flags=mf.READ_WRITE | mf.COPY_HOST_PTR, 
+                    'dbg0': cl.Buffer(ctx, flags=mf.READ_WRITE | mf.COPY_HOST_PTR,
 								hostbuf=host_buffers_init['no_ghosts']['dbg0']),
                     'dbg1': cl.Buffer(ctx, flags=mf.READ_WRITE | mf.COPY_HOST_PTR, 
 								hostbuf=host_buffers_init['no_ghosts']['dbg1']),
@@ -118,6 +121,7 @@ class TestDirectionalAdvection(object):
         cls.inv_dx = inv_dx
         cls.dt     = dtype(dt)
         
+        cls.enable_extra_tests = enable_extra_tests
         cls.enable_error_plots = enable_error_plots
 
 
@@ -393,12 +397,13 @@ class TestDirectionalAdvection(object):
 
         cached=[False,True]
         boundaries=[BoundaryCondition.PERIODIC]
-        nparticles=[1,2,4,8,16]
-        work_dims=[1,2,3]
-        # cached=[False]
-        # boundaries=[BoundaryCondition.NONE]
-        # nparticles=[1]
-        # work_dims=[2,3]
+
+        if self.enable_extra_tests:
+            nparticles=[1,2,4,8,16]
+            work_dims=[1,2,3]
+        else:
+            nparticles=[1,4]
+            work_dims=[2,3]
         
         for boundary in boundaries:
             self._do_compute_cpu(boundary=boundary, rk_scheme=rk_scheme)
@@ -422,7 +427,7 @@ class TestDirectionalAdvection(object):
         self._check_kernels(rk_scheme=rk_scheme)
 
 if __name__ == '__main__':
-    TestDirectionalAdvection.setup_class(enable_error_plots=True)
+    TestDirectionalAdvection.setup_class(enable_extra_tests=True, enable_error_plots=True)
     test = TestDirectionalAdvection()
     
     test.test_advection_Euler()
diff --git a/hysop/codegen/kernels/tests/test_directional_stretching.py b/hysop/codegen/kernels/tests/test_directional_stretching.py
index 85f3c8905..46bf0531d 100644
--- a/hysop/codegen/kernels/tests/test_directional_stretching.py
+++ b/hysop/codegen/kernels/tests/test_directional_stretching.py
@@ -1,6 +1,7 @@
 
 import copy
 
+from hysop import __ENABLE_LONG_TESTS__
 from hysop.gpu import cl
 from hysop.constants import np, BoundaryCondition
 from hysop.codegen.base.test import _test_mesh_info , _test_typegen
@@ -10,7 +11,9 @@ from hysop.methods_keys import StretchingFormulation, ExplicitRungeKutta
 class TestDirectionalStretching(object):
 
     @classmethod
-    def setup_class(cls,do_extra_tests=False, enable_error_plots=False):
+    def setup_class(cls,
+            do_extra_tests=__ENABLE_LONG_TESTS__, 
+            enable_error_plots=False):
         typegen = _test_typegen('double','dec')
         dtype = np.float64
 
@@ -441,7 +444,8 @@ class TestDirectionalStretching(object):
                         axes[0][0].imshow(np.sum(d,axis=0),interpolation='nearest')
                         axes[0][1].imshow(np.sum(d,axis=1),interpolation='nearest')
                         axes[1][0].imshow(np.sum(d,axis=2),interpolation='nearest')
-                        axes[1][1].imshow(np.sum(d,axis=(0,1))[np.newaxis,:],interpolation='nearest')
+                        axes[1][1].imshow(np.sum(d,axis=(0,1))[np.newaxis,:],
+                                interpolation='nearest')
 
                         fig.show()
                         break
@@ -481,8 +485,9 @@ class TestDirectionalStretching(object):
                         self._do_compute_cpu(order=order, direction=direction, boundary=boundary,
                                 formulation=formulation, rk_scheme=rk_scheme)
                         
-                        self._do_compute_gpu_and_check(order=order, direction=direction, boundary=boundary,
-                                formulation=formulation, rk_scheme=rk_scheme, cached=cache)
+                        self._do_compute_gpu_and_check(order=order, direction=direction, 
+                                boundary=boundary, formulation=formulation, 
+                                rk_scheme=rk_scheme, cached=cache)
    
 
 
diff --git a/hysop/gpu/tools.py b/hysop/gpu/tools.py
index dedc1b5df..a67307cb5 100644
--- a/hysop/gpu/tools.py
+++ b/hysop/gpu/tools.py
@@ -15,7 +15,7 @@
 """
 import os, re, itertools, hashlib, pickle, gzip
 
-from __future__ import print_function
+# from __future__ import print_function
 
 from hysop import __VERBOSE__, __KERNEL_DEBUG__, \
         __DEFAULT_PLATFORM_ID__, __DEFAULT_DEVICE_ID__
@@ -464,10 +464,10 @@ class OpenCLEnvironment(object):
             number of remeshed components, default=1
         options: string
             additional OpenCL compile flags
-        force_verbose: bool, optional
+        force_verbose: bool, optional, default=None
             force verbose mode
-        force_debug: bool, optional
-            force debug mode (kernel dumping)
+        force_debug: bool, optional, default=None
+            force debug mode (kernel source dumping and preprocessing)
         
         Returns OpenCL kernel
         Parse the sources to handle single and double precision.
@@ -478,16 +478,17 @@ class OpenCLEnvironment(object):
         gpu_src = ""
         if cl.device_type.to_string(self.device.type) == 'GPU' and \
                 self.precision is DOUBLE_GPU:
-            gpu_src += "#pragma OPENCL EXTENSION cl_khr_fp64: enable \n"
+            gpu_src += '#pragma OPENCL EXTENSION cl_khr_fp64: enable \n'
         
         if isinstance(files, list):
             file_list = files
         else:
             file_list = [files]
+
         if VERBOSE:
-            print "=== Kernel sources compiling ==="
-            for sf in file_list:
-                print "   - ", sf
+            print '=== Kernel sources compiling ==='
+            for sd in file_list:
+                print '  - ', sf
 
         for sf in file_list:
             # search and open cl file.
@@ -567,7 +568,8 @@ Dumped OpenCL Kernel '{}'
                 os.rename(tmp_dump_file,dump_file)
 
             if VERBOSE:
-                print 'OpenCL kernel {} source dumped to {}.'.format(kernel_name, dump_file)
+                msg = 'OpenCL kernel {} source dumped to {}.'.format(kernel_name, dump_file)
+                print msg
 
         # OpenCL program
         prg = cl.Program(self.ctx, gpu_src)
diff --git a/setup.py.in b/setup.py.in
index 6d2e7472f..e28d8b617 100644
--- a/setup.py.in
+++ b/setup.py.in
@@ -84,15 +84,6 @@ for lib in hysop_link_libraries:
         extra_flags.append('-framework ' + filename)
 hysop_link_libraries += extra_flags
 
-# hysop_link_libraries_names = set()
-# hysop_link_libraries_dirs = set()
-# for lib in hysop_link_libraries:
-    # hysop_link_libraries_names.add(os.path.basename(lib))
-    # hysop_link_libraries_dirs.add(os.path.dirname(lib))
-# hysop_link_libraries_names = list(hysop_link_libraries_names)
-# hysop_link_libraries_dirs = list(hysop_link_libraries_dirs)
-
-
 def create_fortran_extension(name, pyf_file=None, src_dirs=None, sources=None,
                              libdir=None, libs=None, debug_mode=0):
     """Create a new f2py module from fortran files
@@ -152,17 +143,14 @@ def create_fortran_extension(name, pyf_file=None, src_dirs=None, sources=None,
     inc_dir =  parseCMakeVar("@FORTRAN_INCLUDE_DIRS@")
     inc_dir += parseCMakeVar("@MPI_Fortran_INCLUDE_PATH@")
     inc_dir += parseCMakeVar('@CMAKE_Fortran_MODULE_DIRECTORY@')
+
     # --- set compilation flags ---
     fortran_flags = ['@Fortran_FLAGS@']
 
-    # --- set include dir ---
-    # inc_dir += hysop_link_libraries_dirs
-    # --- set external libraries ---
-    # libs += hysop_link_libraries_names
     # we trust cmake for external libraries and
     # add them to linker, without using libraries option
-
     extra_link_args = hysop_link_libraries
+
     ext_fort = Extension(name=name,
                          sources=sources,
                          f2py_options=f2py_options,
@@ -202,17 +190,16 @@ def create_swig_extension(name, inc_dirs, src_dirs=None, sources=None):
       name.i in CMAKE_SOURCE_DIR/swig/
 
     """
-    swig_dir = os.path.join('@CMAKE_SOURCE_DIR@', 'swig')
+    swig_dir         = os.path.join('@CMAKE_SOURCE_DIR@', 'swig')
     swig_config_file = os.path.join(swig_dir, name + '.i')
 
     include_dirs = set(inc_dirs)
     if sources is None:
         sources = []
-        assert src_dirs is not None or inc_dirs is not None
+        assert (src_dirs is not None) or (inc_dirs is not None)
     if(src_dirs is None):
         assert(inc_dirs is not None)
         for idir in inc_dirs:
-            #sources += glob.glob(os.path.join(idir, '**/*.cpp'), recursive=True)
             for root, dirnames, filenames in os.walk(idir):
                 for filename in fnmatch.filter(filenames, '*.cpp'):
                     sources.append(os.path.join(root, filename))
@@ -222,6 +209,7 @@ def create_swig_extension(name, inc_dirs, src_dirs=None, sources=None):
 
     sources.insert(0, swig_config_file)
     include_dirs = list(include_dirs)
+    print sources
 
     name = 'hysop._' + name
     swig_opts = ['-I' + swig_dir,
-- 
GitLab