




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Correcting Threading Errors with Intel Parallel Inspector2Intel Parallel InspectorObjectivesAfter successful completion of this module you will be able toUse Parallel Inspector to detect and identify a variety of threading correctness issues in threaded applications Determine if library functions ar
2、e thread-safe3Intel Parallel InspectorAgendaWhat is Intel Parallel Inspector?Detecting race conditions Detecting potential for deadlockChecking library thread-safety4Intel Parallel InspectorMotivationDeveloping threaded applications can be a complex taskNew class of problems are caused by the intera
3、ction between concurrent threadsData races or storage conflictsMore than one thread accesses memory without synchronizationDeadlocks Thread waits for an event that will never happen5Intel Parallel InspectorIntel Parallel InspectorDebugging tool for threaded softwarePlug-in to Microsoft* Visual Studi
4、o*Finds threading bugs in OpenMP*, Intel Threading Building Blocks, and Win32* threaded softwareLocates bugs quickly that can take days to find using traditional methods and toolsIsolates problems, not the symptomsBug does not have to occur to find it!Intel Parallel Inspector FeaturesIntegrated into
5、 Microsoft Visual Studio .NET* IDE2005 & 2008 EditionsSupports different compilersMicrosoft* Visual* C+ .NET*Intel Parallel ComposerView (drill-down to) source code for DiagnosticsOne-click help for diagnosticsPossible causes and solution suggestions6Intel Parallel Inspector7Intel Parallel Inspector
6、Parallel Inspector: Analysis Dynamic as software runsData (workload) -driven executionIncludes monitoring of:Thread and Sync APIs usedThread execution order Scheduler impacts resultsMemory accesses between threadsCode path must be executed to be analyzed8Intel Parallel InspectorParallel Inspector: B
7、efore You StartInstrumentation: backgroundAdds calls to library to record informationThread and Sync APIsMemory accessesIncreases execution time and sizeUse small data sets (workloads)Execution time and space is expandedMultiple runs over different paths yield best resultsWorkload selection is impor
8、tant! 9Intel Parallel InspectorWorkload GuidelinesExecute problem code once per thread to be identifiedUse smallest possible working data set Minimize data set sizeSmaller image sizesMinimize loop iterations or time stepsSimulate minutes rather than daysMinimize update ratesLower frames per secondFi
9、nds threading errors faster!10Intel Parallel InspectorBuilding for Parallel InspectorCompileUse dynamically linked thread-safe runtime libraries (/MDd)Generate symbolic information (/ZI)Disable optimization (/Od)Link Preserve symbolic information (/DEBUG)Specify relocatable code sections (/FIXED:NO)
10、11Intel Parallel InspectorBinary InstrumentationBuild with supported compilerRunning the applicationMust be run from within Parallel InspectorApplication is instrumented when executedExternal DLLs are instrumented as usedStarting Parallel InspectorBuild the Debug version of the application with appr
11、opriate flags set12Intel Parallel InspectorStarting Parallel InspectorSelect Parallel Inspector from the Tools menu13Intel Parallel InspectorYou can choose to look forMemory ErrorsThreading ErrorsStarting Parallel InspectorThe Configure Analysis window pops up14Intel Parallel InspectorSelect the lev
12、el of analysis to be carried out by Parallel InspectorThe deeper the analysis, the more thorough the results and the longer the execution timeClick Run AnalysisStarting Parallel InspectorThe initial (raw) results come up after analysis15Intel Parallel InspectorClick the Interpret Results button to f
13、ilter the raw data into more human consumable formatsStarting Parallel InspectorThe analysis results are gathered together in related categories16Intel Parallel InspectorDouble-click a line from the Problem Sets pane to see the source code that generated the diagnosticStarting Parallel InspectorThe
14、source lines involved in a data race can be shown17Intel Parallel Inspector18Intel Parallel InspectorActivity 1a - Potential Energy Build and run serial version Build threaded versionRun application in Parallel Inspector to identify threading problems19Intel Parallel InspectorRace ConditionsExecutio
15、n order is assumed but cannot be guaranteedConcurrent access of same variable by multiple threadsMost common error in multithreaded programsMay not be apparent at all times20Intel Parallel InspectorSolving Race ConditionsSolution: Scope variables to be local to threadsWhen to useValue computed is no
16、t used outside parallel regionTemporary or “work” variablesHow to implementOpenMP scoping clauses (private, shared)Declare variables within threaded functionsAllocate variables on thread stackTLS (Thread Local Storage) API21Intel Parallel InspectorSolving Race ConditionsSolution: Control shared acce
17、ss with critical regionsWhen to useValue computed is used outside parallel regionShared value is required by each threadHow to implementMutual exclusion and synchronizationLock, semaphore, event, critical section, atomicRule of thumb: Use one lock per data element22Intel Parallel InspectorActivity 1
18、b - Potential Energy Fix errors found by Parallel Inspector23Intel Parallel InspectorDeadlockCaused by thread waiting on some event that will never happenMost common cause is locking hierarchiesAlways lock and un-lock in the same orderAvoid hierarchies if possibleDWORD WINAPI threadA(LPVOID arg) Ent
19、erCriticalSection(&L1); EnterCriticalSection(&L2); processA(data1, data2); LeaveCriticalSection(&L2); LeaveCriticalSection(&L1); return(0);DWORD WINAPI threadB(LPVOID arg) EnterCriticalSection(&L2); EnterCriticalSection(&L1); processB(data2, data1) ; LeaveCriticalSection(&L1);LeaveCriticalSection(&L
20、2); return(0);ThreadA: L1, then L2ThreadB: L2, then L124Intel Parallel InspectorDeadlockAdd lock per elementLock only elements, not whole array of elementsvoid swap (shape_t A, shape_t B) lock(a.mutex); lock(b.mutex);/ Swap data between A & B unlock(b.mutex); unlock(a.mutex);typedef struct / some da
21、ta things SomeLockType mutex; shape_t;shape_t Q1024;swap(Q986, Q34);Thread 4swap(Q34, Q986);Thread 1Grabs mutex 34Grabs mutex 98625Intel Parallel InspectorWindows* Critical SectionLightweight, intra-process only mutexMost useful and most usedNew type CRITICAL_SECTION cs;Create and destroy operations
22、InitializeCriticalSection(&cs)DeleteCriticalSection(&cs);26Intel Parallel InspectorWindows* Critical SectionCRITICAL_SECTION cs ;Attempt to enter protected code EnterCriticalSection(&cs)Blocks if another thread is in critical sectionReturns when no thread is in critical sectionUpon exit of critical
23、sectionLeaveCriticalSection(&cs)Must be from obtaining thread27Intel Parallel InspectorExample: Critical Section#define NUMTHREADS 4CRITICAL_SECTION g_cs; / why does this have to be global?int g_sum = 0;DWORD WINAPI threadFunc(LPVOID arg ) int mySum = putation(); EnterCriticalSection(&g_cs); g_sum +
24、= mySum; / threads access one at a time LeaveCriticalSection(&g_cs); return 0;main() HANDLE hThreadNUMTHREADS; InitializeCriticalSection(&g_cs); for (int i = 0; i NUMTHREADS; i+) hThreadi = CreateThread(NULL,0,threadFunc,NULL,0,NULL); WaitForMultipleObjects(NUMTHREADS, hThread, TRUE, INFINITE); Dele
25、teCriticalSection(&g_cs);28Intel Parallel InspectorActivity 2 - DeadlockUse Intel Parallel Inspector to find and correct the potential deadlock problem.29Intel Parallel InspectorThread Safe RoutinesAll routines called concurrently from multiple threads must be thread safeHow to test for thread safet
26、y?Use OpenMP and Parallel Inspector for analysisUse sections to create concurrent execution30Intel Parallel InspectorThread Safety ExampleCheck for safety issues betweenMultiple instances of routine1()Instances of routine1() and routine2()Set up sections to test all permutationsStill need to provide
27、 data sets that exercise relevant portions of code#pragma omp parallel sections#pragma omp section routine1(&data1);#pragma omp section routine1(&data2);#pragma omp section routine2(&data3);31Intel Parallel InspectorIt is better to make a routine reentrant than to add synchronizationAvoids potential overhead Two Ways to Ensure
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025黑龍江黑河市漠河市公益性崗位招聘18名模擬試卷及答案詳解(易錯題)
- 2025福建廈門市翔安招商集團有限公司(第一期)招聘4人模擬試卷及一套參考答案詳解
- 安全培訓(xùn)自查工作方案課件
- 2025年山東青島西海岸新區(qū)“千名人才進新區(qū)”集中引才考前自測高頻考點模擬試題及參考答案詳解1套
- 涂料產(chǎn)品施工知識培訓(xùn)課件
- 2025河北承德市灤平縣衛(wèi)生健康局和灤平縣醫(yī)療保障局所屬事業(yè)單位選調(diào)醫(yī)療專業(yè)技術(shù)人員15人模擬試卷及參考答案詳解
- 涂布安全知識培訓(xùn)課件
- 2025年甘肅省酒泉市瓜州縣博物館招聘公益性崗位工作人員考前自測高頻考點模擬試題及答案詳解(考點梳理)
- 2025廣西河池市招聘中小學(xué)緊缺學(xué)科教師118人模擬試卷及答案詳解(典優(yōu))
- 2025江西景德鎮(zhèn)陶瓷大學(xué)科研助理崗位招聘11人考前自測高頻考點模擬試題及完整答案詳解
- 日本商務(wù)談判風(fēng)格剖析課件
- 頂管頂力計算
- 綜合實踐活動課程的設(shè)計與實施
- 《影視鑒賞》教學(xué)課件 《影視鑒賞》第三章
- 職工三級安全教育卡模版
- 新疆民族團結(jié)模范人物
- 四議兩公開工作法課件
- 供應(yīng)鏈金融業(yè)務(wù)培訓(xùn)課件
- 幼兒教育政策法規(guī)解讀-高職-學(xué)前教育專業(yè)課件
- 污染場地環(huán)境風(fēng)險管理與原位地下水修復(fù)技術(shù) 陳夢舫
- GB∕T 26745-2021 土木工程結(jié)構(gòu)用玄武巖纖維復(fù)合材料
評論
0/150
提交評論