From fc1cf5033c999922478372007cdc0793a9aaeb2a Mon Sep 17 00:00:00 2001 From: Willem Deconinck Date: Fri, 22 Nov 2024 10:07:46 +0100 Subject: [PATCH] bugfix: DIV_BY_ZERO in MatchingFunctionSpacePartitionerLonLatPolygon for small grids with OMP (#244) --- .../MatchingFunctionSpacePartitionerLonLatPolygon.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/atlas/grid/detail/partitioner/MatchingFunctionSpacePartitionerLonLatPolygon.cc b/src/atlas/grid/detail/partitioner/MatchingFunctionSpacePartitionerLonLatPolygon.cc index c202b11dd..03b99b6df 100644 --- a/src/atlas/grid/detail/partitioner/MatchingFunctionSpacePartitionerLonLatPolygon.cc +++ b/src/atlas/grid/detail/partitioner/MatchingFunctionSpacePartitionerLonLatPolygon.cc @@ -56,6 +56,9 @@ void MatchingFunctionSpacePartitionerLonLatPolygon::partition(const Grid& grid, ATLAS_TRACE("point-in-polygon check for entire grid (" + std::to_string(grid.size()) + " points)"); size_t num_threads = atlas_omp_get_max_threads(); size_t chunk_size = grid.size() / (1000 * num_threads); + if (chunk_size == 0) { + chunk_size = grid.size(); + } size_t chunks = num_threads == 1 ? 1 : std::max(size_t(1), size_t(grid.size()) / chunk_size); atlas_omp_pragma(omp parallel for schedule(dynamic,1)) for( size_t chunk=0; chunk < chunks; ++chunk) {