diff --git a/extra1/Bsend.c b/extra1/Bsend.c new file mode 100644 index 0000000..03842e2 --- /dev/null +++ b/extra1/Bsend.c @@ -0,0 +1,47 @@ +#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(); +} diff --git a/extra1/Rsend.c b/extra1/Rsend.c new file mode 100644 index 0000000..3cbf25d --- /dev/null +++ b/extra1/Rsend.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +// 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_Rsend(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_Rsend(data, MESSAGE_SIZE, MPI_CHAR, IDX0, 0, MPI_COMM_WORLD); + end_send = MPI_Wtime(); + } + end_time = MPI_Wtime(); + printf("[%d]Execution time (MPI_Rsend): %f; Send time: %f\n", my_rank, end_time - start_time, end_send - start_send); + free(data); + } + + MPI_Finalize(); +} diff --git a/extra1/Send.c b/extra1/Send.c new file mode 100644 index 0000000..5eff503 --- /dev/null +++ b/extra1/Send.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +// 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(); +} diff --git a/extra1/Ssend.c b/extra1/Ssend.c new file mode 100644 index 0000000..a7c4a51 --- /dev/null +++ b/extra1/Ssend.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +// 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_Ssend(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_Ssend(data, MESSAGE_SIZE, MPI_CHAR, IDX0, 0, MPI_COMM_WORLD); + end_send = MPI_Wtime(); + } + end_time = MPI_Wtime(); + printf("[%d]Execution time (MPI_Ssend): %f; Send time: %f\n", my_rank, end_time - start_time, end_send - start_send); + free(data); + } + + MPI_Finalize(); +} diff --git a/extra1/output b/extra1/output new file mode 100644 index 0000000..e9611d1 --- /dev/null +++ b/extra1/output @@ -0,0 +1,11 @@ +[0]Execution time (MPI_Send): 2.001213; Send time: 0.000341 +[1]Execution time (MPI_Send): 2.001231; Send time: 2.000874 + +[0]Execution time (MPI_Ssend): 2.022626; Send time: 0.000384 +[1]Execution time (MPI_Ssend): 2.022571; Send time: 2.022247 + +[0]Execution time (MPI_Rsend): 2.018200; Send time: 0.000382 +[1]Execution time (MPI_Rsend): 2.018145; Send time: 2.017824 + +[0]Execution time (MPI_Bsend): 2.000843; Send time: 0.000123 +[1]Execution time (MPI_Bsend): 0.000254; Send time: 0.000105