Unit 3
Unit 3
Reduce
Scatter
Gather
M One-to-All Broadcast M M M
7 6 5 4
0 1 2 3
2
3 3
High Performanc Computing (2019 course)
All-to-One Reduction on Rings
All-to-One Reduction Reduction on an eight-node
ring with node 0 as the destination of the reduction
1 1
2
7 6 5 4
0 1 2 3
2
1 1
High Performanc Computing (2019 course)
Broadcast and Reduction: Example
Consider the problem of multiplying a matrix with a vector:
The n × n matrix is assigned to an n × n (virtual) processor grid
The vector is assumed to be on the first row of processors
The first step of the product requires a one-to-all broadcast of the
vector element along the corresponding column of processors
The processors compute local product of the vector element and
the local matrix entry
In the final step, the results of these products are accumulated to
the first row using n concurrent all-to-one reduction operations
along the columns (using the sum operation)
P4 ˇ P4 ˇ P5 ˇ P6 ˇP7
P8 ˇ P8 ˇ P9 ˇP10 ˇP11 Matrix
P12 ˇ P12 ˇ P13 ˇ P14 ˇP15
Output Vector
3 7 11 15
4 4 4 4
2 6 10 14
3 3 3 3
1 5 9 13
4 4 4 4
2 2
0 4 8 12
1
High Performanc Computing (2019 course)
Broadcast and Reduction on a Hypercube
A hypercube with 2d nodes can be regarded as a d
dimensional mesh with two nodes in each dimension
The mesh algorithm can be generalized to a hypercube
and the operation is carried out in d (= log p) steps.
2 3
1 4 5
(101)
(100)
0 1
(000) 3 (001)
2 2
3 3 3 3
0 1 2 3 4 5 6 7
7 6 5 4
(7) (4)
(6) (5)
1(7) 1 (3)
(0) (2)
(1) (3)
0 1 2 3
7 6 5 4
(7,6) (4,3)
(6,5) (5,4)
2(6) 2 (2)
(0,7) (2,1)
(1,0) (3,2)
0 1 2 3
7 6 5 4
(7,6,5,4,3,2,1)
(6,5,4,3,2,1,0) (5,4,3,2,1,0,7) (4,3,2,1,0,7,6)
7(1) 7 (5)
(0,7,6,5,4,3,2) (1,0,7,6,5,4,3) (2,1,0,7,6,5,4) (3,2,1,0,7,6,5)
0 1 2 3
(6) 6 7 8 (6,7,8) 6 7 8
3 4 5 3 4 5
(3) (4) (5) (3,4,5) (3,4,5) (3,4,5)
0 1 2 0 1 2
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Brrier(MPI_COMM_WORLD);
printf("Hello, world. I am %d of %d\n", rank, nprocs);
fflush(stdout);
MPI_Finalize();
return 0;
}