Advertisement
STEPAN_KODER_228

СТЕПАН КОДЕР 9

May 23rd, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. The code you provided has a few issues that need to be addressed:
  2.  
  3. 1. In the `worker_func` function, the line `MPI_Send(&stop_code, 1, MPI_INT, rank, TO_RECEIVER, MPI_COMM_WORLD);` should be changed to `MPI_Send(&stop_code, 1, MPI_INT, 0, TO_RECEIVER, MPI_COMM_WORLD);`. The receiver process has rank 0, so the stop code should be sent to rank 0.
  4.  
  5. 2. In the `receiver_func` function, the line `MPI_Send(&tasks[old_offset], tasks_length, MPI_INT, status_worker_requester.MPI_SOURCE, SEND_WORK_TAG, MPI_COMM_WORLD);` should be changed to `MPI_Send(&tasks[old_offset], tasks_length, MPI_INT, status_worker_requester.MPI_SOURCE, SEND_WORK_TAG, MPI_COMM_WORLD);`. This line sends the tasks back to the worker process that made the request.
  6.  
  7. 3. It seems like you intended to use the `rank` variable as the source argument in the `MPI_Send` function in the `worker_func` function. However, the correct source argument should be the rank of the receiver process, which is 0. Change the line `MPI_Send(&req_code, 1, MPI_INT, (int)i, TO_RECEIVER, MPI_COMM_WORLD);` to `MPI_Send(&req_code, 1, MPI_INT, 0, TO_RECEIVER, MPI_COMM_WORLD);` to send the request to the receiver process.
  8.  
  9. 4. You should join the worker and receiver threads using `pthread_join` before calling `MPI_Finalize()`. Add the following lines before `MPI_Finalize()` in the `main` function:
  10. ```c
  11. pthread_join(worker, NULL);
  12. pthread_join(receiver, NULL);
  13. ```
  14.  
  15. 5. There is a potential issue with the `do_tasks` function. The while loop condition `if(offset != size * MAX_TASKS - 1)` seems incorrect. It checks if the offset is not equal to `size * MAX_TASKS - 1`, and if it is not equal, it breaks the loop. This means the loop will only continue if the offset is equal to `size * MAX_TASKS - 1`, which is likely not the intended behavior. You might want to change the condition to `if(offset >= size * MAX_TASKS)` to break the loop when all tasks have been processed.
  16.  
  17. After addressing these issues, your code should run without the reported errors. Remember to compile and run the program with an MPI implementation and make sure you have more than one process running for proper execution.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement