Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * File: prg1.c
- * Author: Nikhil Patil
- * Procedures:
- * main - Insert random values in data. Filter and time the execution
- ***************************************************************************/
- #include <mpi.h> // MPI library
- #include <fcntl.h>
- #include <stdlib.h> // Standard C library
- #include <stdio.h> // Used to inout and output to terminal, mainly printf
- #define FILTER_LENGTH 1024 // Length of the filter
- #define TRACE_COUNT 1024 // Number of rows in the trace/data
- #define TRACE_LENGTH 16384 // Number of values in each trace/data row
- float out[FILTER_LENGTH][TRACE_LENGTH] = {{0}};
- float filterBuffer[(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,filterBuffer,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);
- double begin = MPI_Wtime();
- // size = 1;
- // rank = 0;
- int start = ((rank * TRACE_COUNT) / size);
- int final = (((rank+1) * TRACE_COUNT) / size);
- performOperation(start, final);
- MPI_Barrier(MPI_COMM_WORLD);
- begin -= MPI_Wtime();
- MPI_Finalize ();
- 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