#!/usr/bin/env bash

#-Xms   initial java heap size
#-Xmx   maximum java heap size
HEAPSIZE="-Xmx8G"
#Enable verbose garbage collector.
VERBOSE="-verbose:gc"
#-Xbatch option stops the program while the hot spot compiler is recompiling/optimising the code.
COMPILATION="-Xbatch -XX:+PrintCompilation"
#Print out GC detail
DETAIL="-XX:+PrintTenuringDistribution -XX:+PrintGCDetails"
 
#The MaxTenuringThreshold(MTT) flag governs how many times the objects are copied between the Survivor Spaces
#before being moved to the Tenured (Old) 
#Usage: -XX:MaxTenuringThreshold=n
# where n is the number of times the objects are copied. The default value of ‘n’ is (or actually was) 31.
MaxTenuringThreshold="-XX:MaxTenuringThreshold=1"
 
#Maximum size of new generation (in bytes).
NewSize="-XX:NewSize=4096m"

BIAS="-XX:BiasedLockingStartupDelay=0"
CARDMARK="-XX:+UseCondCardMark"

#Sequential or parallel version
JARS="PvWattsGamma-par-optimized PvWattsGamma-seq-optimized"

#Gamma data structure
PARGAMMAS="ConcurrentHashMap ConcurrentHashMapV8 ConcurrentSkipListMap ConcurrentSkipListSet"
SEQGAMMAS="HashMap TreeSet"

#Capacity


#Main class
count=0;

ARGS="--threads=1 --table,GenTuples,group=1 --benchmark=30 24"

CASES="seq"
for CASE in $CASES
do
	case $CASE in
	capacity)
		for Gamma in HashMap ConcurrentHashMap ConcurrentHashMapV8
		do
			#for Capacity in 16000000 12000000 8000000 4000000 2000000 1000000
			for Capacity in 0  
			do 
				JAR="PvWattsGamma-seq-optimized"
				TARGET="jstar.examples.pvwattsgamma.ParallelMainGamma"	
				ARGUMENTS[count]="-cp $JAR.jar $TARGET --table,PvWatts,estimated=$Capacity,gamma=$Gamma $ARGS"
				OUTS[count]=SEQ-Optimized.$Gamma.thread1.$Capacity
				count=$count+1;
			done
		done
	;;
	par)		
	Capacity="16000000"
	#Parallel version of PvWattsGamma program	 			
	for thread in 1 2 3 4 5 6 7 8
	do							
		if [ $thread == "1" ]; then
			for Gamma in $SEQGAMMAS
			do
				JAR= "PvWattsGamma-seq-optimized"
				TARGET="jstar.examples.pvwattsgamma.ParallelMainGamma"			
				ARGUMENTS[count]="-cp $JAR.jar $TARGET --threads=$thread --table,PvWatts,estimated=$Capacity,gamma=$Gamma $ARGS"
				OUTS[count]=PAR-Optimized.$Gamma.thread$thread.$Capacity
				count=$count+1;
			done			
		fi
		for Gamma in $PARGAMMAS
		do
			JAR= "PvWattsGamma-par-optimized"
			TARGET="jstar.examples.pvwattsgamma.ParallelMainGamma"			
			ARGUMENTS[count]="-cp $JAR.jar $TARGET --threads=$thread --table,PvWatts,estimated=$Capacity,gamma=$Gamma $ARGS"
			OUTS[count]=PAR-Optimized.$Gamma.thread$thread.$Capacity
			count=$count+1;
		done				    	
	done
	;;
	noDelta)
	#Sequential version of PvWattsGamma program
	JAR="PvWattsGamma-seq-optimized"
	thread=1
	for Gamma in $SEQGAMMAS
	do
		TARGET="jstar.examples.pvwattsgamma.ParallelMainGamma"			
		ARGUMENTS[count]="-cp $JAR.jar $TARGET --threads=$thread --table,PvWatts,estimated=$Capacity,gamma=$Gamma $ARGS"
		OUTS[count]=SEQ-Optimized.$Gamma.thread$thread.$Capacity
		count=$count+1;
	done
	;;
	seq)
	#Sequential version of PvWattsGamma program	
	JAR="PvWattsGamma-seq"
	thread=1
	Gamma="TreeSet"
	TARGET="jstar.examples.pvwattsgamma.Main"			
	ARGUMENTS[count]="-cp $JAR.jar $TARGET $ARGS"
	OUTS[count]=SEQ.$Gamma.thread$thread.0
	count=$count+1;
	esac
done

#JVM option string
OPS="DEFAULT"

for OP in $OPS
do
    mkdir $OP
	rm $OP/*.out
	case $OP in
	DEFAULT) 
	JAVAOPS="$HEAPSIZE $VERBOSE $COMPILATION $DETAIL"
	;;
	CARDMARK)
	JAVAOPS="$HEAPSIZE $VERBOSE $COMPILATION $DETAIL $CARDMARK"
	;;
	esac

	for(( i=0; i < count; i++));
	do
	    OUT=$OP/${OUTS[i]}".out"
	 	
	 	echo ${HEADERS[i]}
	    echo ${HEADERS[i]} >>$OUT
	    java -version >>$OUT
	    uname -a >>$OUT
	    cat /proc/cpuinfo >>$OUT
	    cat /proc/meminfo >>$OUT
	    lscpu >>$OUT
	    
	    echo java $JAVAOPS ${ARGUMENTS[i]}
	    echo java $JAVAOPS ${ARGUMENTS[i]} >>$OUT
	    java $JAVAOPS ${ARGUMENTS[i]} >>$OUT
	done

done






