SHARE
TWEET

Untitled

a guest Feb 21st, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mpi.h"
  2. #include <fcntl.h>
  3. #include <stdlib.h>     //the standard library for c
  4. #include <sys/time.h>   //used to have access to gettimeofday to calculate time taken
  5. #include <time.h>       //used to have access to gettimeofday to calculate time taken
  6. #include <stdio.h>      //used for printf command to allow easy printing
  7. const int filter_length = 1024;                       //length of the filter
  8. const int trace_count = 1024;                         //number of arrays in the trace
  9. const int trace_length = 16384;                       //length of each trace
  10. //place items in heap beacuse the stack is not large enough for them
  11. float d[1024][17408] = {{0}};   //holds the data values that will be filtered.
  12.                                 //This includes 512 0 value buffers surrounding the data
  13.            //holds the data that will be used to filter the data matrix
  14. float out[1024][16384] = {{0}};   //holds the filtered output
  15. float fb[(sizeof(float)* filter_length)];
  16. float data[trace_count][trace_length + filter_length] = {{0}};
  17.  
  18.  
  19. void performOperation(int start, int final);
  20.  
  21. int main(int argc, char** argv) {
  22.  
  23.     int currentRow = 0;
  24.     int dataFD = open("/home/data/files/data.bin", O_RDONLY);
  25.     for (currentRow = 0; currentRow < trace_count; currentRow++) {      //for each row
  26.         off_t offset = currentRow * trace_length * sizeof(float);       //calculate offset
  27.         lseek(dataFD, offset, SEEK_SET);                                       //seek to offset in the code
  28.         read(dataFD, &data[currentRow][512], sizeof(float) * trace_length);   //read next 16k elements
  29.     }
  30.  
  31.     //reading Filter from flt.bin
  32.     int fd = open("/home/data/files/filt.bin", O_RDONLY);
  33.     read(fd,fb,sizeof(float)*filter_length);
  34.     int rank;                   // Process order
  35.     int size;                   // Number of processes    
  36.  
  37.     int i, j;
  38.     // for(i = 0; i < trace_count;i++) {
  39.     //     for(j = 512; j < trace_length+512; j++){
  40.     //         printf("data[%d][%d] = %f\n", i, j, data[i][j]);
  41.     //     }
  42.     // }
  43.     MPI_Init (&argc, &argv);
  44.     MPI_Comm_size (MPI_COMM_WORLD, &size);
  45.     MPI_Comm_rank (MPI_COMM_WORLD, &rank);
  46.  
  47.     int count = 0;
  48.     double begin = MPI_Wtime();
  49.  
  50.     int start = ((rank * trace_count) / size);
  51.     int final = (((rank+1) * trace_count) / size);
  52.     performOperation(start, final);
  53.  
  54.     MPI_Barrier(MPI_COMM_WORLD);
  55.  
  56.     begin -= MPI_Wtime();
  57.     begin *= -1;
  58.     MPI_Finalize ();
  59.     if(rank==0) {
  60.        printf("Execution across %d nodes took %f seconds.\n", size, begin);
  61.     }
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top