CS代写 LENGTH 25000

#include
#include
#include
#include

Copyright By PowCoder代写 加微信 powcoder

#define BILLION 1000000000.0
#define MAX_LINE_LENGTH 25000

#define BLUR_SIZE 2

int main (int argc, char *argv[])
// Check console errors
if( argc != 6)
printf(“USE LIKE THIS: convolution_serial n_row n_col mat_input.csv mat_output.csv time.csv\n”);
return EXIT_FAILURE;

// Get dims
int n_row = strtol(argv[1], NULL, 10);
int n_col = strtol(argv[2], NULL, 10);

// Get files to read/write
FILE* inputFile1 = fopen(argv[3], “r”);
if (inputFile1 == NULL){
printf(“Could not open file %s”,argv[2]);
return EXIT_FAILURE;
FILE* outputFile = fopen(argv[4], “w”);
FILE* timeFile = fopen(argv[5], “w”);

// Matrices to use
int* filterMatrix_h = (int*)malloc(5 * 5 * sizeof(int));
int* inputMatrix_h = (int*) malloc(n_row * n_col * sizeof(int));
int* outputMatrix_h = (int*) malloc(n_row * n_col * sizeof(int));

// read the data from the file
int row_count = 0;
char line[MAX_LINE_LENGTH] = {0};
while (fgets(line, MAX_LINE_LENGTH, inputFile1)) {
if (line[strlen(line) – 1] != ‘\n’) printf(“\n”);
char *token;
const char s[2] = “,”;
token = strtok(line, s);
int i_col = 0;
while (token != NULL) {
inputMatrix_h[row_count*n_col + i_col] = strtol(token, NULL,10 );
token = strtok (NULL, s);
row_count++;

// Filling filter
// 1 0 0 0 1
// 0 1 0 1 0
// 0 0 1 0 0
// 0 1 0 1 0
// 1 0 0 0 1
for(int i = 0; i< 5; i++) for(int j = 0; j< 5; j++) filterMatrix_h[i*5+j]=0; filterMatrix_h[0*5+0] = 1; filterMatrix_h[1*5+1] = 1; filterMatrix_h[2*5+2] = 1; filterMatrix_h[3*5+3] = 1; filterMatrix_h[4*5+4] = 1; filterMatrix_h[4*5+0] = 1; filterMatrix_h[3*5+1] = 1; filterMatrix_h[1*5+3] = 1; filterMatrix_h[0*5+4] = 1; fclose(inputFile1); // --------------------------------------------------------------------------- // // ------ Algorithm Start ---------------------------------------------------- // struct timespec start, end; clock_gettime(CLOCK_REALTIME, &start); // Performing convolution // Take a look at slides about the blurring example for(int i=0; i -1 && curRow < n_row && curCol > -1 && curCol < n_col) sum_val += inputMatrix_h[curRow*n_col + curCol]*filterMatrix_h[i_row*5 + i_col]; outputMatrix_h[i*n_col+j] = sum_val; clock_gettime(CLOCK_REALTIME, &end); double time_spent = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / BILLION; // --------------------------------------------------------------------------- // // ------ Algorithm End ------------------------------------------------------ // // Save output matrix as csv file for (int i = 0; iCS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com