#include "mpi.h"
#include <stdio.h>
int main(int argc, char** argv) {
int rank;
double start, end;
char message[100000]; // Розмір повідомлення можна змінювати для перевірки залежності часу
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
for (int len = 1; len <= 100000; len *= 10) {
if (rank == 0) {
start = MPI_Wtime();
MPI_Send(message, len, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
MPI_Recv(message, len, MPI_CHAR, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
end = MPI_Wtime();
printf("Довжина повідомлення: %d, Час: %f секунд\n", len
, end
- start
); }
else if (rank == 1) {
MPI_Recv(message, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
MPI_Send(message, len, MPI_CHAR, 0, 0, MPI_COMM_WORLD);
}
}
MPI_Finalize();
return 0;
}
I2luY2x1ZGUgIm1waS5oIgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyKiogYXJndikgewogICAgaW50IHJhbms7CiAgICBkb3VibGUgc3RhcnQsIGVuZDsKICAgIGNoYXIgbWVzc2FnZVsxMDAwMDBdOyAvLyDQoNC+0LfQvNGW0YAg0L/QvtCy0ZbQtNC+0LzQu9C10L3QvdGPINC80L7QttC90LAg0LfQvNGW0L3RjtCy0LDRgtC4INC00LvRjyDQv9C10YDQtdCy0ZbRgNC60Lgg0LfQsNC70LXQttC90L7RgdGC0ZYg0YfQsNGB0YMKCiAgICBNUElfSW5pdCgmYXJnYywgJmFyZ3YpOwogICAgTVBJX0NvbW1fcmFuayhNUElfQ09NTV9XT1JMRCwgJnJhbmspOwoKICAgIGZvciAoaW50IGxlbiA9IDE7IGxlbiA8PSAxMDAwMDA7IGxlbiAqPSAxMCkgewogICAgICAgIGlmIChyYW5rID09IDApIHsKICAgICAgICAgICAgc3RhcnQgPSBNUElfV3RpbWUoKTsKICAgICAgICAgICAgTVBJX1NlbmQobWVzc2FnZSwgbGVuLCB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