Last active
October 27, 2019 15:51
-
-
Save silviup/4af0e838604a0c2f1cf159014c9767eb to your computer and use it in GitHub Desktop.
MPI receive dynamic length message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rank-ul procesului de unde vor fi primite datele | |
int source_rank; | |
// aici se va stoca lungimea mesajului care va fi receptionat | |
int data_size; | |
// folosim MPI_Probe pt a obtine un status al operatie de primire (output in status) | |
MPI_Status status; | |
MPI_Probe(source_rank, MPI_ANY_TAG, MPI_COMM_WORLD, &status); | |
// cu statusul anterior se poate obtine marimea mesajului transmit (output in data_size) | |
MPI_Get_count(&status, MPI_CHAR, &data_size); | |
// stiind marimea mesajului care urmeaza a fi primit putem aloca memoria necesara acestuia | |
char* data = (char*)malloc(sizeof(char) * data_size); | |
// receptionam mesajul in bufferul alocat anterior | |
MPI_Recv(data, data_size, MPI_CHAR, source_rank, MPI_ANY_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mai multe detalii: https://mpitutorial.com/tutorials/dynamic-receiving-with-mpi-probe-and-mpi-status/