Advertisement
Lubino41

funkcny seek_KOMPLET

Dec 10th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mpi.h>
  3.  
  4.  
  5. int main(int argc, char * argv[])
  6. {
  7. int noProcesses, processId;
  8. char poz;
  9. char s = 'a';
  10. int total;
  11. int rozdelene;
  12. int nova;
  13.  
  14. MPI_Init(&argc, &argv);
  15. MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
  16. MPI_Comm_rank(MPI_COMM_WORLD, &processId);
  17. long filesize(FILE *stream);
  18. FILE *stream;
  19. stream = fopen("riadky80k.txt", "r");
  20.  
  21. // printf ("procesor cislo %d " , processId);
  22. // printf ("procesorov celkovo %d " , noProcesses);
  23.  
  24. int ga = 0;
  25. int pro;
  26. int f = 0;
  27. char c; int i=0;
  28.  
  29. if (processId == 0)
  30. {
  31.  
  32.  
  33. fseek(stream, 0, SEEK_END);
  34. poz = getc(stream);
  35. pro = ftell(stream);
  36.  
  37. printf ("som na konci %d pozicia je %c \n",pro, poz);
  38.  
  39. rozdelene = pro/noProcesses;
  40. printf ("po rozdeleni %d \n",rozdelene);
  41.  
  42. fseek(stream, 0, SEEK_SET);
  43.  
  44. pro = ftell(stream);
  45. poz = getc(stream);
  46. // printf ("som na zaciatku %d pozicia je %c \n",pro, poz);
  47.  
  48. }
  49. MPI_Bcast(&rozdelene, 1, MPI_INT, 0, MPI_COMM_WORLD);
  50.  
  51. //while(feof(stream)==0)
  52. for (nova = processId*rozdelene; nova < (processId+1)*rozdelene; nova++)
  53. {
  54.  
  55. fseek(stream,nova,0);
  56. //i+=1;
  57. c=getc(stream);
  58. // printf("%c",c);
  59. f=f+1;
  60. if( s == c )
  61. {
  62. ga = ga+1;
  63. }
  64. }
  65.  
  66. MPI_Reduce(&ga, &total, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
  67. if (processId == 0)
  68. {
  69. // printf ("%d \n",f); // kolko kra siel cyklus
  70. printf (" zhoda %d krat",total);
  71. }
  72. fclose(stream);
  73. MPI_Finalize();
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement