联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2025-05-12 09:14

Beijing-Dublin International College

COMP3036J - Parallel and Cluster Computing

Assignment 1

Assignment Details:

• Assignment Type: Code and report

• Release Date: 14-April-2025

• Weighting: 15%

• Due Date: 10-May-2025 (4 Weeks)

• Method of Submission: Moodle (.pdf and .c file) and beckett4 (.c file)

Task:

Implement a ”hot-potato” game using point-to-point communication in a logical ring of processes. A message

(the“potato”) with a decreasing timer is passed randomly to one of the neighbors. When the timer reaches

0, the current process is ”burnt” and exits the ring. The game continues until one process remains.

Game Rules and Simulation Logic

• Each MPI process represents a player in a circular game of hot-potato.

• A ”potato” is a message containing:

– A countdown timer (integer)

– A player ID for tracking

• The potato starts from a randomly chosen process and is passed to one of its neighbors (next or

previous in the ring).

• The timer is decremented at each pass.

• When the timer hits 0, the current process is eliminated (burnt) and exits the game.

• The remaining processes re-form the ring, and the game continues with a new potato.

• The game ends when only one process remains, and that process is declared the winner.

1

Implementation Guidelines

1. MPI Setup

• Use MPI_Init, MPI_Comm_rank, MPI_Comm_size to initialize the MPI environment.

• Each process should determine its left and right neighbors in the ring: left = (rank - 1 +

size) % size

right = (rank + 1) % size

2. Potato Structure Define a simple struct to represent the potato:

1 typedef struct {

2 int timer;

3 int origin_rank;

4 } Potato;

3. Potato Passing

• Use MPI_Send and MPI_Recv to pass the potato to a neighbor.

• Decrement the timer by 1 before sending.

• Print logs at each hop:

1 Process 3 received the potato with timer = 4

2 Process 3 passed the potato to 4

4. Elimination

• If the timer reaches 0, the process logs:

1 Process 4 is eliminated.

5. Game Continuation

• A new potato may be initialized or the last surviving potato continues until 1 remains.

• Final process logs:

1 Process 1 is the winner!

6. Sample Output (for 5 processes)

1 [Game Start] Process 2 starts with the potato. Timer = 5

2 Process 2 received the potato with timer = 5

3 Process 2 passed the potato to 3

4 Process 3 received the potato with timer = 4

5 Process 3 passed the potato to 4

6 Process 4 received the potato with timer = 3

7 Process 4 passed the potato to 0

8 Process 0 received the potato with timer = 2

9 Process 0 passed the potato to 1

10 Process 1 received the potato with timer = 1

11 Process 1 is eliminated.

12

13 Process 2 received the potato with timer = 5

14 ...

15 Process 4 is the winner!

2

Deliverables:

• Source code (hot_potato.c) implementing the hot-potato simulation.

• Sample run logs showing potato passing and elimination (Can be annexed to the report)

• Short report (500–700 words) explaining the logic, process coordination, and any corner cases handled.

The document should include the following sections:

– Logic and design decisions

– Use of MPI communication

– How random selection and eliminations are handled

Grading

• Correct implementation of logic & exit conditions 35%

• Use of MPI communication patterns (Send/Recv) 20%

• Random neighbor selection & timer decrementing 15%

• Clarity of report and explanation of logic 20%

• Code readability, organization, documentation 10%

3


相关文章

【上一篇】:到头了
【下一篇】:没有了

版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp