Difference between revisions of "Raytrace Scheduler"

From CSE231 Wiki
Jump to navigation Jump to search
Line 1: Line 1:
=Where to Start=
+
=Motivation=
==Demo==
+
Gain some exposure to different task scheduling styles.
 +
 
 +
=Background=
 +
[https://en.wikipedia.org/wiki/Ray_tracing_(graphics) Ray Tracing]
 +
 
 +
=Code To Investigate=
 
{{CodeToInvestigate|SplitFourWayRayTracer|rayTrace|raytrace.demo}}
 
{{CodeToInvestigate|SplitFourWayRayTracer|rayTrace|raytrace.demo}}
  
Line 11: Line 16:
 
[[File:DivideAndConquerRayTracer.png|thumb]]
 
[[File:DivideAndConquerRayTracer.png|thumb]]
 
Recursively divide the given region into 4 tasks for each of the four quadrants until you get below the threshold.
 
Recursively divide the given region into 4 tasks for each of the four quadrants until you get below the threshold.
When you get below the threshold, call the <code>renderSection</code> method to render the section.
+
When areaThreshold predicate test method returns false, call the <code>rayTraceBaseCase(context, xMin, yMix, xMax, yMax)</code> method to render the section.
  
 
{{CodeToImplement|DivideAndConquerRayTracer|rayTraceKernel|raytrace.fun}}
 
{{CodeToImplement|DivideAndConquerRayTracer|rayTraceKernel|raytrace.fun}}
Line 27: Line 32:
 
{{CodeToImplement|WorkStealingRayTracer|renderMyTasksUntilEmptyThenStealWorkFromOthers|raytrace.fun}}
 
{{CodeToImplement|WorkStealingRayTracer|renderMyTasksUntilEmptyThenStealWorkFromOthers|raytrace.fun}}
  
{{Sequential|private void renderMyTasksUntilEmptyThenStealWorkFromOthers(RayTraceTaskContext taskContext, List<ConcurrentLinkedDeque<Section>> quadrants, int id)}}
+
{{Sequential|private void renderMyTasksUntilEmptyThenStealWorkFromOthers(RayTraceTaskContext taskContext, Deque<Section> myTaskDeque, List<Deque<Section>> otherTaskDeques, int id)}}

Revision as of 07:01, 5 March 2019

Motivation

Gain some exposure to different task scheduling styles.

Background

Ray Tracing

Code To Investigate

class: SplitFourWayRayTracer.java DEMO: Java.png
methods: rayTrace
package: raytrace.demo
source folder: src//java

method: public void rayTrace(RayTraceContext context) Parallel.svg (parallel implementation required)

StaticScheduleRayTracer.png

Fun

DivideAndConquerRayTracer

DivideAndConquerRayTracer.png

Recursively divide the given region into 4 tasks for each of the four quadrants until you get below the threshold. When areaThreshold predicate test method returns false, call the rayTraceBaseCase(context, xMin, yMix, xMax, yMax) method to render the section.

class: DivideAndConquerRayTracer.java Java.png
methods: rayTraceKernel
package: raytrace.fun
source folder: student/src/main/java

method: private void rayTraceKernel(RayTraceContext context, int xMin, int yMin, int xMax, int yMax, int areaThreshold) Parallel.svg (parallel implementation required)

WorkStealingRayTracer

WorkStealingRayTracer.png

The renderMyTasksUntilEmptyThenStealWorkFromOthers method will be called on one of the four quadrants, but it will be given the sections that make up all four quadrants. You can use the id to find the particular quadrant being called.

This method should repeatedly draw from the tail of its own double-ended queue to render its own tasks using the Section.render method. If it finishes all of its tasks, and there are still unfinished tasks in the other quadrants, then it should draw tasks from the head of the other quadrants' deques.

As you can see in the WorkStealingRayTracer.rayTrace method, the parallelism comes from the fact that the renderMyTasksUntilEmptyThenStealWorkFromOthers method is called multiple times in parallel. You don't have to worry about spawning new tasks. Also, because ConcurrentLinkedDeque is thread-safe, all operations are atomic, so you you shouldn't need to use isolated. However, you should avoid reading and then writing.

class: WorkStealingRayTracer.java Java.png
methods: renderMyTasksUntilEmptyThenStealWorkFromOthers
package: raytrace.fun
source folder: student/src/main/java

method: private void renderMyTasksUntilEmptyThenStealWorkFromOthers(RayTraceTaskContext taskContext, Deque<Section> myTaskDeque, List<Deque<Section>> otherTaskDeques, int id) Sequential.svg (sequential implementation only)