Advertisement
Lubino41

para nefun

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