Hands-on: Collective operations
mpi/collectives/
First, write a program where rank 0 sends an array containing numbers from 0to 7 to all the other ranks using collective communication.Next, we continue with four MPI tasks with following initial data vectors:
Task 0: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
Task 1: | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Task 2: | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
Task 3: | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
in the buffer are initialized to -1. Implement a program that sends and
receives values from the data vectors to receive buffers using a single
collective communication routine for each case, so that the receive buffers
will have the following values. You can start from the skeleton file
skeleton.py
.Case 1
Task 0: | 0 | 1 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 1: | 2 | 3 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 2: | 4 | 5 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 3: | 6 | 7 | -1 | -1 | -1 | -1 | -1 | -1 |
Case 2
Task 0: | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 1: | 0 | 1 | 8 | 9 | 16 | 17 | 24 | 25 |
Task 2: | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 3: | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
Case 3
Task 0: | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 |
Task 1: | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
Task 2: | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 |
Task 3: | -1 | -1 | -1 | -1 | -1 | -1 | -1 | -1 |
Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.
Learn more about how FutureLearn is transforming access to education