Hi
So , I have C code on optimizing matrix multiplication and I’ve put getchar() not to do all the functions if I’m not interested. The compiled code on my laptop prints a statement, asks if the user wants to run that function and does it if it gets a ‘y’. As intended to do.
But when I compile it using RISC-V toolchain and upload it on Milkv-duo this happens. it first asks for the getchar()==‘y’ , then prints the statement it should have done before. It’s ok to me as I’ve written the code, but doesn’t make sense to a 3rd party user. U guys have any idea why is this happening and what’s the fix to it ?
Here’s a snippet of the code:
printf("Input size of matrix, n = ");
scanf("%d", &n);
ref = 0;
double *A = (double*)_aligned_malloc(n * n * sizeof(double), 64 /*sizeof(double)*/); // 64 is cache line size
double *B = (double*)_aligned_malloc(n * n * sizeof(double), 64 /*sizeof(double)*/);
double *C1 = (double*)_aligned_malloc(n * n * sizeof(double), 64 /*sizeof(double)*/);
double *C2 = (double*)_aligned_malloc(n * n * sizeof(double), 64 /*sizeof(double)*/);
if(A == NULL || B == NULL || C1 == NULL || C2 == NULL){
printf("Memory Allocation Error\n\n");
return(-1);
}
unsigned int seed = time(NULL);
printf("\nseed = %u\n", seed);
srand(seed);
fill(A, n);
fill(B, n);
fflush(stdin);
printf("\n\nDo you want to run matrix_mult_index (y/n)? ");
if(getchar() == 'y'){
ref = 1;
t0 = clock();
matrix_mult_index(n, A, B, C1);
t1 = clock();
printf("\n\tExecution time of matrix_mult_index = %0.2f s", (float)(t1-t0)/CLOCKS_PER_SEC);
}
fflush(stdin);
printf("\n\nDo you want to run matrix_mult_ptr_no_reg (y/n)? ");
if(getchar() == 'y'){
if(++ref > 2) ref = 2;
t0 = clock();
matrix_mult_ptr_no_reg(n, A, B, ref == 1 ? C1 : C2);
t1 = clock();
printf("\n\tExecution time of matrix_mult_ptr_no_reg = %0.2f s", (float)(t1-t0)/CLOCKS_PER_SEC);
}