Destroy the Castle – Example Instructions
Functional Decomposition2 Lab 1 Activity 1 Build, Run, and Benchmark
Functional Decomposition3 Lab 1 Activity 1 Step 1 Open ParallelDemo.sln
Functional Decomposition4 Lab 1 Activity 1 Step 2 Set Main as StartUp Project
Functional Decomposition5 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 Decomposition6 Lab 1 Activity 1 Steps 3-4 Switch to Release Mode or
Functional Decomposition7 Lab 1 Activity 1 Steps 5-6 Build and Run
Functional Decomposition8 Lab 1 Activity 1 Steps 7-11 Benchmark the Castle Demo
Functional Decomposition 9 Lab 1 Activity 1 Results – Single Threaded Run 1Run 2Run 3Average 47 FPS48 FPS47 FPS
Functional Decomposition10 Lab 1 Activity 2 Data Synchronization
Functional Decomposition11 Lab 1 Activity 2 Step 1 Open ParallelDemo.cpp
Functional Decomposition12 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 Decomposition13 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 Decomposition14 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 Decomposition15 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 Decomposition16 Lab 1 Activity 2 Steps 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 Decomposition17 Lab 1 Activity 2 Step 13 Build and Run
Functional Decomposition18 Lab 1 Activity 3 Implement Functional Decomposition Physics AI Particles Main
Functional Decomposition19 Lab 1 Activity 3 Steps 1-3 Create Synchronization Events s_hTickDoneEvent[n] = CreateEvent( NULL, TRUE, FALSE, NULL );
Functional Decomposition20 Lab 1 Activity 3 Steps 4-6 Destroy Synchronization Events WaitForMultipleObjects( NUM_EVENTS, s_hTickDoneEvent, TRUE, INFINITE ); … CloseHandle( s_hTickDoneEvent[n] );
Functional Decomposition21 Lab 1 Activity 3 Steps 7-8 Wait for Threads WaitForMultipleObjects( NUM_EVENTS, s_hTickDoneEvent, TRUE, INFINITE );
Functional Decomposition22 Lab 1 Activity 3 Steps 9-12 Thread Functional Block ResetEvent( s_hTickDoneEvent[n] ); QueueUserWorkItem( …ThreadProc, NULL, WT_EXECUTELONGFUNCTION );
Functional Decomposition23 Lab 1 Activity 3 Steps Implement Threaded Functional Block s_pCastleSimulation->Tick(); or s_pBugs->Tick(); or s_pParticles->Tick(); SetEvent( s_hTickDoneEvent[n] );
Functional Decomposition24 Lab 1 Activity 3 Step 16 Build and Run
Functional Decomposition25 Lab 1 Activity 3 Steps Benchmark Multi-Threaded Version
Functional Decomposition 26 Lab 1 Activity 3 Results – Multi-Threaded Run 1Run 2Run 3 AverageSpeed Up 77 FPS79 FPS78 FPS 1.7x