#!/bin/awk -f
BEGIN {
    key="";
    filename="";
    run=1;
    machine[""]="";
    times[""]="";
    thread=0;
    delta="";
    deltaList[""]=0;
    gamma="";
    gammaList[""]=0;
    version="";
    versionList[""]="";
    jvm[""]="";
    #num_thread=split("1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", threads, " ");
    num_thread=split("1 2 3 4 6 8 12 16 20 24 28 32", threads, " ");
    task=120;
}
{ 
    if(filename != FILENAME){
		filename=FILENAME;
		split(filename,array,".");
		version=array[1];
		versionList[version]=version;
    	gamma=array[2];
		gammaList[gamma]+=1;
		thread=substr(array[3],7,length(array[3])+1);			
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," ");
		key=version","gamma","thread","task","run;	
		times[key]=array[3];
		#printf("key: %s Value:%s\n",key, array[3]); 
		run++;	    
    }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
		}
		
		if(match($0, "java -.*")){
		    jvm[version","ds",jvm"]=$0
		}
    }
   
}
END {
    for(version in versionList){
	if(version != ""){
	    for(gamma in gammaList){
		if(gamma != ""){
		    key="hardware";
		    printf("Machine: %s with %d CPUs (%s) and %s memory\n",machine["OS"],int(machine["processor"])+1,\
		    machine["model"],machine["memtotal"]);
		    
		    printf("Median benchmarks:\tVersion:%s\tGamma:%s\tTask:%s\t\n",version,gamma,task);
		    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(i=1;i<=num_thread;i++){
				    thread=threads[i];
				    key=version","gamma","thread","task","run;
				    printf("\t%s",times[key]);
				}
				printf("\n");
		    }    
		    
		    printf("\nVersion:");
			for(j=1;j<=num_thread;j++){
				thread=threads[j];
		   		printf("\t%s",version);
		   	}
		   	
		   	printf("\nGamma:");
			for(j=1;j<=num_thread;j++){
				thread=threads[j];
		   		printf("\t%s",gamma);
		   	}
		   	
		   	printf("\nTask:");
			for(j=1;j<=num_thread;j++){
				thread=threads[j];
		   		printf("\t%s",task);
		   	}
		   
		    printf("\nNumThreads:");
			for(j=1;j<=num_thread;j++){
				thread=threads[j];
		   		printf("\t%s",thread);
		   	}
		    
		    printf("\nAverage7-30");
		    printf("\nMedian7-30");
		    printf("\nVar7-30");
		    printf("\nSpeedup\n");
		}
	    }
	}
    }    
}
