Download presentation
Presentation is loading. Please wait.
Published byMelvin Cummings Modified over 8 years ago
1
Using Parallel Threads Why? When? Where? George Serbanut University of Turin / INFN Turin / ISS Bucharest (serbanut@to.infn.it) CSC – August 28 th, 2007
2
Aim CSC07George SerbanutSlide 02/10 Stage 1 (before) Stage 2 (after)
3
Outline CSC07George SerbanutSlide 03/10 ● What? ● How? ● Why? ● When? ● Where?
4
Outline CSC07George SerbanutSlide 03/10 ● What? - Definitions ● Where? - Modern (single core) CPU's ● How? - Simple examples in C/C++/JAVA ● Why? - Benchmark for Intel dual core2 (CygWin) ● Where and when? - Limitations in working with parallel threads
5
What? - Definitions CSC07George SerbanutSlide 04/10 ● Processing element (see GRID technologies) – A CPU / a set of CPU's connected by the same Mother Board (PC, laptop/notebook) ● Pipelines – Execution lines in the processing element ● Dataflow (see Network QoS & performances) – A stream of instructions ● Threaded dataflow (see TProof in ROOT) – A stream of instructions “flowing” in a pipeline
6
Where? - Modern Processing Elements CSC07George SerbanutSlide 05/10
7
Where? - Modern Processing Elements CSC07George SerbanutSlide 05/10 Pipelines here! Level of serialization defined here
8
C programming language #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello from thread 1"; char *message2 = "Hello from thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 06/10 See GNU POSIX threading (pthread) documentation
9
C programming language #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello from thread 1"; char *message2 = "Hello from thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 06/10 See GNU POSIX threading (pthread) documentation #include
10
C programming language #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello from thread 1"; char *message2 = "Hello from thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 06/10 See GNU POSIX threading (pthread) documentation pthread_t thread1, thread2;
11
C programming language #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello from thread 1"; char *message2 = "Hello from thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 06/10 See GNU POSIX threading (pthread) documentation iret1 = pthread_create(...)
12
C programming language #include void *print_message_function( void *ptr ); main() { pthread_t thread1, thread2; char *message1 = "Hello from thread 1"; char *message2 = "Hello from thread 2"; int iret1, iret2; iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); pthread_join( thread1, NULL); pthread_join( thread2, NULL); printf("Thread 1 returns: %d\n",iret1); printf("Thread 2 returns: %d\n",iret2); exit(0); } void *print_message_function( void *ptr ) { char *message; message = (char *) ptr; printf("%s \n", message); } How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 06/10 See GNU POSIX threading (pthread) documentation pthread_join( thread1, NULL);
13
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 07/10 C++ programming language class definition: class Thread { public: Thread(); int Start(void * arg); protected: int Run(void * arg); static void * EntryPoint(void*); virtual void Setup(); virtual void Execute(void*); void * Arg() const {return Arg_;} void Arg(void* a){Arg_ = a;} private: THREADID ThreadId_; void * Arg_; }; class implementation: Thread::Thread() {} int Thread::Start(void * arg) { Arg(arg); // store user data int code = thread_create(Thread::EntryPoint, this, & ThreadId_); return code; } int Thread::Run(void * arg) { Setup(); Execute( arg ); } /*static */ void * Thread::EntryPoint(void * pthis) { Thread * pt = (Thread*)pthis; pthis->Run( Arg() ); } virtual void Thread::Setup() { /*Do any setup here*/ } virtual void Thread::Execute(void* arg) { /*Your code goes here*/ } (See Ryan Teixeira's tutorial on internet)
14
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 07/10 C++ programming language class definition: class Thread { public: Thread(); int Start(void * arg); protected: int Run(void * arg); static void * EntryPoint(void*); virtual void Setup(); virtual void Execute(void*); void * Arg() const {return Arg_;} void Arg(void* a){Arg_ = a;} private: THREADID ThreadId_; void * Arg_; }; class implementation: Thread::Thread() {} int Thread::Start(void * arg) { Arg(arg); // store user data int code = thread_create(Thread::EntryPoint, this, & ThreadId_); return code; } int Thread::Run(void * arg) { Setup(); Execute( arg ); } /*static */ void * Thread::EntryPoint(void * pthis) { Thread * pt = (Thread*)pthis; pthis->Run( Arg() ); } virtual void Thread::Setup() { /*Do any setup here*/ } virtual void Thread::Execute(void* arg) { /*Your code goes here*/ } (See Ryan Teixeira's tutorial on internet) int code = thread_create(...)
15
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
16
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html import java.lang.Thread;
17
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html... extends Thread
18
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html public void run()
19
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html....start()
20
How? - Working with Threads ~ simple examples ~ CSC07George SerbanutSlide 08/10 JAVA: import java.lang.Thread; public class HelloThread extends Thread { public void HelloThread(int i) { counter = i; } public void run() { System.out.println("Hello from thread " + counter); } int counter; public static void main(String args[]) { (new HelloThread(1)).start(); (new HelloThread(2)).start(); } see http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html or SUN websitehttp://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html new versions of JAVA changed Thread with Runnable
21
Why? - Benchmark for Intel Dual Core2 (CygWin) CSC07George SerbanutSlide 09/10
22
When? - Working with Threads ~ limitations ~ CSC07George SerbanutSlide 10/10 No predefined ANSI threading implementation
23
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Slide 10/10
24
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Slide 10/10
25
When? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Slide 10/10
26
When? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Slide 10/10
27
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Under MS Windows OS: if used with GUI and if priority is not defined, the active window takes the highest priority Slide 10/10
28
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Under MS Windows OS: if used with GUI and if priority is not defined, the active window takes the highest priority he parallelization of the threads is done by a pseudo-serialization (so, weak enhancement in performances) Slide 10/10
29
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Under MS Windows OS: if used with GUI and if priority is not defined, the active window takes the highest priority he parallelization of the threads is done by a pseudo-serialization (so, weak enhancement in performances) On LINUX OS: starting with kernel 2.6, the threading system was rewritten from scratch, even though, POSIX threads kept the same function names. Slide 10/10
30
Where? - Working with Threads ~ limitations ~ CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Under MS Windows OS: if used with GUI and if priority is not defined, the active window takes the highest priority he parallelization of the threads is done by a pseudo-serialization (so, weak enhancement in performances) On LINUX OS: starting with kernel 2.6, the threading system was rewritten from scratch, even though, POSIX threads kept the same function names Parallel threads are defined on a single computer element for more advanced parallel computing see TProof, cluster and GRID technologies) Slide 10/10
31
When and where? - Working with Threads (limitations) CSC07George Serbanut No predefined ANSI threading implementation Each core of processing elements based on Intel 32-bits architecture (Intel, AMD) supports up to 16 pipelines Pipelines in processing units are FIFO Parallel threads do not work with static/constant defined members Initialization of threads takes CPU cycles Therefore not to be used in simple applications Under MS Windows OS: if used with GUI and if priority is not defined, the active window takes the highest priority he parallelization of the threads is done by a pseudo-serialization (so, weak enhancement in performances) On LINUX OS: starting with kernel 2.6, the threading system was rewritten from scratch, even though, POSIX threads kept the same function names Parallel threads are defined on a single computer element for more advanced parallel computing see TProof, cluster and GRID technologies) Slide 10/10
32
THANK YOU!
33
MIT Processing Element ~ static dataflow processors ~ CSC07George SerbanutSlide 03/17
34
MIT Processing Element ~ static dataflow processors ~ CSC07George SerbanutSlide 04/17
35
Manchester Processing Element ~ dynamic dataflow processors ~ CSC07George SerbanutSlide 05/10
36
Manchester Processing Element ~ dynamic dataflow processors ~ CSC07George SerbanutSlide 06/17
37
Monsoon Processing Element ~ explicit data store or controlled dataflow processors ~ CSC07George SerbanutSlide 07/17
38
Monsoon Processing Element ~ explicit data store or controlled dataflow processors ~ CSC07George SerbanutSlide 08/17
39
Processing Element ~ memory addressing and operations in controlled dataflow processors ~ CSC07George SerbanutSlide 09/17
40
Processing Element ~ hybrids ~ CSC07George SerbanutSlide 11/17
41
Processing Element ~ threads in hybrids ~ CSC07George SerbanutSlide 12/17 See http://csd.ijs.si/courses/processor/index.html for more informationhttp://csd.ijs.si/courses/processor/index.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.