#include <stdio.h>
#include <stdint.h>
#include <getopt.h>
#include <stdlib.h>
#define DEFAULT_DIM 140
#define MIN_DIM 1
#define MAX_DIM 500
#define TIMER rc_nanos_thread_time()
#define TIMER_DELAY 2100
static void __print_usage(void)
{
printf("\n");
printf("-d use default matrix size (%dx%d)\n",DEFAULT_DIM,DEFAULT_DIM);
printf("-s {size} use custom matrix size\n");
printf("-h print this help message\n");
printf("\n");
}
int main(int argc, char *argv[])
{
int dim = 0;
int c,diff,mflops;
uint64_t t1, t2, flops;
if(argc>3){
printf("Too many arguments given.\n");
__print_usage();
return -1;
}
if(argc<2){
printf("Not enough arguments given.\n");
__print_usage();
return -1;
}
opterr = 0;
while ((c = getopt(argc, argv, "ds:h")) != -1){
switch (c){
case 'd':
if(dim!=0){
printf("invalid combination of arguments\n");
__print_usage();
return -1;
}
dim = DEFAULT_DIM;
break;
case 's':
if(dim!=0){
printf("invalid combination of arguments\n");
__print_usage();
return -1;
}
dim = atoi(optarg);
if(dim>MAX_DIM || dim<MIN_DIM){
printf("requested size out of bounds\n");
__print_usage();
return -1;
}
break;
case 'h':
__print_usage();
return 0;
default:
printf("inavlid argument\n");
__print_usage();
return -1;
}
}
printf("Starting\n");
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to make random matrix & vector\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to duplicate matrix\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to multiply matrices\n", diff);
flops = ((uint64_t)2*dim*dim*dim*1000000000)/(diff);
mflops = flops/(uint64_t)1000000;
printf("%10d MFLOPS multiplying matrices\n", mflops);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to find matrix determinant\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to invert matrix\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to do LUP decomposition\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to do QR decomposition\n", diff);
t1 = TIMER;
t2 = TIMER;
diff = (int)((t2-t1-TIMER_DELAY)/(uint64_t)1000);
printf("%10dus Time to solve linear system\n", diff);
printf("DONE\n");
return 0;
}