1 /* Copyright (c) 2009, 2010. 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[])
30 struct timeval *start_time = NULL, *stop_time = NULL;
38 MPI_Init(&argc, &argv);
40 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
41 MPI_Comm_size(MPI_COMM_WORLD, &size);
44 start_time = (struct timeval *) malloc(sizeof(struct timeval));
45 stop_time = (struct timeval *) malloc(sizeof(struct timeval));
48 for (N = N_START; N <= N_STOP; N = N_NEXT) {
50 buffer = malloc(sizeof(char) * N);
53 for (j = 0; j < N; j++) {
54 buffer[j] = (char) (random() % 256);
56 if (-1 == gettimeofday(start_time, NULL)) {
57 printf("couldn't set start_time on node 0!\n");
58 MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR);
63 for (i = 0; i < ITER; i++) {
64 MPI_Bcast(buffer, N, MPI_BYTE, 0, MPI_COMM_WORLD);
66 for (j = 1; j < size; j++) {
67 MPI_Recv(&check, 1, MPI_INT, MPI_ANY_SOURCE, 1, MPI_COMM_WORLD,
71 MPI_Send(&rank, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
76 if (-1 == gettimeofday(stop_time, NULL)) {
77 printf("couldn't set start_time on node 0!\n");
78 MPI_Abort(MPI_COMM_WORLD, GETTIMEOFDAY_ERROR);
82 (double) (stop_time->tv_sec - start_time->tv_sec) +
83 (double) (stop_time->tv_usec -
84 start_time->tv_usec) / ONE_MILLION;
90 printf("N: %10d, iter: %d, time: %10f s, avg rate: %12f Mbps\n", N,
92 ((double) N * ITER * 8) / (1024.0 * 1024.0 * seconds));