Part8 ChoosingAppropriateThreadModel
Part8 ChoosingAppropriateThreadModel
Objectives
At the end of this module, you should be able to
Explain the relative advantages and
disadvantages of OpenMP compared to
Win32/Java/POSIX threads
Give examples of
Applications more suitable for a parallel
program based on OpenMP
Applications more suitable for a parallel
program based on Win32/Java/
POSIX threads
Fork/Join Nested
Fork/Join
Thread terminates
without join
Join
Function pthread_create
int pthread_create (
/* Pointer to thread ID */
pthread_t *thread,
/* Pointer to thread attribute object */
const pthread_attr_t *attr,
/* Function thread is to execute */
void *(*start)(void *),
/* Pointer to function argument */
void *arg);
Function pthread_join
int pthread_join (
/* Thread ID */
pthread_t thread,
/* Address of thread status pointer */
void **status);
C Code
OpenMP Design
Forked threads
follow links and
create snapshot
images
Forked threads
follow links and
create snapshot
images
Main thread
Retrieves page
Identifies links
Forks one thread per link to generate previews
Draws page
Waits for threads responsible for initially visible links
Created thread
Retrieves page and builds snapshot image
C / Pthreads Code
Thread States
State Meaning
Ready Able to run, waiting for CPU
Running Executing on a CPU
Blocked Waiting for an something, such as the
completion of an I/O operation or the
availability of a mutex
Terminated Has finished execution by returning
from start function or calling
pthread_exit or being cancelled
g h i
parallel
sections
parallel for j
Grid Refinement
Prioritizing Threads
Monster 3
Hero (Low priority)
Monster 1 Monster 2
(High priority) (medium priority)
Conclusion
References