#include #include #include #include // 3 КБайта #define MESSAGE_SIZE (3*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_Bsend(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_Bsend(data, MESSAGE_SIZE, MPI_CHAR, IDX0, 0, MPI_COMM_WORLD); end_send = MPI_Wtime(); } end_time = MPI_Wtime(); printf("[%d]Execution time (MPI_Bsend): %f; Send time: %f\n", my_rank, end_time - start_time, end_send - start_send); free(data); } MPI_Finalize(); }