| Version | mit.in | koch.in |
|---|---|---|
| Naive | 45.905592s | 932.316011s |
| quad tree | 9.328597s | 18.491237s |
| parallelization | 1.546889s | 3.322799s |
In my quad tree implementation, I would assign lines to quadrants if it fully contained the parallelogram of the line and its velocity. Otherwise, the line would be placed in the root tree. I set a max depth and line threshold as the base case of my recursive implementation.
-
Jamming
Similar to loop jamming, I calculate the number of collisions as I create my node, comparing the current lines with its parent lines, and also comparing the lines within each node. -
Coarsening
I set the base case to be larger to reduce function-call overhead and reducing excessive memory allocation when$n$ was small enough. -
Inlining
I inlined some functions to reduce function-call overhead.
I implemented 2 reducers to ensure data consistency.
-
IntersectionEventListReducer
TheIntersectionEventListReducerensures the data consistency of theIntersectionEventListthat is passed intoQuadTree_createsince this function is called withcilk_spawn. The identity function is just theheadandtailset toNULL. The associative binary operation is appending therighttoleft. -
uintReducer To ensure the data consistency of
numLineLineCollisionswithincollisionWorld, instead of turningCollisionWorldinto a reducer, I made a simple uint reducer instead for simplicity, and simply updatednumLineLineCollisionsafterwards.
For parallelization, I call cilk_for when checking for line intersections, since
there are no data dependencies when checking for intersections. Similarly, I call
cilk_spawn recursively on each child.
Overall, when implementing parallelization using openCilk, cilkscale gives us:
tag,work (seconds),span (seconds),parallelism,burdened_span (seconds),burdened_parallelism
,22.2409,0.792948,28.0483,2.1343,10.4207
To run, simply run the screensaver executable and follow the CLI.