Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mpi.h"
- #include <fcntl.h>
- #include <stdlib.h> //the standard library for c
- #include <sys/time.h> //used to have access to gettimeofday to calculate time taken
- #include <time.h> //used to have access to gettimeofday to calculate time taken
- #include <stdio.h> //used for printf command to allow easy printing
- const int filter_length = 1024; //length of the filter
- const int trace_count = 1024; //number of arrays in the trace
- const int trace_length = 16384; //length of each trace
- //place items in heap beacuse the stack is not large enough for them
- float d[1024][17408] = {{0}}; //holds the data values that will be filtered.
- //This includes 512 0 value buffers surrounding the data
- //holds the data that will be used to filter the data matrix
- float out[1024][16384] = {{0}}; //holds the filtered output
- float fb[(sizeof(float)* filter_length)];
- float data[trace_count][trace_length + filter_length] = {{0}};
- void performOperation(int start, int final);
- int main(int argc, char** argv) {
- int currentRow = 0;
- int dataFD = open("/home/data/files/data.bin", O_RDONLY);
- for (currentRow = 0; currentRow < trace_count; currentRow++) { //for each row
- off_t offset = currentRow * trace_length * sizeof(float); //calculate offset
- lseek(dataFD, offset, SEEK_SET); //seek to offset in the code
- read(dataFD, &data[currentRow][512], sizeof(float) * trace_length); //read next 16k elements
- }
- //reading Filter from flt.bin
- int fd = open("/home/data/files/filt.bin", O_RDONLY);
- read(fd,fb,sizeof(float)*filter_length);
- int rank; // Process order
- int size; // Number of processes
- int i, j;
- // for(i = 0; i < trace_count;i++) {
- // for(j = 512; j < trace_length+512; j++){
- // printf("data[%d][%d] = %f\n", i, j, data[i][j]);
- // }
- // }
- MPI_Init (&argc, &argv);
- MPI_Comm_size (MPI_COMM_WORLD, &size);
- MPI_Comm_rank (MPI_COMM_WORLD, &rank);
- int count = 0;
- double begin = MPI_Wtime();
- int start = ((rank * trace_count) / size);
- int final = (((rank+1) * trace_count) / size);
- performOperation(start, final);
- MPI_Barrier(MPI_COMM_WORLD);
- begin -= MPI_Wtime();
- begin *= -1;
- MPI_Finalize ();
- if(rank==0) {
- printf("Execution across %d nodes took %f seconds.\n", size, begin);
- }
- // for(i = 0; i < trace_count;i++) {
- // for(j = 0; j < trace_length; j++){
- // printf("out[%d][%d] = %f\n", i, j, out[i][j]);
- // }
- // }
- return 0;
- }
- void performOperation(int start, int final) {
- int j = start;
- int i = 0;
- int k = 0;
- int count = 1;
- int diff = final - start;
- for( j=start; j< final; j++ ) { //iterate over each trace
- for( i=0; i<trace_length; i++ ) {
- for( k=0; k<filter_length; k++ ) {
- out[j][i] += fb[k] * data[j][i+k - (filter_length / 2) + 512];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement