Skip to content
Snippets Groups Projects
Commit 2bdf3e52 authored by Chao Zhan's avatar Chao Zhan
Browse files

add MPI_Probe

parent 26bfd49c
No related branches found
No related tags found
No related merge requests found
...@@ -280,3 +280,61 @@ token -> 0 -> 1 -> 2 -> 3 -> 0 -> token ...@@ -280,3 +280,61 @@ token -> 0 -> 1 -> 2 -> 3 -> 0 -> token
Add all missing function calls in `exercises/MPI_examples/round_trip/round_trip.c` Add all missing function calls in `exercises/MPI_examples/round_trip/round_trip.c`
---
title: MPI IX
---
### Message Reception and Status
The receive buffer must be able to fit the entire message:
- send count <= receive count (<span class="text-green-500">OK</span>)
- send count > receive count (<span class="text-rose-500">Error: message truncation</span>)
The MPI status object holds information about the received message.
**MPI_Status status**:
```c
status.MPI_SOURCE // message source rank
status.MPI_TAG // message tag
status.MPI_ERROR // receive status code
```
### Message Size Inquiry
**MPI_Get_count (MPI_Status \*status, MPI_Datatype datatype, int \*count)**
- Calculates how many **datatype** elements can be formed from the data in the message referenced by status
- Can be used with the status from **MPI_Recv** or **MPI_Probe**
---
title: MPI Probe
---
### MPI Probe
Blocks until a matching message appears without actually receiving the message:
**MPI_Probe (int source, int tag, MPI_Comm comm, MPI_Status \*status)**
One must still call **MPI_Recv** to receive the message and copy the data into the buffer.
When probing tells you that there is a message, you can use **MPI_Get_count** to determine its size, allocate a large enough receive buffer, and do a regular receive to have the data copied.
```c
if (rank == receiver) {
MPI_Status status;
MPI_Probe(sender, 0, comm, &status);
int count;
MPI_Get_count(&status,MPI_FLOAT,&count);
float recv_buffer[count];
MPI_Recv(recv_buffer, count, MPI_FLOAT, sender, 0, comm, MPI_STATUS_IGNORE);
} else if (rank == sender) {
float buffer[buffer_size];
MPI_Send(buffer, buffer_size, MPI_FLOAT, receiver, 0, comm);
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment