Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <mpi.h>
- int main(int argc, char * argv[])
- {
- int noProcesses, processId;
- char poz;
- char s = 'a';
- int total;
- int rozdelene;
- int nova;
- MPI_Init(&argc, &argv);
- MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
- MPI_Comm_rank(MPI_COMM_WORLD, &processId);
- long filesize(FILE *stream);
- FILE *stream;
- stream = fopen("lala.txt", "r");
- // printf ("procesor cislo %d " , processId);
- // printf ("procesorov celkovo %d " , noProcesses);
- int ga = 0;
- int pro;
- // int rank0 = 0, rank1 = 1, rank2 = 2, rank3 = 3;
- int f = 0;
- char c; int i=0;
- if (processId == 0)
- {
- fseek(stream, 0, SEEK_END);
- poz = getc(stream);
- pro = ftell(stream);
- printf ("som na konci %d pozicia je %c \n",pro, poz);
- rozdelene = pro/noProcesses;
- printf ("po rozdeleni %d \n",rozdelene);
- fseek(stream, 0, SEEK_SET);
- pro = ftell(stream);
- poz = getc(stream);
- // printf ("som na zaciatku %d pozicia je %c \n",pro, poz);
- }
- MPI_Bcast(&rozdelene, 1, MPI_INT, 0, MPI_COMM_WORLD);
- if (processId == 3)
- {
- //while(feof(stream)==0)
- for (nova = processId*rozdelene; nova < processId+1*rozdelene; nova++)
- {
- fseek(stream,nova,0);
- //i+=1;
- c=getc(stream);
- printf("%c",c);
- f=f+1;
- if( s == c )
- {
- ga = ga+1;
- }
- }
- }
- MPI_Reduce(&ga, &total, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
- if (processId == 0)
- {
- // printf ("%d \n",f); // kolko kra siel cyklus
- printf (" zhoda %d krat",total);
- }
- fclose(stream);
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement