#!/bin/awk -f
BEGIN {
    key="";
    filename="";
    run=1;
    machine[""]="";
    times[""]="";
    thread=0;
    task=0;
    version="";
    experiment="";
    expList[""]="";
    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 5 6 7 8", threads, " ");
    #num_thread=split("1 2 3 4 6 8 12 16 20 24 28 32", threads, " ");
}
{ 
    if(filename != FILENAME){
		filename=FILENAME;
		split(filename,array,".");
		version=array[1];
		done=array[2];
		edge=array[3];
		delta=array[4];
		experiment=version" "done" "edge" "delta;
		#printf("experiment=%s\n",experiment);
		expList[experiment]=experiment;
	    thread=substr(array[5],7,length(array[5])+1);
		run=1;
    }

    if($0 ~ "Execution time:"){
		split($0,array," ");
		key=version","done","edge","delta","thread","run;			 
		times[key]=array[3];
		#printf("Key=%s\tValue=%s\n",key,times[key]);
		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];
		}
    }
   
}
END {
    for(experiment in expList){if(experiment != ""){
    	split(experiment, paraList, " ");
    	version=paraList[1];
    	done=paraList[2];
    	edge=paraList[3];
    	delta=paraList[4];
		printf("Machine: %s with %d CPUs (%s) and %s memory\n",machine["OS"],machine["processor"]+1,\
		machine["model"],machine["memtotal"]);
		printf("Dijkstra benchmarks:\tVersion:%s\tDone:%s\tEdge:%s\tDeltaNode:%s\tVertices:1000000\tExtra Edges:1000000\t\n",version,done, edge,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(i=1;i<=num_thread;i++){
				thread=threads[i];
				key=version","done","edge","delta","thread","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("\nDone:");
		for(j=1;j<=num_thread;j++){
			thread=threads[j];
			printf("\t%s",done);
		}
		
		printf("\nEdge:");
		for(j=1;j<=num_thread;j++){
			thread=threads[j];
			printf("\t%s",edge);
		}
		
		printf("\nDelta:");
		for(j=1;j<=num_thread;j++){
			thread=threads[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\n");
	
    }}    
}
