1 /* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #define GETTIMEOFDAY_ERROR 1
19 #define N_STOP 1024*1024
22 #define ONE_MILLION 1000000.0
23 #define RAND_SEED 842270
25 int main(int argc, char *argv[])
28 struct timeval *start_time = NULL, *stop_time = NULL;
35 MPI_Init(&argc, &argv);
37 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
38 MPI_Comm_size(MPI_COMM_WORLD, &size);
41 start_time = (struct timeval *) malloc(sizeof(struct timeval));
42 stop_time = (struct timeval *) malloc(sizeof(struct timeval));
45 for (int N = N_START; N <= N_STOP; N = N_NEXT) {
46 buffer = malloc(sizeof(char) * N);
49 for (int j = 0; j < N; j++) {
50 buffer[j] = (char) (random() % 256);
52 if (-1 == gettimeofday(start_time, NULL)) {
53 printf("couldn't set start_time on node 0!\n");
54 MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR);
59 for (int i = 0; i < ITER; i++) {
60 MPI_Bcast(buffer, N, MPI_BYTE, 0, MPI_COMM_WORLD);
62 for (int j = 1; j < size; j++) {
63 MPI_Recv(&check, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
66 MPI_Send(&rank, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
71 if (-1 == gettimeofday(stop_time, NULL)) {
72 printf("couldn't set start_time on node 0!\n");
73 MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR);
76 seconds = (double) (stop_time->tv_sec - start_time->tv_sec) +
77 (double) (stop_time->tv_usec - start_time->tv_usec) / ONE_MILLION;
83 printf("N: %10d, iter: %d, time: %10f s, avg rate: %12f Mbps\n", N, ITER, seconds,
84 ((double) N * ITER * 8) / (1024.0 * 1024.0 * seconds));