#include #include #include /* Compilation: mpic++ main.cc Execution: mpiexec -n 4 a.out Expected output: Thread 1 got 42 from thread 0 Thread 3 got 42 from thread 0 Thread 2 got 42 from thread 0 */ int main(void) { MPI_Init(nullptr, nullptr); int world_rank; MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); int world_size; MPI_Comm_size(MPI_COMM_WORLD, &world_size); int number = -1; if (world_rank == 0) { number = 42; } MPI_Barrier(MPI_COMM_WORLD); MPI_Bcast(&number, 1, MPI_INT, 0, MPI_COMM_WORLD); if (world_rank != 0) { printf("Thread %d got %d from thread 0\n", world_rank, number); } MPI_Finalize(); }