- /* Allocate memory regions to communicate */
- sbuf = (char*) malloc(SIZE);
- rbuf = (char*) malloc(size * SIZE);
+ /* Time when rank 0 gathers the data */
+ MPI_Barrier(MPI_COMM_WORLD);
+ t1 = MPI_Wtime();
+ for (i = 0; i < ITER; i++) {
+ MPI_Gather(sbuf, SIZE, MPI_BYTE, rbuf, SIZE, MPI_BYTE, 0, MPI_COMM_WORLD);
+ MPI_Barrier(MPI_COMM_WORLD);
+ }
+ t2 = MPI_Wtime();
+ t = (t2 - t1) / ITER;