Learning materials
Chapter 6: MPI Case Study, and Pthread
On this page
Pthread
- POSIX standard: Unix, Linux, BSD, etc.
- Thread library for POSIX Operating Systems
- Code
pthread.hheader file-lpthreadlinking flag for gcc
- Types
pthread_tthread handle object used to refer to a thread
- Function as parameter
- declaration like
void *function_name (void * arg); - parameter declared like
void *(*function_name)(void)
- declaration like
- API
pthread-createcreate a thread, run the function, return a pthread_t objectpthread-joinwait for the thread to finish
- Compilation with gcc
-pthreadflag, preferred-lpthreadold flag, retiring, should put at the very end of the gcc command line
Case Studies
Odd-even transportation sort
- Modified bubble sort to adapt to parallelization
- Assuming size
N, parallelized onPprocesses - Serial version
- Phase 0: compare and swap between even element with its right neighbor
- Phase 1: compare and swap between even element with its left neighbor
- N rounds to finish
- Parallelized with MPI
- Sort the local section first
- Phase 0: compare and exchange between even process with its right neighbor
- Phase 1: compare and swap between even process with its left neighbor
N-body MPI
- Decide the data structure
- each process stores a whole array of masses
- computes physical metrics of its share of local particles
- allgether to collect local position array to global position array