Created
May 5, 2021 15:54
-
-
Save zdxerr/4dad7a7f9fd8972e0692f64cac6e1e22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <mpi.h> | |
#include <string.h> | |
const int N = 50; | |
// const int SIZE = 32; | |
const int SIZE = 32000000; | |
const char charset[] = "abcdefghijklmnopqrstuvwxyzABC"; | |
int main(void) { | |
char msg[SIZE]; | |
int com_size, rank; | |
double start, finish; | |
double durations_sum = 0; | |
double delay = 0; | |
MPI_Init(NULL, NULL); | |
MPI_Comm_size(MPI_COMM_WORLD, &com_size); | |
MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
for (int s=0;s < SIZE-1;s++) { | |
msg[s] = charset[s % strlen(charset)]; | |
} | |
msg[SIZE-1] = '\0'; | |
MPI_Barrier(MPI_COMM_WORLD); | |
if (rank == 0) { | |
for(int i=0;i < N; i++) { | |
start = MPI_Wtime(); | |
MPI_Send(msg, SIZE, MPI_CHAR, 1, 0, MPI_COMM_WORLD); | |
MPI_Recv(msg, SIZE, MPI_CHAR, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
finish = MPI_Wtime(); | |
durations_sum += finish - start; | |
// printf("Ping pong #%d done on %d of %.9fs\n", value_tx, rank, duration); | |
} | |
delay = (durations_sum / N) / 2; | |
printf("Delay: %lf\n", delay); | |
} | |
else if (rank == 1) { | |
for(int i=0;i < N; i++) { | |
MPI_Recv(msg, SIZE, MPI_CHAR, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
MPI_Send(msg, SIZE, MPI_CHAR, 0, 0, MPI_COMM_WORLD); | |
} | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment