Syntax:
Das Argument 'recvcount' gibt die maximale Länge einer Nachricht an. Wieviele Elemente tatsächlich empfangen wurden, läßt sich mit MPI_Get_count ermitteln.
Aufruf:
Weiterschieben von Daten unterschiedlichen Typs in einem Ring
(Anzahl der Prozesse für das Beispiel muß geradzahlig sein.)
#include "mpi.h"
int myid, numprocs, pred, succ;
int count1, count2;
void *buf1, *buf2;
MPI_Datatype datatype1, datatype2;
MPI_Comm comm;
MPI_Status status;
...
MPI_Comm_size(comm, &numprocs);
MPI_Comm_rank(comm, &myid);
succ=(myid+1)%(numprocs);
pred=(myid+numprocs-1)%(numprocs);
if (myid%2 == 0) {
...
MPI_Sendrecv(buf1, count1, datatype1, succ, 99,
buf2, count2, datatype2, pred, MPI_ANY_TAG,
comm, &status);
...
}
if (myid%2 == 1) {
...
MPI_Sendrecv(buf2, count1, datatype2, succ, 11,
buf1, count2, datatype1, pred, MPI_ANY_TAG,
comm, &status);
...
}
...