Question: Make file reality.c #include #include void reality_1_example_1(); void reality_1_example_2(); void reality_3(); double fun(); typedef struct { int a[2]; double d; } struct_t; int main(int argc,char
Make file
![fun(); typedef struct { int a[2]; double d; } struct_t; int main(int](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f51d77df690_89566f51d777fca2.jpg)
reality.c
#include
#include
void reality_1_example_1();
void reality_1_example_2();
void reality_3();
double fun();
typedef struct {
int a[2];
double d;
} struct_t;
int main(int argc,char **argv) {
int n; /* used to loop for reality_3() */
reality_1_example_1();
reality_1_example_2();
if (argc==1) n = 5; /* default 5 iter */
else n = atoi(argv[1]);
reality_3(n);
return 0;
}
void reality_1_example_1(){
float f=50000;
int i=40000;
/* fill here */
i=50000;
/* fill here */
}
void reality_1_example_2(){
float fx=1e20,fy=-1e20,fz=3.14;
unsigned int uix=12,uiy=34,uiz=56;
int six=12,siy=34,siz=56;
/* fill here */
}
void reality_3(int n) {
double d;
int i;
/* fill here */
}
double fun(int i){
volatile struct_t s;
s.d = 3.14;
s.a[i] = 1073741824;
printf("fun(%d) -> %f ",i,s.d);
return s.d;
}
/* End of file */
reality4.c
#include
#include
#include
#include
#define NNN 2048
void copyij();
void copyji();
void init_mat();
int64_t time_diff();
int src[NNN][NNN], dst[NNN][NNN];
int main(int argc,char **argv) {
long int del_sec,del_msec;
struct timeval tv_s,tv_e;
init_mat();
gettimeofday(&tv_s, NULL);
copyij();
gettimeofday(&tv_e, NULL);
/* fill here to compute elapsed time */
printf("copyji(): dim=%d: elapsed=%ld.%03ld secs ",NNN,del_sec,del_msec/1000);
init_mat();
gettimeofday(&tv_s, NULL);
copyji();
gettimeofday(&tv_e, NULL);
/* fill here to compute elapsed time */
printf("copyji(): dim=%d: elapsed=%ld.%03ld secs ",NNN,del_sec,del_msec/1000);
return 0;
}
void copyij(){
int i,j;
/* fill here */
}
void copyji(){
int i,j;
/* fill here */
}
void init_mat(){
int i,j;
for (i=0;i for (j=0;j
}
Write C programs to implement the reality we discussed last week. See the details of reality in the lecture notes: reality_1 on page 4, reality_3 on page 8 and reality_4 on page 12. Use the skeleton code reality.c for reality 1 and 3 and reality4.c for reality 4. The skeleton code is just a guideline for those who are not familiar with or don't want to write your own. You may change the model. Use Makefile for managing and compiling. When reality is executed, your program will make necessary decisions and print the following: $ reality 5 reality_1_example_1_float: f=50000.000000 f*f=2500000000.000000 >= 0 reality_1_example_1_int: i=40000 i*i=1600000000 >= 0 reality_1_example_1_int: i=50000 i*i=-1794967296 3.140000 fun(1) -> 3.140000 fun (2) -> 3.140000 fun (3) -> 2.000001 fun(4) -> 3.140000 Segmentation fault (core dumped) $ When reality4 is executed, your program will compute the time taken to run the two functions copyijO and copyji0, and print them as follows: $ reality copyij(): dim=2048: elapsed=0.013 secs copyji(): dim=2048: elapsed=0.127 secs $ Note: the elpased times are just samples. It's very likely that your numbers will be different from these since your machine is different from the machine used to get the sample numbers above. For example, last Thursday, you saw different numbers when I executed the code on my Linux box. OBJS = reality.o reality4.0 CC = gcc PROGS = reality reality4 all: $ (PROGS) reality: reality.o $ (CC) reality.c -o reality reality4: reality4.0 $ (CC) reality4.c -o reality4 clean: rm *.0 *- reality reality4 Write C programs to implement the reality we discussed last week. See the details of reality in the lecture notes: reality_1 on page 4, reality_3 on page 8 and reality_4 on page 12. Use the skeleton code reality.c for reality 1 and 3 and reality4.c for reality 4. The skeleton code is just a guideline for those who are not familiar with or don't want to write your own. You may change the model. Use Makefile for managing and compiling. When reality is executed, your program will make necessary decisions and print the following: $ reality 5 reality_1_example_1_float: f=50000.000000 f*f=2500000000.000000 >= 0 reality_1_example_1_int: i=40000 i*i=1600000000 >= 0 reality_1_example_1_int: i=50000 i*i=-1794967296 3.140000 fun(1) -> 3.140000 fun (2) -> 3.140000 fun (3) -> 2.000001 fun(4) -> 3.140000 Segmentation fault (core dumped) $ When reality4 is executed, your program will compute the time taken to run the two functions copyijO and copyji0, and print them as follows: $ reality copyij(): dim=2048: elapsed=0.013 secs copyji(): dim=2048: elapsed=0.127 secs $ Note: the elpased times are just samples. It's very likely that your numbers will be different from these since your machine is different from the machine used to get the sample numbers above. For example, last Thursday, you saw different numbers when I executed the code on my Linux box. OBJS = reality.o reality4.0 CC = gcc PROGS = reality reality4 all: $ (PROGS) reality: reality.o $ (CC) reality.c -o reality reality4: reality4.0 $ (CC) reality4.c -o reality4 clean: rm *.0 *- reality reality4