Back
Close

Introduction to MPI

Aveuh
26.4K views

Probing information - exercise

In this exercise, we are going to use the probing mechanism to find out which process with which tag are trying to communicate pwith process 0. Your goal will be to handle process 0, the rest of the program will be hidden so you have no way of knowing which process is communicating what.

For this, you will need to use the MPI_Probe function, whose prototype is :

int MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status);

Remember that source (resp. tag) can be MPI_ANY_SOURCE (resp. MPI_ANY_TAG). The tag and source will be stored in the status variable.

MPI_Status

As a reminder, here's the corresponding structure of MPI_Status :

struct MPI_Struct {
  int MPI_SOURCE;
  int MPI_TAG;
  int MPI_ERROR;
  int _cancelled;
  size_t _ucount;
};

Exercise

You must fill in the function so that the process receives a message from any process. Then writes to stdout Received a message from process ## with tag ##. Then, if tag is 0, receive the message as a single integer and add it to int_sum. Else, if the tag is 1, receive the message as a single float and add it to the float_sum variable.

Probing
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
void probing_process(int &int_sum, float &float_sum) {
MPI_Status status;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants