Skip to content

Instantly share code, notes, and snippets.

@silviup
Last active October 27, 2019 15:51
Show Gist options
  • Save silviup/4af0e838604a0c2f1cf159014c9767eb to your computer and use it in GitHub Desktop.
Save silviup/4af0e838604a0c2f1cf159014c9767eb to your computer and use it in GitHub Desktop.
MPI receive dynamic length message
// 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);
@silviup
Copy link
Author

silviup commented Oct 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment