#!/usr/bin/awk -f
BEGIN 	{ 
version="";
versionList[""]="";
thread="";
num_thread=split("1_2_3_4_5_6_7_8_9_10_11_12_13_14_15", threads, "_");
filename="";
run=1;
key="";
times[""]=0;
gamma="";
delta="";
}
{
    if( filename != FILENAME){
		filename = FILENAME;
		split(filename,array,".");
		version=array[1];
		versionList[version]=version;
		thread=substr(array[2],7,length(array[2])+1);
		run=1;
		#printf("File:%s",filename);
    }

    if ( $0 ~ "Execution time:"){
		if(match(version, "PAR.*")){
		    gamma="ConcurrentSkipListSet";
		    delta="ParallelDeltaNodeInt";
		}else{
		    gamma="TreeSet";
		    delta="DeltaNodeInt";	
		}
	
		#printf("%s\n",$0);
		split($0, array, " ");	
		key=version","gamma","delta","thread","run;
		times[key]=array[3];
		run+=1;
		#printf("key:%s\tTime:%s\n",key,times[key]);
    }else{
    	
		if(match($0, "Linux.*")){
		    machine["OS"]=substr($0,1,index($0,"#"));
		}		
		if(match($0, "processor")){
		    split($0,array," ");
		    machine["processor"]=array[3];
		}
		if(match($0, "model name")){
		    split($0,array,":");
		    machine["model"]=array[2];
		}
		if(match($0, "MemTotal:")){
		    split($0,array," ");
		    machine["memtotal"]=array[2];
		}
		if(match($0, "====.*")){
		    machine["header"]=$0
		}
    }
 
}
END {
    for(version in versionList){
	    if(version != ""){
			if(match(version, "PAR.*")){
			    gamma="ConcurrentSkipListSet";
			    delta="ParallelDeltaNodeInt";
			}else{
			    gamma="TreeSet";
			    delta="DeltaNodeInt";	
			}
			
			printf("Machine: %s with %d cores (%s) and %s memory\n",machine["OS"],\
			int(machine["processor"])+1,machine["model"],machine["memtotal"]);
				
			printf("MatrixMult\tVersion:%s\tGamma:%s\tDelta:%s\n",version,gamma,delta);
			printf("\nNumThreads:");
			for(j=1;j<=num_thread;j++){
				thread=threads[j];
	   	   		printf("\t%s",thread);
	   		}
			printf("\n");
		
			for(run=1;run<=30;run++){
			    printf("Run%s",run);
			    for(j=1;j<=num_thread;j++){
					thread=threads[j];
					key=version","gamma","delta","thread","run;
					printf("\t%s",times[key]);
			    }
			    printf("\n");
			}
			
			printf("\nVersion:");
			for(j=1;j<=num_thread;j++){
	   	   		printf("\t%s",version);
	   		}
		    printf("\nGamma:");
		    for(j=1;j<=num_thread;j++){					   	   
			    printf("\t%s",gamma);							 
		    }
	   		printf("\nDelta:");
		    for(j=1;j<=num_thread;j++){					   	   
			    printf("\t%s",delta);							 
		    }
		    printf("\nNumThreads:");
		    for(j=1;j<=num_thread;j++){
		    	thread=threads[j];
			    printf("\t%s",thread);
		    }						   
		    printf("\nAverage7-30");
		    printf("\nMedian7-30");
		    printf("\nVariance7-30");
		    printf("\nSpeedup");
		    printf("\n");
		}
	
    }
	
 
 }
