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