26
Destroy the Castle – Example Instructions

Destroy the Castle – Example Instructions. Functional Decomposition2 Lab 1 Activity 1 Build, Run, and Benchmark

Embed Size (px)

Citation preview

Destroy the Castle – Example Instructions

Functional Decomposition 2

Lab 1 Activity 1 Build, Run, and Benchmark

Functional Decomposition 3

Lab 1 Activity 1 Step 1 Open ParallelDemo.sln

Functional Decomposition 4

Lab 1 Activity 1 Step 2 Set Main as StartUp Project

Functional Decomposition 5

Lab 1 Activity 1 Step 3a

Set Project Properties Include Path to point to DX7SDK/include directory

Set Project Properties Library Path to point to DX7SDK/Lib

Build in Debug Mode and run.◦Notice abysmal performance◦Why is this the case?

Functional Decomposition 6

Lab 1 Activity 1 Steps 3-4 Switch to Release Mode

or

Functional Decomposition 7

Lab 1 Activity 1 Steps 5-6 Build and Run

Functional Decomposition 8

Lab 1 Activity 1 Steps 7-11 Benchmark the Castle Demo

Functional Decomposition9

Lab 1 Activity 1 Results – Single Threaded

Run 1 Run 2 Run 3 Average

47 FPS 48 FPS 47 FPS 47 FPS

Functional Decomposition 10

Lab 1 Activity 2 Data Synchronization

Functional Decomposition 11

Lab 1 Activity 2 Step 1 Open ParallelDemo.cpp

Functional Decomposition 12

Lab 1 Activity 2 Steps 2-3 Declare Variable for Physics

///////////////////////////////////////////////////////////////////////////// ////// Lab 1 Activity 2: Declare Variable ////// ////// Declare variable pointer for the physics (Dynamics*) ////// Initialize to NULL ////// ///

/// ------------------------- INSERT CODE HERE ----------------------- ///Dynamics* pDynamics = NULL;

/// /////////////////////////////////////////////////////////////////////////////

Functional Decomposition 13

Lab 1 Activity 2 Steps 4-5 Get Physics Data

///////////////////////////////////////////////////////////////////////////// ////// Lab 1 Activity 2: Get Physics Data ////// ////// Call the GetDynamics function of the castle simulation class ////// (s_pCastleSimulation) ////// ///

/// ------------------------- INSERT CODE HERE ----------------------- ///pDynamics = s_pCastleSimulation->GetDynamics();

/// /////////////////////////////////////////////////////////////////////////////

Functional Decomposition 14

Lab 1 Activity 2 Steps 6-7 Replace with Variable

///////////////////////////////////////////////////////////////////////////// ////// Lab 1 Activity 2: Replace Dynamics ////// ////// Replace call to GetDynamics with the newly created variable ////// ///

/// ------------------------- INSERT CODE HERE ----------------------- ///s_pBugs->Update( s_pCastleSimulation->GetDynamics() );

/// /////////////////////////////////////////////////////////////////////////////pDynamics

Functional Decomposition 15

Lab 1 Activity 2 Steps 8-9 Get Insect Data

///////////////////////////////////////////////////////////////////////////// ////// Lab 1 Activity 2: Get Bug Data ////// ////// Call the GetInstances function of the bugs class (s_pBugs) ////// ///

/// ------------------------- INSERT CODE HERE ----------------------- ///s_pBugs->GetInstances( &pBugInstances );

/// /////////////////////////////////////////////////////////////////////////////

Functional Decomposition 16

Lab 1 Activity 2 Steps 10-12 Replace with Variable

///////////////////////////////////////////////////////////////////////////// ////// Lab 1 Activity 2: Replace Dynamics and Bugs ////// ////// Replace call to GetDynamics with the newly created variable ////// Remove the call to get bug information ////// ///

/// ------------------------- INSERT CODE HERE ----------------------- ///s_pBugs->GetInstances( &pBugInstances );s_pParticles->Update( s_pCastleSimulation->GetDynamics(), g_pCamera, pBugInstances, ( s_bPauseSimulation || s_bPauseParticles ) );

/// /////////////////////////////////////////////////////////////////////////////

pDynamics

Functional Decomposition 17

Lab 1 Activity 2 Step 13 Build and Run

Functional Decomposition 18

Lab 1 Activity 3 Implement Functional Decomposition

Physics

AI

Particles

Main Main

Functional Decomposition 19

Lab 1 Activity 3 Steps 1-3 Create Synchronization Events

s_hTickDoneEvent[n] = CreateEvent( NULL, TRUE, FALSE, NULL );

Functional Decomposition 20

Lab 1 Activity 3 Steps 4-6 Destroy Synchronization Events

WaitForMultipleObjects( NUM_EVENTS, s_hTickDoneEvent, TRUE, INFINITE );

CloseHandle( s_hTickDoneEvent[n] );

Functional Decomposition 21

Lab 1 Activity 3 Steps 7-8 Wait for Threads

WaitForMultipleObjects( NUM_EVENTS, s_hTickDoneEvent, TRUE, INFINITE );

Functional Decomposition 22

Lab 1 Activity 3 Steps 9-12 Thread Functional Block

ResetEvent( s_hTickDoneEvent[n] );

QueueUserWorkItem( …ThreadProc, NULL, WT_EXECUTELONGFUNCTION );

Functional Decomposition 23

Lab 1 Activity 3 Steps 13-15 Implement Threaded Functional Block

s_pCastleSimulation->Tick();ors_pBugs->Tick();ors_pParticles->Tick();

SetEvent( s_hTickDoneEvent[n] );

Functional Decomposition 24

Lab 1 Activity 3 Step 16 Build and Run

Functional Decomposition 25

Lab 1 Activity 3 Steps 17-18 Benchmark Multi-Threaded Version

Functional Decomposition26

Lab 1 Activity 3 Results – Multi-Threaded

Run 1 Run 2 Run 3 Average Speed Up

77 FPS 79 FPS 78 FPS 78 FPS 1.7x