Partitioning simply divides the problem into parts and then compute the parts and combine results.
Create a file called divide.c
1
2
mpicc -lm -o divide divide.c
mpirun -np 8 divide
conquer.c
1
2
mpicc -lm -o conquer conquer.c
mpirun -np 8 conquer
Many sorting algorithms can be parallelized by partitioning using divide and conquer
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
);
sendbuf: address of send buffer (choice, significant only at root)sendcount: integer array (of length group size) specifying the number of elements to send to each processordispls: integer array (of length group size). Entry i specifies the displacement (relative to sendbuf from which to take the outgoing data to process isendtype: data type of send buffer elementsrecvbuf: address of receive buffer (choice)recvcnt: number of elements in receive buffer (integer)recvtype: data type of receive buffer elementsroot: rank of sending process (integer)comm: communicator
1
2
mpicc -o scatterv scatterv.c
mpirun -np 4 scatterv
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
);
sendbuf: starting address of send buffer (choice)sendcount: number of elements in send buffer (integer)sendtype: data type of send buffer elementsrecvbuf: address of receive buffer (choice, significant only at root)recvcnts: integer array (of length group size) containing the number of elements that are received from each process (significant only at root)displs: integer array (of length group size). Entry i specifies the displacement relative to recvbuf at which to place the incoming data from process i (significant only at root)recvtype: data type of recv buffer elements (significant only at root)root: rank of receiving process (integer)comm: communicator
1
2
mpicc -o gatherv gatherv.c
mpirun -np 4 gatherv
1
2
mpicc -o bucket1 bucket1.c
mpirun -np 8 bucket1
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
);
sendbuf: starting address of send buffer (choice)sendcount: number of elements to send to each process (integer)sendtype: data type of send buffer elementsrecvbuf: address of receive buffer (choice)recvcount: number of elements received from any process (integer)recvtype: data type of receive buffer elementscomm: communicator
1
2
mpicc -o alltoall alltoall.c
mpirun -np 4 alltoall
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
);
sendbuf: starting address of send buffer (choice)sendcounts: integer array equal to the group size specifying the number of elements to send to each processorsdispls: integer array (of length group size). Entry j specifies the displacement (relative to sendbuf from which to take the outgoing data destined for process jsendtype: data type of send buffer elementsrecvbuf: address of receive buffer (choice)recvcounts: integer array equal to the group size specifying the maximum number of elements that can be received from each processorrdispls: integer array (of length group size). Entry i specifies the displacement (relative to recvbuf at which to place the incoming data from process irecvtype: data type of receive buffer elementscomm: communicator
1
2
mpicc -o alltoallv alltoallv.c
mpirun -np 4 alltoallv
1
2
mpicc -o bucket2 bucket2.c
mpirun -np 8 bucket2
Fundamental settings for most, if not all, of computational simulation problems:
Simulate how these reactions impact all entities and the entire space overtime
Start with whole region in which one square contains the bodies (or particles).