Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with the code in C please, and every information is in here and for the code it'd already some of them and

Please help me with the code in C please, and every information is in here and for the code it'd already some of them and need to do the TODO part. Thank you so much

image text in transcribedimage text in transcribedimage text in transcribed

Problem 2. (50 points for CS4473 and CS5473] In this course, we will use C for the OpenMP, GPU and MPI programming. This exercise will refresh your memory about C programming. Please write a serial C program to do the matrix- vector multiplication It should take two input files, one for the input matrix and the other one for the input vector. All the numbers are integers. The two input files are provided in the comma-separated values (CSV) format. Because the input matrix and vector can be very large, please use dynamic memory allocation (malloc and free) to store them in the heap. To prevent the numbers from running out of range, please declare the type of all variables as long int. The output vector should be saved in a CSV file. Your program should be run using the following command line: serial_mult_mat_vec file_1.csv n_row_1 n_col_1 file_2.csv n_row 2 result_vector.csv The input parameters of your programs include: file_1.csv: input CSV file for the input matrix n_row_1: number of rows in the input matrix n_col_1: number of columns in the input matrix file_2.csv: input CSV file for the input vector n_row_2: number of rows in the input vector result_vector.csv: output CSV file for the result vector The starter code and the make file are provided for your reference in the Problem_2 folder. Please keep the names of the C code and executable as serial_mult_mat_vec.c and serial_mult_mat_vec, respectively. To use the Make command, you may need to first load GCC using the following command: module load GCC Our auto-grading script will unzip the zip files submitted by every student, compile the code using the Makefile, execute the program using the command specified above, and validate the output. Therefore, it is important for you to name the directories and files as instructed. #include #include // Use more libraries as necessary #define DEBUG 0 /* Project 1 - Problem 2 - Mat-Vec Mult This file will multiply a matrix and vector. Complete the TODOs left in this file. // int main (int argc, char *argv[]) { // Catch console errors if( argc != 7) { printf("USE LIKE THIS: serial_mult_mat_vec in_mat.csv n_row_1 n_col_1 in_vec.csv n_row_2 output_file.csv "); return EXIT_FAILURE; } // Get the input files FILE *matFile = fopen(argv[1], "r"); FILE *vecFile = fopen(argv[4], "r"); // Get dim of the matrix char* p1; char* p2; int n_row1 = strtol(argv[2], &p1, 10); int n_col1 = strtol(argv[3], &p2, 10); // Get dim of the vector char* p3; int n_row2 = strtol(argv[5], &p3, 10); // Get dim of the matrix char* p1; char* p2; int n_row1 strtol(argv[2], &p1, 10 ); int n_col1 = strtol (argv[3], &p2, 10); // Get dim of the vector char* p3; int n_row2 = strtol (argv[5], &p3, 10 ); // Get the output file FILE *outputFile fopen(argv[6], "W"); = // TODO: Use malloc to allocate memory for the matrices // TODO: Parse the input CSV files // TODO: Perform the matrix-vector multiplication // TODO: Write the output CSV file // TODO: Free memory // Cleanup fclose (matFile); fclose (vecFile); fclose (outputFile); // Free buffers here as well! return

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

What is group replacement? Explain with an example. (2-3 lines)

Answered: 1 week ago