You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB
C

9 months ago
#include <stdio.h>
#include <mpi.h>
#include <stdlib.h>
#include <unistd.h>
// 16 КБайт
#define MESSAGE_SIZE (16*1024)
#define IDX0 0
#define IDX1 1
int main(int argc, char *argv[]) {
double start_time, end_time;
double start_send, end_send;
int my_rank, commsize;
char *data;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &commsize);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if ((my_rank == 0) || (my_rank ==1)) {
data = (char *)malloc(sizeof(char) * MESSAGE_SIZE);
start_time = MPI_Wtime();
if (my_rank == 0) {
start_send = MPI_Wtime();
MPI_Send(data, MESSAGE_SIZE, MPI_CHAR, IDX1, 0, MPI_COMM_WORLD);
end_send = MPI_Wtime();
sleep(2);
MPI_Recv(data, MESSAGE_SIZE, MPI_CHAR, IDX1, 0, MPI_COMM_WORLD, NULL);
}
else {
MPI_Recv(data, MESSAGE_SIZE, MPI_CHAR, IDX0, 0, MPI_COMM_WORLD, NULL);
start_send = MPI_Wtime();
MPI_Send(data, MESSAGE_SIZE, MPI_CHAR, IDX0, 0, MPI_COMM_WORLD);
end_send = MPI_Wtime();
}
end_time = MPI_Wtime();
printf("[%d]Execution time (MPI_Send): %f; Send time: %f\n", my_rank, end_time - start_time, end_send - start_send);
free(data);
}
MPI_Finalize();
}