Guest User

Untitled

a guest
Aug 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. fread() in MPI is giving Signal 7 Bus Error
  2. #include "RabinKarp.c"
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include<string.h>
  6. #include<math.h>
  7. #include </usr/include/mpi/mpi.h>
  8.  
  9. typedef struct {
  10. int lowerOffset;
  11. int upperOffset;
  12. int processorNumber;
  13.  
  14. } patternPartitioning;
  15.  
  16. int rank;
  17. FILE *fp;
  18.  
  19. char* filename = "/home/rohit/Downloads/10_seqs_2000_3000_bp.fasta";
  20. int n = 0;
  21. int d = 0;
  22. //number of processors
  23. int k, i = 0, lower_limit, upper_limit;
  24.  
  25. int main(int argc, char** argv) {
  26. char* pattern= "taaat";
  27. patternPartitioning partition[k];
  28. MPI_Init(&argc, &argv);
  29. MPI_Comm_size(MPI_COMM_WORLD, &k);
  30. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  31.  
  32.  
  33. fp = fopen(filename, "rb");
  34. if (fp != '') {
  35. fseek(fp, 0L, SEEK_END);
  36. n = ftell(fp);
  37. fseek(fp, 0L, SEEK_SET);
  38. }
  39.  
  40.  
  41. //Do for Master Processor
  42. if(rank ==0){
  43. int m = strlen(pattern);
  44. printf("pattern length is %d n", m);
  45.  
  46. d = (int)(n - m + 1) / k;
  47. for (i = 0; i <= k - 2; i++) {
  48. lower_limit = round(i * d);
  49. upper_limit = round((i + 1) * d) + m - 1;
  50. partition->lowerOffset = lower_limit;
  51. partition->upperOffset = upper_limit;
  52. partition->processorNumber = i+1;
  53.  
  54. // k-2 times calculate the limits like this
  55. printf(" the lower limit is %d and upper limit is%dn",
  56. partition->lowerOffset, partition->upperOffset);
  57. int mpi_send_block[2];
  58. mpi_send_block[0]= lower_limit;
  59. mpi_send_block[1] = upper_limit;
  60. MPI_Send(mpi_send_block, 2, MPI_INT, i+1, i+1, MPI_COMM_WORLD);
  61.  
  62. //int MPI_Send(void *buf, int count, MPI_Datatype dtype, int dest, int tag, MPI_Comm comm);
  63. }
  64. // for the last processor calculate the index here
  65. lower_limit = round((k - 1) * d);
  66. upper_limit = n;
  67. partition->lowerOffset = lower_limit;
  68. partition->upperOffset = n;
  69. partition->processorNumber = k;
  70.  
  71. printf("Processor : %d : has start : %d : and end : %d :n",rank,partition->lowerOffset,partition->upperOffset);
  72.  
  73. //perform the search here
  74.  
  75. int size = partition->upperOffset-partition->lowerOffset;
  76. char *text = (char*) malloc (size);
  77.  
  78. fseek(fp,partition->lowerOffset , SEEK_SET);
  79. fread(&text, sizeof(char), size, fp);
  80. printf("read in rank0");
  81. fputs(text,stdout);
  82.  
  83.  
  84. int number =0;
  85. fputs(text,stdout);
  86. fputs(pattern,stdout);
  87. number = rabincarp(text,pattern);
  88. for (i = 0; i <= k - 2; i++) {
  89. int res[1];
  90. res[0]=0;
  91. MPI_Status status;
  92. // MPI_Recv(res, 1, MPI_INT, i+1, i+1, MPI_COMM_WORLD, &status);
  93. // number = number + res[0];
  94. }
  95. printf("nntotal number of result found:%dn", number);
  96.  
  97.  
  98. } else {
  99. patternPartitioning mypartition;
  100. MPI_Status status;
  101. int number[1];
  102. int mpi_recv_block[2];
  103. MPI_Recv(mpi_recv_block, 2, MPI_INT, 0, rank, MPI_COMM_WORLD,
  104. &status);
  105. printf("Processor : %d : has start : %d : and end : %d :n",rank,mpi_recv_block[0],mpi_recv_block[1]);
  106.  
  107. //perform the search here
  108.  
  109. int size = mpi_recv_block[1]-mpi_recv_block[0];
  110. char *text = (char*) malloc (size);
  111. fseek(fp,mpi_recv_block[0] , SEEK_SET);
  112. fread(&text, sizeof(char), size, fp);
  113. printf("read in rank1");
  114.  
  115. // fread(text,size,size,fp);
  116. printf("length of text segment by proc: %d is %d",rank,(int)strlen(text));
  117.  
  118. number[0] = rabincarp(text,pattern);
  119. //MPI_Send(number, 1, MPI_INT, 0, rank, MPI_COMM_WORLD);
  120. }
  121.  
  122. MPI_Barrier(MPI_COMM_WORLD);
  123. MPI_Finalize();
  124. fclose(fp);
  125. return (EXIT_SUCCESS);
  126. }
  127.  
  128. [localhost:03265] *** Process received signal ***
  129. [localhost:03265] *** Process received signal ***
  130. --------------------------------------------------------------------------
  131. mpirun noticed that process rank 1 with PID 3265 on node localhost exited on signal 7 (Bus error).
  132.  
  133. char *text = (char*) malloc (size);
  134.  
  135. fseek(fp,partition->lowerOffset , SEEK_SET);
  136. fread(&text, sizeof(char), size, fp);
  137.  
  138. if (fp != '') {
Add Comment
Please, Sign In to add comment