#include "mpi.h" /* dolacza plik naglowkowy potrzebny dla biblioteki MPI */ #include /* potrzebny dla funkcji 'fprintf()' */ #include int main(int argc, char **argv) { int myid, size, namelen; char computer_name[512]; /* nazwa komputera na ktorym */ int a[2], b; MPI_Status status; MPI_Init(&argc, &argv); /* inicjalizuje srodowisko MPI */ /* pobiera identyfikator biezacego procesu */ MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &size); /* Pobiera nazwe komputera na ktorym proces sie wykonuje */ MPI_Get_processor_name(computer_name, &namelen); srandom((myid+1)*time(NULL)); a[0] = random()%100; fprintf(stderr, "Proces %d z %d na %s licytuje: %d\n", myid, size, computer_name, a[0]); if (myid == 0) { MPI_Send(a, 1, MPI_INT, 1, 12, MPI_COMM_WORLD); } else { MPI_Recv(&b, 1, MPI_INT, 0, 12, MPI_COMM_WORLD, &status); if (a[0] < b) { fprintf(stderr,"Proces 0 wygral stawka: %d\n", b); } else if (a[0] >b) { fprintf(stderr,"Proces 1 wygral stawka: %d\n", a[0]); } else { fprintf(stderr,"Rownowaga\n"); } } /* konczy dzialanie srodowiska MPI */ MPI_Finalize(); return 0; }