From bf0874bbd36a9c9232ea0b89df4e47ebed0e9bdd Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 9 Aug 2017 17:42:02 +0200 Subject: [PATCH] Fixes to compile on OSX --- python/CMakeLists.txt | 6 +++++- python/_cosmo_bispectrum.cpp | 10 ++++++++++ python/_cosmotool.pyx | 9 ++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index bb2f745..f5c963d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,5 +1,6 @@ set(CMAKE_SHARED_MODULE_PREFIX) + include_directories(${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/python) IF(CYTHON) @@ -39,7 +40,10 @@ add_library(_project MODULE ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp) -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Bsymbolic-functions") +SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Bsymbolic-functions") +if(APPLE) + set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup") +endif() target_link_libraries(_cosmotool ${CosmoTool_local} ${PYTHON_LIBRARIES} ${GSL_LIBRARIES}) target_link_libraries(_cosmo_power ${CosmoTool_local} ${PYTHON_LIBRARIES} ${GSL_LIBRARIES}) diff --git a/python/_cosmo_bispectrum.cpp b/python/_cosmo_bispectrum.cpp index 94e6491..db6a6e0 100644 --- a/python/_cosmo_bispectrum.cpp +++ b/python/_cosmo_bispectrum.cpp @@ -1,4 +1,6 @@ +#ifdef _OPENMP #include +#endif #include #include #include @@ -171,7 +173,11 @@ void CosmoTool_compute_bispectrum( { // First remap to multi_array for easy access size_t kNz = Nz/2+1; +#ifdef _OPENMP int Ntasks = omp_get_max_threads(); +#else + int Ntasks = 1; +#endif boost::multi_array_ref, 3> a_delta(reinterpret_cast*>(delta_hat), boost::extents[Nx][Ny][kNz]); boost::multi_array_ref a_Nt(Ntriangles, boost::extents[Nk][Nk][Nk]); boost::multi_array_ref, 3> a_B(reinterpret_cast*>(B), boost::extents[Nk][Nk][Nk]); @@ -190,6 +196,7 @@ void CosmoTool_compute_bispectrum( delta_mirror[n1.i1][n1.i2][n1.i3] = std::conj(delta_mirror[n2.i1][n2.i2][n2.i3]); } +#ifdef _OPENMP // First loop over m1 #pragma omp parallel { @@ -236,6 +243,9 @@ void CosmoTool_compute_bispectrum( a_B_p[q] += b_B_p[q]; } } +#else +#warning Serial version not implemented +#endif } diff --git a/python/_cosmotool.pyx b/python/_cosmotool.pyx index 628e4e9..5ef1c1a 100644 --- a/python/_cosmotool.pyx +++ b/python/_cosmotool.pyx @@ -9,6 +9,9 @@ cimport cython np.import_array() +cdef extern from "sys/types.h": + ctypedef np.int64_t int64_t + cdef extern from "loadSimu.hpp" namespace "CosmoTool": cdef cppclass SimuData: @@ -20,7 +23,7 @@ cdef extern from "loadSimu.hpp" namespace "CosmoTool": np.float_t Omega_Lambda np.int64_t TotalNumPart np.int64_t NumPart - np.int64_t *Id + int64_t *Id float *Pos[3] float *Vel[3] int *type @@ -323,7 +326,7 @@ cdef object wrap_array(void *p, np.uint64_t s, int typ): cdef object wrap_float_array(float *p, np.uint64_t s): return wrap_array(p, s, np.NPY_FLOAT32) -cdef object wrap_int64_array(np.int64_t* p, np.uint64_t s): +cdef object wrap_int64_array(int64_t* p, np.uint64_t s): return wrap_array(p, s, np.NPY_INT64) cdef object wrap_int_array(int* p, np.uint64_t s): @@ -501,7 +504,7 @@ def writeGadget(str filename, object simulation): simdata.Vel[j] = vel.data ids = simulation.getIdentifiers() - simdata.Id = ids.data + simdata.Id = ids.data simdata.BoxSize = simulation.getBoxsize() simdata.time = simulation.getTime() simdata.Hubble = simulation.getHubble()