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
TheIntersectionEventListReducer
ensures the data consistency of theIntersectionEventList
that is passed intoQuadTree_create
since this function is called withcilk_spawn
. The identity function is just thehead
andtail
set toNULL
. The associative binary operation is appending theright
toleft
. -
uintReducer To ensure the data consistency of
numLineLineCollisions
withincollisionWorld
, instead of turningCollisionWorld
into a reducer, I made a simple uint reducer instead for simplicity, and simply updatednumLineLineCollisions
afterwards.
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.