100% Guaranteed Results


Parallel Programming – Solved
$ 29.99

Description

5/5 – (1 vote)

SLURM quick reference
srun [flags] ./prog
============ or ============
#!/bin/bash
#SBATCH [flags] srun ./prog # (MPI) ./prog # (non-MPI)
——— run with: ——-sbatch job.sh

[flags]:
-p debug or batch
-N number of nodes
-n number of processes -c CPUs per process
-t additional time limit
-J name of job

Outline
● Pthread
○ Hello world
○ Mutex
○ Condition variable
● OpenMP
● OpenMP + MPI
Running pthread programs on apollo
SYNOPSIS Type man pthread_create in terminal to see this
#include <pthread.h>
int pthread_create( pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); Compile and link with -pthread.
Running pthread programs on apollo
compile gcc hello_pthread.c -o hello_pthread -pthread
execute srun -c4 -n1 ./hello_pthread 4
-c4 means 4 CPUs per process
-n1 means 1 process
You can use sbatch as well
Outline
● Pthread
○ Hello world
○ Mutex
○ Condition variable
● OpenMP
● OpenMP + MPI

Mutex
#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int pthread_mutex_lock(pthread_mutex_t *mutex); int pthread_mutex_trylock(pthread_mutex_t *mutex); int pthread_mutex_unlock(pthread_mutex_t *mutex);
Mutex:
[Practice 1] approximate π using pthread
gcc pi_pthread.c -o pi_pthread -pthread -lm

Outline
● Pthread
○ Hello world
○ Mutex
○ Condition variable
● OpenMP
● OpenMP + MPI

Condition variable
#include <pthread.h>
pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond); int pthread_cond_wait( pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex);

Condition variable
pthread_cond_signal
Make 1 thread that called pthread_cond_wait to continue
pthread_cond_broadcast
Make all threads that called pthread_cond_wait to continue
pthread_cond_wait
Wait for some other thread to call pthread_cond_signal

[Practice 2] Condition variable
Compile and execute pthread_cond.c under lab2/
you should see →
which is incorrect
Modify the program using condition variable so it will wait until you input the values then print

Threads have been created
Enter 4 values
Values filled in array are
0
0
0
0

Outline
● Pthread
○ Hello world
○ Mutex
○ Condition variable
● OpenMP
● OpenMP + MPI
compile gcc hello_omp.c -o hello_omp -fopenmp
execute srun -c4 -n1 ./hello_omp
-c4 means 4 CPUs per process
-n1 means 1 process You can use sbatch as well
Try different number of threads!
Count prime numbers: sequential version
gcc -lm prime.c -o prime srun ./prime 1000 srun ./prime 10000000
Count prime numbers:
[Practice 3] OpenMP
1. Modify the sequential prime.c with openmp
2. Try to see the effect of changing dynamic/static scheduling chunk size number of threads
[example commands]
gcc -lm prime_omp.c -o prime_omp -fopenmp srun -c4 -n1 ./prime_omp 10000000
Outline
● Pthread
○ Hello world
○ Mutex
○ Condition variable
● OpenMP
● OpenMP + MPI
Hybrid MPI and OpenMP program
mpicc hello_hybrid.c -o hello_hybrid -fopenmp

srun -c3 -n2 ./hello_hybrid

Hybrid MPI and OpenMP program: Hello World
srun -c 3 -n2 -N2 ./hello_hybrid Hello apollo32: rank 0/ 2, thread 0/ 3
Hello apollo32: rank 0/ 2, thread 1/ 3
Hello apollo32: rank 0/ 2, thread 2/ 3
Hello apollo33: rank 1/ 2, thread 0/ 3
Hello apollo33: rank 1/ 2, thread 1/ 3
Hello apollo33: rank 1/ 2, thread 1/ 3
Hybrid MPI and OpenMP program: [Practice 4] Approximate π
Use MPI and OpenMP to approximate π
(You can refer to your lab1b code)

Reviews

There are no reviews yet.

Be the first to review “Parallel Programming – Solved”

Your email address will not be published. Required fields are marked *

Related products