#include "mpi.h" #include "stdlib.h" #define N 1000 /* N is the number of rounds */ #define B 1250 /* B is the buffer size (50K) */ #define P 12 /* P is the number of players */ #define C 50 /* C indicates the amount of computation */ /* This is a random topology program. */ /* It sends a single message around N times among P entities. */ main(int argc, char *argv[]) { int my_id, enemy_id, values, comp; int timer = 0; int flag = 1; int bombarray[B]; MPI_Status stat; if (MPI_Init(&argc, &argv)!=MPI_SUCCESS) { printf("Sorry, that's an error.\n"); exit(1); } MPI_Comm_rank(MPI_COMM_WORLD, &my_id); /* Get rank */ /* Start the action -- send message to first process */ bombarray[0]=0; if (my_id==0) MPI_Send(bombarray, B, MPI_INT, 1, 0, MPI_COMM_WORLD); /* Wait for the message then send it to another process */ while (flag) { /* Receive message and increment counters */ MPI_Recv(bombarray,B,MPI_INT,MPI_ANY_SOURCE,0,MPI_COMM_WORLD,&stat); timer = bombarray[0] + 1; bombarray[0] = timer; /* Put random values into the array between 0-300 then send */ if (timer < N) { for (comp=1; comp N) { /* printf("Enemy %d is dying!!!\n", my_id); */ MPI_Finalize(); flag = 0; } } }