Exercises
- Implement the ring algorithm using non-blocking functions, using the skeleton in ring.c, where the process with ID 0 sends a random number to process 1 (its neighbor), and then the other nodes will receive the number from the previous process, increment it by 2, and send it to the next process (for example, process 2 receives the value from process 1, increments it, and forwards it to process 3), ending when the value reaches process 0. For each process, you should display its rank and the received value (hint: the first exercise from laboratory 8).
- Solve the deadlock in the deadlock.c file in the lab skeleton in 3 variants (also check the hint below):
- using MPI_Sendrecv
- using MPI_Bsend
- using non-blocking functions - here, instead of MPI_Test and MPI_Wait, use MPI_Waitall.
- Starting from the code skeleton in queue.c, where processes run in a ring topology, create a new MPI data type based on the structure defined in the code. Each process will generate a random number, which will be added to the respective structure. In the end, process 0 will have each number generated by each process. After that, process 0 will display which elements are in the respective structure, which is a queue-like structure.
Bonus: Starting from the skeleton, use the barrier in the barrier.c file to ensure that the output in the file is always hello.
note
For exercise 2, you can use this hint.
tip
Adding to the queue is done as follows: q.arr[q.size++] = element;