Skip to content

Commit b3f2cdc

Browse files
authored
Fix reproject with threads + add Windows and Mac CI (#292)
* Run CI on mac and windows on julia v1 at least this way we don't get hammered * Use proj_context_destroy not proj_destroy That was causing the segfault it seems. * Clean up the code and remove allocations from broadcasting TODO: is it "safe" to use ntuple here? is nthreads a compile time constant? Not sure, we can leave that for later, but this is a nice note * add arch on Win
1 parent aef4c07 commit b3f2cdc

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

.github/workflows/CI.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ jobs:
2525
- ubuntu-latest
2626
arch:
2727
- x64
28+
include:
29+
- os: windows-latest
30+
version: '1'
31+
arch: x64
32+
- os: macos-latest
33+
version: '1'
34+
arch: arm64
2835
steps:
2936
- uses: actions/checkout@v2
3037
- uses: julia-actions/cache@v1

ext/GeometryOpsProjExt/reproject.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@ function reproject(geom, transform::Proj.Transformation;
5252
if istrue(threaded)
5353
tasks_per_thread = 2
5454
ntasks = Threads.nthreads() * tasks_per_thread
55+
# Clone the transformation once for each task.
56+
# Currently, these transformations live in the same context, but we will soon
57+
# assign them to per-task contexts.
58+
proj_transforms = [Proj.Transformation(Proj.proj_clone(transform.pj)) for _ in 1:ntasks]
59+
5560
# Construct one context per planned task
5661
contexts = [Proj.proj_context_clone(context) for _ in 1:ntasks]
57-
# Clone the transformation for each context
58-
proj_transforms = [Proj.Transformation(Proj.proj_clone(transform.pj)) for context in contexts]
59-
# Assign the context to the transformation
60-
Proj.proj_assign_context.(getproperty.(proj_transforms, :pj), contexts)
62+
# Assign the context to the transformation. We use `foreach` here
63+
# to avoid generating output where we don't have to.
64+
foreach(Proj.proj_assign_context, getproperty.(proj_transforms, :pj), contexts)
6165

6266
results = if _is3d(geom)
6367
functors = TaskFunctors(WithXYZ.(proj_transforms))
@@ -67,7 +71,7 @@ function reproject(geom, transform::Proj.Transformation;
6771
apply(functors, GI.PointTrait(), geom; kw1...)
6872
end
6973
# Destroy the temporary threading contexts that we created
70-
Proj.proj_destroy.(contexts)
74+
foreach(Proj.proj_context_destroy, contexts)
7175
# Return the results
7276
return results
7377
else

0 commit comments

Comments
 (0)