Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /***************************************************************************
  2. * File: prg1.c
  3. * Author: Nikhil Patil
  4. * Procedures:
  5. * main - Insert random values in data. Filter and time the execution
  6. ***************************************************************************/
  7.  
  8. #include <mpi.h> // MPI library
  9. #include <fcntl.h>
  10. #include <stdlib.h> // Standard C library
  11. #include <stdio.h> // Used to inout and output to terminal, mainly printf
  12.  
  13. #define FILTER_LENGTH 1024 // Length of the filter
  14. #define TRACE_COUNT 1024 // Number of rows in the trace/data
  15. #define TRACE_LENGTH 16384 // Number of values in each trace/data row
  16.  
  17. float out[FILTER_LENGTH][TRACE_LENGTH] = {{0}};
  18. float filterBuffer[(sizeof(float)* FILTER_LENGTH)];
  19. float data[TRACE_COUNT][TRACE_LENGTH + FILTER_LENGTH] = {{0}};
  20.  
  21. void performOperation(int start, int final);
  22.  
  23. int main(int argc, char** argv) {
  24.  
  25. int currentRow = 0;
  26. int dataFD = open("/home/data/files/data.bin", O_RDONLY);
  27. for (currentRow = 0; currentRow < TRACE_COUNT; currentRow++) { //for each row
  28. off_t offset = currentRow * TRACE_LENGTH * sizeof(float); //calculate offset
  29. lseek(dataFD, offset, SEEK_SET); //seek to offset in the code
  30. read(dataFD, &data[currentRow][512], sizeof(float) * TRACE_LENGTH); //read next 16k elements
  31. }
  32.  
  33. //reading Filter from flt.bin
  34. int fd = open("/home/data/files/filt.bin", O_RDONLY);
  35. read(fd,filterBuffer,sizeof(float)*FILTER_LENGTH);
  36. int rank; // Process order
  37. int size; // Number of processes
  38.  
  39. int i, j;
  40. // for(i = 0; i < TRACE_COUNT;i++) {
  41. // for(j = 512; j < TRACE_LENGTH+512; j++){
  42. // printf("data[%d][%d] = %f\n", i, j, data[i][j]);
  43. // }
  44. // }
  45. MPI_Init (&argc, &argv);
  46. MPI_Comm_size (MPI_COMM_WORLD, &size);
  47. MPI_Comm_rank (MPI_COMM_WORLD, &rank);
  48.  
  49. double begin = MPI_Wtime();
  50. // size = 1;
  51. // rank = 0;
  52. int start = ((rank * TRACE_COUNT) / size);
  53. int final = (((rank+1) * TRACE_COUNT) / size);
  54. performOperation(start, final);
  55.  
  56. MPI_Barrier(MPI_COMM_WORLD);
  57.  
  58. begin -= MPI_Wtime();
  59. MPI_Finalize ();
  60.  
  61. printf("Execution across %d nodes took %f seconds.\n", size, begin);
  62.  
  63. // for(i = 0; i < TRACE_COUNT;i++) {
  64. // for(j = 0; j < TRACE_LENGTH; j++){
  65. // printf("out[%d][%d] = %f\n", i, j, out[i][j]);
  66. // }
  67. // }
  68. return 0;
  69.  
  70. }
  71.  
  72. void performOperation(int start, int final) {
  73. int j = start;
  74. int i = 0;
  75. int k = 0;
  76. int count = 1;
  77. int diff = final - start;
  78.  
  79. for( j=start; j< final; j++ ) { //iterate over each trace
  80. for( i=0; i<TRACE_LENGTH; i++ ) {
  81. for( k=0; k<FILTER_LENGTH; k++ ) {
  82. out[j][i] += fb[k] * data[j][i+k - (FILTER_LENGTH / 2) + 512];
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement