SlideShare a Scribd company logo
1 of 45
OpenMP for Beginners
김우현
SSM 24-1
- OpenMP tutorial -
Contents
1. Introduction……………………………………
2. Project Environment ………………………
3. Components of OpenMP …………………
4. Creating Threads……………………………
5. Data Scope Attribute………………………
6. For loop…………………………………………
7. Synchronization ……………………………
8. Reduction………………………………………
9. Reference………………………………………
10. Final Practice…………………………………
※ 단계별 소스코드 예제를 구현하면서 진행
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
2
~ 8min
~10min
~15min
~25min
~45min
~52min
~75min
~85min
~90min
 쓰레드 단위의 공유 메모리 다중 처리 프로그래밍 API
- 일련의 작업 처리를 위한 데이터들을 어떻게 분배할 것인가?
• Shared Memory
- 다수의 코어가 하나의 전역 메모리 공간을 사용
- 코어 간 데이터 수정, 공유에 대해 적은 비용부담
• Distributed Memory
- 각 코어마다 자신만의 지역 메모리 공간을 사용
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
3
1. Introduction
1.1. OpenMP(Open Multi-Processing) ?
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
4
1. Introduction
1.2. Evolution of Intel Processor
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
5
1. Introduction
1.2. Evolution of Intel Processor
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
6
1. Introduction
1.3. Parallel Programming API/languages
멀티 쓰레드 기반의 공유 메모리 병렬 프로그래밍
새로운 프로그래밍 언어가 아니다.
이미 작성된 순차적 프로그램에 적용할 수 있다.
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
7
1. Introduction
1.4. What is OpenMP ?
OpenMP는 사실상의 성숙한 표준
성능, 이식성, 확장성 ↑
병렬화를 위한 소스코드가 적다.
- 간결한 Serial code를 유지할 수 있다.
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
8
1. Introduction
1.5. Why OpenMP ?
컴파일러 지시
- #pragma omp parallel
런타임 라이브러리
- get_omp_thread_num();
환경 변수
- $ export OMP_NUM_THREADS = 4
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
9
1. Introduction
1.6. Consist
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
10
2. Project Environment
2.1. Visual Studio 2010
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
11
2. Project Environment
2.1. Visual Studio 2010
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
12
2. Project Environment
2.1. Visual Studio 2010
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
13
2. Project Environment
2.1. Visual Studio 2010
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
14
2. Project Environment
2.1. Visual Studio 2010
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
15
2. Project Environment
2.2. GCC/ICC …
Compile 시 다음의 옵션 추가
$ gcc –fopenmp
$ icc -openmp
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
16
3. Hello world !
3.1. Consist of OpenMP
< Serial code “1_hello_serial.c”>
1_hello.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
17
4. Create Threads
4.1. Create Threads 2_createThreads.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
18
4. Create Threads
4.2. Runtime Libraries related to Thread
Function : omp_~()
omp_get_num_procs() 코어 수 반환
omp_set_num_threads(integer) 사용할 쓰레드 수 설정
omp_get_max_threads() 현재 문맥에서의 가용 쓰레드 수
omp_get_thread_num() 현재 문맥에서의 쓰레드 수
omp_get_num_threads() 자신의 쓰레드 ID
3_threadLibraries.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
19
5. Data Scope Attribute
5. Data Scope Attribute
shared(=>default)
private
firstprivate
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
20
5. Data Scope Attribute
5.1. Data Scope Attribute
Shared Memory
4_dataScope1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
21
5. Data Scope Attribute
5.1. Data Scope Attribute 4_dataScope1.c
tid
tid = omp_get_thread_num();
Sleep(1);
printf(“I am %d (tid=%d) n”, omp_get_thread_num(), tid);
1
3
2
4
sleep
sleep
sleep
sleep
print
print
print
print
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
22
5. Data Scope Attribute
5.1. Data Scope Attribute 4_dataScope1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
23
5. Data Scope Attribute
5.1. Data Scope Attribute 4_dataScope1.c
#pragma omp parallel
{
int tid = omp_get_thread_num();
}
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
24
5. Data Scope Attribute
5.2. private 4_dataScope2.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
25
5. Data Scope Attribute
5.2. private 4_dataScope2.c
int tid;
#pragma omp parallel private(tid)
{
tid = omp_get_thread_num();
}
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
26
5. Data Scope Attribute
5.3. firstprivate 4_dataScope3.c
int tid = -1;
int i = 10;
#pragma omp parallel private(tid) firstprivate(i)
{
tid = omp_get_thread_num();
printf(“tid:%d, i:%d”, tid, i);
}
-1
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
27
5. Data Scope Attribute
5.4. shared 4_dataScope4.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
28
5. Data Scope Attribute
5.5. practice 4_dataScope4.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
29
6. For loop
6. For loop
‘for’directive
#private omp for
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
30
6. For loop
6.1. for loop 5_loop1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
31
6. For loop
6.1. for loop 5_loop1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
32
6. For loop
6.1. for loop 5_loop1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
33
6. For loop
6.1. for loop 5_loop1.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
34
7. Synchronization
7. Synchronization
Barrier
Critical
Atomic
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
35
7. Synchronization
7.1. barrier 6_sync0.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
36
7. Synchronization
7.2. critical, atomic 6_product_serial.c
6_sync1.c
6_sync2.c
6_sync3.c
6_sync4.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
37
7. Synchronization
7.3. critical example Break time
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
38
8. Reduction
8.1. Reduction 7_reduction.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
39
8. Reduction
8.1. Reduction 7_reduction.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
40
8. Reduction
8.2. Reduction operator
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
41
8. Reduction
8.3. Reduction examples
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
42
9. Reference
http://edu.ksc.re.kr
http://www.openmp.org
http://www.compunity.org
https://computing.llnl.gov/tutorials/openMP/
http://www.citutor.org
http://docs.oracle.com/cd/E19422-01/819-3694/
resources.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
43
Contest
http://hpcschool.kr/ksc2014/
[9.29~9.30]
Registration
7.14~8.24
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
44
10. Final Practice
Q1-serial.c
- 코드를 gcc를 통해 컴파일
- OpenMP를 통해 병렬화
Q1-serial.c
2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현
45
Thank you.
Q & A

More Related Content

Similar to OpenMP for beginners

Curso de JBPM5
Curso de JBPM5Curso de JBPM5
Curso de JBPM5
Oscar V
 
BPM for developers, extended
BPM for developers, extendedBPM for developers, extended
BPM for developers, extended
Alexander SAMARIN
 

Similar to OpenMP for beginners (20)

Agile process with a fixed cost
Agile process with a fixed costAgile process with a fixed cost
Agile process with a fixed cost
 
Document 14 (6).pdf
Document 14 (6).pdfDocument 14 (6).pdf
Document 14 (6).pdf
 
MTLM Visual Studio 2010 ALM workshop
MTLM Visual Studio 2010 ALM workshopMTLM Visual Studio 2010 ALM workshop
MTLM Visual Studio 2010 ALM workshop
 
Renesas DevCon 2010: Starting a QT Application with Minimal Boot
Renesas DevCon 2010: Starting a QT Application with Minimal BootRenesas DevCon 2010: Starting a QT Application with Minimal Boot
Renesas DevCon 2010: Starting a QT Application with Minimal Boot
 
Curso de JBPM5
Curso de JBPM5Curso de JBPM5
Curso de JBPM5
 
Qtp basics
Qtp basicsQtp basics
Qtp basics
 
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
 
TI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBootTI TechDays 2010: swiftBoot
TI TechDays 2010: swiftBoot
 
UiPath Task Capture training.pdf
UiPath Task Capture training.pdfUiPath Task Capture training.pdf
UiPath Task Capture training.pdf
 
JVM and OS Tuning for accelerating Spark application
JVM and OS Tuning for accelerating Spark applicationJVM and OS Tuning for accelerating Spark application
JVM and OS Tuning for accelerating Spark application
 
UDP Report
UDP ReportUDP Report
UDP Report
 
Profiling and optimizing go programs
Profiling and optimizing go programsProfiling and optimizing go programs
Profiling and optimizing go programs
 
Faster Python Programs Through Optimization by Dr.-Ing Mike Muller
Faster Python Programs Through Optimization by Dr.-Ing Mike MullerFaster Python Programs Through Optimization by Dr.-Ing Mike Muller
Faster Python Programs Through Optimization by Dr.-Ing Mike Muller
 
BPM for developers, extended
BPM for developers, extendedBPM for developers, extended
BPM for developers, extended
 
ELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot TimesELC-E 2010: The Right Approach to Minimal Boot Times
ELC-E 2010: The Right Approach to Minimal Boot Times
 
Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)Mule soft meetup__adelaide_october_2020_final (2)
Mule soft meetup__adelaide_october_2020_final (2)
 
How to Use OpenMP on Native Activity
How to Use OpenMP on Native ActivityHow to Use OpenMP on Native Activity
How to Use OpenMP on Native Activity
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
A challenge for thread parallelism on OpenFOAM
A challenge for thread parallelism on OpenFOAMA challenge for thread parallelism on OpenFOAM
A challenge for thread parallelism on OpenFOAM
 

Recently uploaded

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 

OpenMP for beginners

  • 1. OpenMP for Beginners 김우현 SSM 24-1 - OpenMP tutorial -
  • 2. Contents 1. Introduction…………………………………… 2. Project Environment ……………………… 3. Components of OpenMP ………………… 4. Creating Threads…………………………… 5. Data Scope Attribute……………………… 6. For loop………………………………………… 7. Synchronization …………………………… 8. Reduction……………………………………… 9. Reference……………………………………… 10. Final Practice………………………………… ※ 단계별 소스코드 예제를 구현하면서 진행 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 2 ~ 8min ~10min ~15min ~25min ~45min ~52min ~75min ~85min ~90min
  • 3.  쓰레드 단위의 공유 메모리 다중 처리 프로그래밍 API - 일련의 작업 처리를 위한 데이터들을 어떻게 분배할 것인가? • Shared Memory - 다수의 코어가 하나의 전역 메모리 공간을 사용 - 코어 간 데이터 수정, 공유에 대해 적은 비용부담 • Distributed Memory - 각 코어마다 자신만의 지역 메모리 공간을 사용 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 3 1. Introduction 1.1. OpenMP(Open Multi-Processing) ?
  • 4. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 4 1. Introduction 1.2. Evolution of Intel Processor
  • 5. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 5 1. Introduction 1.2. Evolution of Intel Processor
  • 6. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 6 1. Introduction 1.3. Parallel Programming API/languages
  • 7. 멀티 쓰레드 기반의 공유 메모리 병렬 프로그래밍 새로운 프로그래밍 언어가 아니다. 이미 작성된 순차적 프로그램에 적용할 수 있다. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 7 1. Introduction 1.4. What is OpenMP ?
  • 8. OpenMP는 사실상의 성숙한 표준 성능, 이식성, 확장성 ↑ 병렬화를 위한 소스코드가 적다. - 간결한 Serial code를 유지할 수 있다. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 8 1. Introduction 1.5. Why OpenMP ?
  • 9. 컴파일러 지시 - #pragma omp parallel 런타임 라이브러리 - get_omp_thread_num(); 환경 변수 - $ export OMP_NUM_THREADS = 4 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 9 1. Introduction 1.6. Consist
  • 10. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 10 2. Project Environment 2.1. Visual Studio 2010
  • 11. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 11 2. Project Environment 2.1. Visual Studio 2010
  • 12. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 12 2. Project Environment 2.1. Visual Studio 2010
  • 13. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 13 2. Project Environment 2.1. Visual Studio 2010
  • 14. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 14 2. Project Environment 2.1. Visual Studio 2010
  • 15. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 15 2. Project Environment 2.2. GCC/ICC … Compile 시 다음의 옵션 추가 $ gcc –fopenmp $ icc -openmp
  • 16. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 16 3. Hello world ! 3.1. Consist of OpenMP < Serial code “1_hello_serial.c”> 1_hello.c
  • 17. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 17 4. Create Threads 4.1. Create Threads 2_createThreads.c
  • 18. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 18 4. Create Threads 4.2. Runtime Libraries related to Thread Function : omp_~() omp_get_num_procs() 코어 수 반환 omp_set_num_threads(integer) 사용할 쓰레드 수 설정 omp_get_max_threads() 현재 문맥에서의 가용 쓰레드 수 omp_get_thread_num() 현재 문맥에서의 쓰레드 수 omp_get_num_threads() 자신의 쓰레드 ID 3_threadLibraries.c
  • 19. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 19 5. Data Scope Attribute 5. Data Scope Attribute shared(=>default) private firstprivate
  • 20. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 20 5. Data Scope Attribute 5.1. Data Scope Attribute Shared Memory 4_dataScope1.c
  • 21. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 21 5. Data Scope Attribute 5.1. Data Scope Attribute 4_dataScope1.c tid tid = omp_get_thread_num(); Sleep(1); printf(“I am %d (tid=%d) n”, omp_get_thread_num(), tid); 1 3 2 4 sleep sleep sleep sleep print print print print
  • 22. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 22 5. Data Scope Attribute 5.1. Data Scope Attribute 4_dataScope1.c
  • 23. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 23 5. Data Scope Attribute 5.1. Data Scope Attribute 4_dataScope1.c #pragma omp parallel { int tid = omp_get_thread_num(); }
  • 24. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 24 5. Data Scope Attribute 5.2. private 4_dataScope2.c
  • 25. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 25 5. Data Scope Attribute 5.2. private 4_dataScope2.c int tid; #pragma omp parallel private(tid) { tid = omp_get_thread_num(); }
  • 26. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 26 5. Data Scope Attribute 5.3. firstprivate 4_dataScope3.c int tid = -1; int i = 10; #pragma omp parallel private(tid) firstprivate(i) { tid = omp_get_thread_num(); printf(“tid:%d, i:%d”, tid, i); } -1
  • 27. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 27 5. Data Scope Attribute 5.4. shared 4_dataScope4.c
  • 28. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 28 5. Data Scope Attribute 5.5. practice 4_dataScope4.c
  • 29. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 29 6. For loop 6. For loop ‘for’directive #private omp for
  • 30. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 30 6. For loop 6.1. for loop 5_loop1.c
  • 31. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 31 6. For loop 6.1. for loop 5_loop1.c
  • 32. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 32 6. For loop 6.1. for loop 5_loop1.c
  • 33. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 33 6. For loop 6.1. for loop 5_loop1.c
  • 34. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 34 7. Synchronization 7. Synchronization Barrier Critical Atomic
  • 35. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 35 7. Synchronization 7.1. barrier 6_sync0.c
  • 36. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 36 7. Synchronization 7.2. critical, atomic 6_product_serial.c 6_sync1.c 6_sync2.c 6_sync3.c 6_sync4.c
  • 37. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 37 7. Synchronization 7.3. critical example Break time
  • 38. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 38 8. Reduction 8.1. Reduction 7_reduction.c
  • 39. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 39 8. Reduction 8.1. Reduction 7_reduction.c
  • 40. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 40 8. Reduction 8.2. Reduction operator
  • 41. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 41 8. Reduction 8.3. Reduction examples
  • 42. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 42 9. Reference http://edu.ksc.re.kr http://www.openmp.org http://www.compunity.org https://computing.llnl.gov/tutorials/openMP/ http://www.citutor.org http://docs.oracle.com/cd/E19422-01/819-3694/ resources.c
  • 43. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 43 Contest http://hpcschool.kr/ksc2014/ [9.29~9.30] Registration 7.14~8.24
  • 44. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 44 10. Final Practice Q1-serial.c - 코드를 gcc를 통해 컴파일 - OpenMP를 통해 병렬화 Q1-serial.c
  • 45. 2018-01-10OMP tutorial for Samsung Software Membership, 24-1 김우현 45 Thank you. Q & A

Editor's Notes

  1. 안녕하세요 OpenMP세미나를 진행하게된 24-1기 김우현입니다.
  2. 사용할 언어는 C이구요. 실습을 통해 OpenMP를 배워보도록 하겠습니다. 시작하기에 앞서서 병렬처리와 OpenMP에 대해 소개하고, 프로젝트 환경 세팅 후에 단계별 실습을 하겠습니다.
  3. OpenMP에 대해 설명하기 앞서서 잠깐 짚고 넘어갈 내용에 대해 이야기 해봅시다. 요즘 CPU는 하나의 프로세서에 다수의 코어가 존재하는데 이를 멀티코어 프로세서라 한다. 병렬프로그래밍은 그런 HW자원인 코어들을 모두 사용해서 성능을 최대한 끌어올리는 것이 목표. 즉 쓰레드를 사용하고 있지 않는 serial source는 실제 cpu 자원의 일부분만을 사용하고 있다. OpenMP는 쓰레드 단위로 작업을 분배하여 처리하기 위한 API 이해를 위해서 공유메모리와 분산(지역) 메모리를 간단하게 설명 그렇다면 이제 하드웨어를 살펴보자.
  4. 프로세서의 코어 성능은 향상되면서 동시에 사이즈가 줄어들었다. 캐쉬의 사이즈가 늘어났다. 하지만 일정 캐시 사이즈 이상부터는 프로세서의 성능에 큰 영향을 미치지 못했다. 또한 단일 코어의 성능 향상에 대한 한계점이 있었다.
  5. 하나의 프로세서에 코어를 여러 개 달게 되었다. 다수의 코어가 L3캐쉬를 공유하고 있다. 무어의 법칙은 여전히 만족하고 있다. 우리는 이러한 하드웨어 진화 과정을 이해하고 다수의 코어를 활용할 수 있어야 한다.
  6. 현재 병렬화를 지원하는 언어 및 라이브러리 등 다양하게 존재한다. Pthread, Win32 threads는 아마도 익숙할 것이다.
  7. 특징
  8. 가장 높은 성능을 가진 API는 아니다. 다양한 컴파일러에서 지원한다. 병렬화를 위한 소스코드가 줄어들게 되면 실제 수행을 위한 소스코드
  9. 요즘 CPU는 하나의 프로세서에 다수의 코어가 존재하는데 이를 멀티코어 프로세서라 한다. OpenMP는 프로세서에 일련의 작업 처리를 위하여 데이터들을 어떻게 분배할 것인지를 지시하는 언어
  10. (선택사항)
  11. (선택사항)
  12. (선택사항)
  13. (예제1)다음과 같은 시리얼 코드를 병렬화하면서 배운 것들을 확인해보자.
  14. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  15. 쓰레드와 관련한 몇 가지 라이브러리 함수를 익혀보자.
  16. 동기화 지시어가 굉장히 많은데, 그 중에서 대표적인 세가지만 살펴보겠습니다. 먼저 barrier 지시어를 통해 모든 쓰레드들이 해당 영역까지 도달하기까지 대기 하도록 합니다.
  17. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  18. 쓰레드가 print하기 전에 sleep 동안 공유 메모리값이 변하기 때문
  19. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  20. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  21. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  22. (예제2 끝낸 후)이후에 다시 #pragma omp parallel에서는 쓰레드는 몇 개 생성될까?
  23. Default data scope는 shared이다. 하지만 명시적으로 shared()를 붙여주면 병렬 영역에서의 가독성이 좋아진다.
  24. 이제 여태까지 배운 것들을 복습할 수 있는 간단한 예제를 풀어봅니다. int배열의 크기가 12라 할때 자신의 index+i값으로 데이터를 초기화하는 병렬 코드를 구현합니다. 여기에서 쓰레드 수는 4개, for문은 사용하지 않습니다.
  25. 동기화 지시어가 굉장히 많은데, 그 중에서 대표적인 세가지만 살펴보겠습니다. 먼저 barrier 지시어를 통해 모든 쓰레드들이 해당 영역까지 도달하기까지 대기 하도록 합니다.
  26. 이 전에 구현한 코드는 병렬처리를 통해 배열을 초기화해보았는데, 이번에는 for문을 통해 배열을 초기화 해봅니다.
  27. 그런데 여기에서 우리가 정작 병렬 프로그래밍을 통해 원했던 것은 어떤 작업을 위해 쓰레드 병렬화를 얼마나 시킬 것인지
  28. 그리고 어떤 작업을 할 것인지가 저희의 목표였습니다. 따라서 이 외적인 소스코드들은 전부 병렬화를 위한 코드였다는 것입니다. 이제부터는 병렬화 코드를 하나씩 줄여보겠습니다.
  29. 주석 처리하면 serial source code와 동일하다. 결론적으로 openMP를 얼마나 간결하게 사용할 수 있는지 알 수 있다.
  30. 동기화 지시어가 굉장히 많은데, 그 중에서 대표적인 세가지만 살펴보겠습니다. 먼저 barrier 지시어를 통해 모든 쓰레드들이 해당 영역까지 도달하기까지 대기 하도록 합니다.
  31. 동기화 지시어가 굉장히 많은데, 그 중에서 대표적인 세가지만 살펴보겠습니다. 먼저 barrier 지시어를 통해 모든 쓰레드들이 해당 영역까지 도달하기까지 대기 하도록 합니다.
  32. 이번에는 내적하는 serial code를 병렬화 해봅시다. 6_~.c 모두 설명
  33. 이번에는 내적하는 serial code를 병렬화 해봅시다. 6_~.c 모두 설명
  34. 최종적으로 도달한 방법은 이처럼 atomic을 통해 구현하는 것이었습니다. 하지만 여기에서 reduction을 사용하면 이 조차도 더 간단하게 구현을 할 수가 있습니다.
  35. 이전의 serial code에서의 결론은 atomic이었으나 우리가 원하는 것은 병렬화를 위한 소스코드를 최대한 줄이는 것. 그래서 openMP에는 reduction이라는 토큰을 통해 더 간결하게 작성할 수 있다. 여태까지 많은 것들을 배워왔는데, 이런 모든 것들은 reduction이라는 토큰을 통해 모두 한 줄로 처리가 가능하다. 그렇게 되면 모두 헛수고인 것처럼 느껴지지만, 내부적인 처리방식은 우리가 학습해본 마지막 방법을 통해 처리하게 된다.
  36. Reduction의 단점은 해당 scope에서는 한정된 연산만을 수행할 수 있다. 그리고 그 연산은 다음과 같다. 만약 reduction을 사용할 수 없는 복잡한 처리를 할 경우에는 atomic을 통해서 구현한다.
  37. 이 외에도 적분이나 몬테카를로 법을 통한 Pi계산 등 여러가지 예제가 있다.