Question: Coding exercise ( Language: C ) You tutor students part - time as part of your work - study program. Currently, the students are facing
Coding exercise Language: C
You tutor students parttime as part of your workstudy program. Currently, the students are facing threads and memory management for the first time and theyre having a hard time. To help them, you devised an exercise for them to practice with. One of the students submitted the following code, everything they added is encased to the base code supplied with Students Code Comment.
#include
#include
#include
int threads;
double sol;
struct matrix
int data;
int size;
int size;
;
void runnervoid param
struct matrix matrices struct matrix param;
int startrow int param;
int endrow startrow ;
for int i startrow; i endrow; i
for int j ; j matricessize; j
solij;
for int k ; k matricessize; k
solij matricesdataik matricesdatakj;
pthreadexit;
void matrixOperationint scalar, struct matrix X struct matrix Y
pthreadt tidthreads;
int rowsperthread Xsize threads;
int remainingrows Xsize threads;
int threadargsthreads;
int startrow ;
for int i ; i threads; i
threadargsi startrow;
int rows rowsperthread remainingrows : ;
remainingrows;
startrow rows;
pthreadcreate&tidi NULL, runner, &threadargsi;
for int i ; i threads; i
pthreadjointidi NULL;
Prints out the solution matrix
printfResult ;
for int i ; i Xsize; i
printf;
for int j ; j Xsize; j
j Xsize printff solij : printff solij;
i Xsize printf : printf;
printf
;
int main
struct matrix X Y;
Xdata;
Xdata;
Xdata;
Xdata;
Xsize;
Xsize;
Ydata;
Ydata;
Ydata;
Ydata;
Ysize;
Ysize;
threads ;
matrixOperation X Y;
threads ;
Ydata;
matrixOperation X Y;
Ysize;
threads ;
matrixOperation X Y;
return ;
Here are the results to compare:
Students Result:
Result
Result
Result
Expected Result:
Result
Result
ILLEGAL OPERATION
There are multiple errors within the code, how would you go about resolving those issues and explaining the changes made such that the student can improve? Was the approach efficient? Only use pThreads, check for Illegal cases, and ensure the code compiles with NO errors and compatibility with gcc matmult.c o matmult Wall Werror terminal command.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
