diff --git a/include/medium.h b/include/medium.h index ac39b7c1..47bd9604 100644 --- a/include/medium.h +++ b/include/medium.h @@ -69,7 +69,9 @@ namespace batoid { const Medium* getDevPtr() const override; private: - const double _B1, _B2, _B3, _C1, _C2, _C3; + // ``_C1`` / ``_C2`` / ``_C3`` collide with macros from the + // Windows SDK (ctype.h), so use a Sellmeier-prefixed name. + const double _B1, _B2, _B3, _sellC1, _sellC2, _sellC3; }; diff --git a/setup.py b/setup.py index 04ea42c9..02b2e290 100644 --- a/setup.py +++ b/setup.py @@ -36,12 +36,32 @@ def build_extension(self, ext): "-DPYTHON_EXECUTABLE=" + sys.executable, ] + # Make pybind11 discoverable in PEP 517 isolated builds, where + # CMake's normal find_package would not see the temporary site + # packages. ``python -m pybind11 --cmakedir`` returns the + # directory shipped with the pybind11 wheel. + try: + import pybind11 + cmake_args.append("-Dpybind11_DIR=" + pybind11.get_cmake_dir()) + except (ImportError, AttributeError): + pass + cfg = "Debug" if self.debug else "RelWithDebInfo" build_args = ["--config", cfg] cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] + # Hand parallelism to ``cmake --build --parallel`` instead of + # forwarding ``-j8`` to the underlying tool: MSBuild rejects + # ``-j8`` outright (it expects ``/m`` or ``-maxCpuCount``), while + # Make/Ninja are happy with the CMake-level flag. ``--parallel`` + # picks up CMAKE_BUILD_PARALLEL_LEVEL when set, or defaults to a + # generator-appropriate count. if "TF_BUILD" not in env: - build_args += ["--", "-j8"] + jobs = os.environ.get("CMAKE_BUILD_PARALLEL_LEVEL") + if jobs: + build_args += ["--parallel", str(jobs)] + else: + build_args += ["--parallel"] if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) diff --git a/src/batoid.cpp b/src/batoid.cpp index 2627e2c7..c56c68c8 100644 --- a/src/batoid.cpp +++ b/src/batoid.cpp @@ -1,4 +1,5 @@ #include "batoid.h" +#include // ptrdiff_t for OpenMP-safe signed loop counters on MSVC. #include @@ -10,8 +11,12 @@ namespace batoid { double* x, double* y, double* z, size_t n, int max_threads ) { + // MSVC's OpenMP requires a signed integral loop counter; reuse a + // ptrdiff_t mirror of ``n`` so the parallel-for index can be signed + // without clipping. + ptrdiff_t nloop = static_cast(n); #pragma omp parallel for num_threads(max_threads) - for(size_t i=0; i(n); #pragma omp parallel for num_threads(max_threads) - for(size_t i=0; i ymax)) { + if ((y < ymin) || (y > ymax)) { for (int i=0; i= (_nx-1)) or (ix < 0) or (iy >= (_ny-1)) or (iy < 0)) { + if ((ix >= (_nx-1)) || (ix < 0) || (iy >= (_ny-1)) || (iy < 0)) { return _use_nan ? NAN : 0.0; } double xgrid = _x0 + ix*_dx; @@ -95,7 +95,7 @@ namespace batoid { ) const { int ix = int(std::floor((x-_x0)/_dx)); int iy = int(std::floor((y-_y0)/_dy)); - if ((ix >= (_nx-1)) or (ix < 0) or (iy >= (_ny-1)) or (iy < 0)) { + if ((ix >= (_nx-1)) || (ix < 0) || (iy >= (_ny-1)) || (iy < 0)) { if (_use_nan) { dzdx = NAN; dzdy = NAN;