Partitioning: Divide and Conquer

Final Exam

Overview

Partitioning

Partitioning simply divides the problem into parts and then compute the parts and combine results.

Divide and Conquer
Divide process
Divide process with process ID
Divide

Create a file called divide.c

1
2
mpicc -lm -o divide divide.c
mpirun -np 8 divide
Run divide
Conquer
1
2
mpicc -lm -o conquer conquer.c
mpirun -np 8 conquer
Run conquer

Many sorting algorithms can be parallelized by partitioning using divide and conquer

Bucket Sort

Overview
Overview of Bucket Sort
Simple approach
A simple approach to Bucket Sort
Scatter and Scatterv Syntax
1
2
3
4
5
6
7
8
9
int MPI_Scatter(
    void *sendbuf, 
    int sendcount, 
    MPI_Datatype sendtype, 
    void *recvbuf,
    int recvcnt,
    MPI_Datatype recvtype,
    int root, 
    MPI_Comm comm);
1
2
3
4
5
6
7
8
9
10
11
int MPI_Scatterv(
  void *sendbuf,
  int *sendcount,
  int *displs,
  MPI_Datatype sendtype,
  void *recvbuf,
  int recvcnt,
  MPI_Datatype recvtype,
  int root,
  MPI_Comm comm
);
Hands-on: Scatterv
1
2
mpicc -o scatterv scatterv.c
mpirun -np 4 scatterv
Run Scatterv
Gather and Gatherv Syntax
1
2
3
4
5
6
7
8
9
int MPI_Gather(
    void *sendbuff, 
    int sendcount, 
    MPI_Datatype sendtype, 
    void *recvbuff,
    int recvcnt,
    MPI_Datatype recvtype,
    int root, 
    MPI_Comm comm);
1
2
3
4
5
6
7
8
9
10
11
int MPI_Gatherv(
  void *sendbuf,
  int sendcount,
  MPI_Datatype sendtype,
  void *recvbuf,
  int *recvcnts,
  int *displs,
  MPI_Datatype recvtype,
  int root,
  MPI_Comm comm
);
Hands-on: Gatherv
1
2
mpicc -o gatherv gatherv.c
mpirun -np 4 gatherv
Run Gatherv
Simple approach implementation
1
2
mpicc -o bucket1 bucket1.c
mpirun -np 8 bucket1

Complex Parallel Bucket Sort

Overview
Complex approach to Bucket Sort
All to all
All to all explanation
Alltoall
1
2
3
4
5
6
7
8
9
int MPI_Alltoall(
  void *sendbuf,
  int sendcount,
  MPI_Datatype sendtype,
  void *recvbuf,
  int recvcount,
  MPI_Datatype recvtype,
  MPI_Comm comm
);
Hands-on: Alltoall
1
2
mpicc -o alltoall alltoall.c 
mpirun -np 4 alltoall
Run All to all
Alltoallv
1
2
3
4
5
6
7
8
9
10
11
int MPI_Alltoallv(
  void *sendbuf,
  int *sendcounts,
  int *sdispls,
  MPI_Datatype sendtype,
  void *recvbuf,
  int *recvcounts,
  int *rdispls,
  MPI_Datatype recvtype,
  MPI_Comm comm
);
Hands-on: Alltoallv
1
2
mpicc -o alltoallv alltoallv.c 
mpirun -np 4 alltoallv
Run All to allv
Complex approach implementation
1
2
mpicc -o bucket2 bucket2.c
mpirun -np 8 bucket2

N-Body Problem

Overview

Fundamental settings for most, if not all, of computational simulation problems:

Mass of multiple bodies
Barnes-Hut Algorithm (2-D)

Start with whole region in which one square contains the bodies (or particles).

Barnes-Hut algorithm
Orthogonal Recursive Bisection
Orthogonal bisection