Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <mpi.h>
- #include <string.h>
- #include <unistd.h>
- #define MASTER 0
- int main(int argc, char **argv)
- {
- int id, nproc;
- char stavek[100];
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &nproc);
- MPI_Comm_rank(MPI_COMM_WORLD, &id);
- if (id == MASTER)
- {
- printf("Vnesite stavek za igro telefon: ");
- fgets(stavek, 100, stdin);
- MPI_Send(stavek, 100, MPI_CHAR, id + 1, 0, MPI_COMM_WORLD);
- MPI_Recv(stavek, 100, MPI_CHAR, nproc - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
- printf("%d -> %d: %s\n",nproc-1,id, stavek);
- }
- else
- {
- MPI_Recv(stavek, 100, MPI_CHAR, id - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
- sleep(id-1);
- printf("%d -> %d: %s\n",id-1,id, stavek);
- for (int i = 0; i < 100; i++)
- {
- if (id == 1)
- {
- if (stavek[i] == 'e')
- {
- stavek[i] = 'a';
- }
- else if (stavek[i] == 'E')
- {
- stavek[i] = 'A';
- }
- }
- else if (id == 2)
- {
- if (stavek[i] == 't')
- {
- stavek[i] = 'm';
- }
- else if (stavek[i] == 'T')
- {
- stavek[i] = 'M';
- }
- }
- else if (id == 3)
- {
- if (stavek[i] == 'h')
- {
- stavek[i] = 'p';
- }
- else if (stavek[i] == 'H')
- {
- stavek[i] = 'P';
- }
- }
- }
- MPI_Send(stavek, 100, MPI_CHAR, (id + 1) % nproc, 0, MPI_COMM_WORLD);
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement