Question: Order of Memory Access ~~~~~~~~~~~~~~~~~~~~~~ Below are several memory layouts of A / B elements to consider. - - - - - - - -

Order of Memory Access ~~~~~~~~~~~~~~~~~~~~~~ Below are several memory layouts of A/B elements to consider. ------------------------------------------------------------------------- Byte Offset +00+04+08+12+16+80+84+88+92+96 LAYOUT1 A0 A1 A2 A3 A4... B0 B1 B2 B3 B4...-------------------------------------------------------------------------------------------------------------------------------------------- Byte Offset +00+04+08+12+16+20+24+2832+36 LAYOUT 2 A0 B0 A1 B1 A2 B2 A3 B3 A4 B4...------------------------------------------------------------------- For each of following, indicate the best suited option. The `int_field_base' approach code that is timed.. -() Uses memory LAYOUT 1 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -(X) Uses memory LAYOUT 1 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. The `arr_field_base' approach code that is timed.. -() Uses memory LAYOUT 1 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -(X) Uses memory LAYOUT 1 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. The `int_field_optm' approach code that is timed.. -() Uses memory LAYOUT 1 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 1 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. -(X) Uses memory LAYOUT 2 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. The `arr_field_optm' approach code that is timed.. -(X) Uses memory LAYOUT 1 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 1 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, B0, A1, B1, A2, B2, etc. -() Uses memory LAYOUT 2 and visit elements in the order A0, A1, A2,... B0, B1, B2, etc. Solve the above questions using the code below as reference: #include #include #include typedef struct {// fields are individual ints int a; int b; } int_field_t; typedef struct {// fields are arrays of ints int *a_arr; int *b_arr; } arr_field_t; // Use this format string for printf() invocations so that the output // identical for each timing run const char *FORMAT = "method: %14s CPU time: %.4e sec sum: %d
"; //||+-> sum computed in loop, should be 0 each time //|+-> CPU time computed over nested summing loops //+-> string describing one of the methods used to print; // One of: "int_field_base" "arr_field_base" // "int_field_optm" "arr_field_optm" //// Example: printf(FORMAT, "int_field_optm", some_time, total); int main(int argc, char *argv[]){ if(argc <3){ printf("usage: %s
",argv[0]); return 1; } int length = atoi(argv[1]); int max_iter = atoi(argv[2]); clock_t begin, end; // Variables for timing double cpu_time; int suma,sumb; // sum of elements in structs ////////////////////////////////////////////////////////////////////////////////// int_field_base approach int_field_t *int_field_arr1=// allocate/initialize int_field array malloc(sizeof(int_field_t)*length); for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!