#include #include #include #include "broadcast.h" int main(int argc, char *argv[]) { char msg[20]; int myrank; int tag = 99; clock_t begin, end; double time_spent; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if (myrank == 0) { strcpy(msg, "Hello world"); begin = clock(); MYMPI_Bcast(msg, 20, MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("exec time norm: %f", time_spent); // -------------------- begin = clock(); MYMPI_Bcast_(msg, 20, MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("exec time opt: %f", time_spent); } else { MYMPI_Bcast(msg, 20, MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); //printf("%d: %s\n", myrank, msg); MYMPI_Bcast_(msg, 20, MPI_CHAR, 0, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); } MPI_Finalize(); return 0; }