#!/bin/bash
svn checkout svn+ssh://lnalod@forge.ipsl.jussieu.fr/ipsl/forge/projets/yao/svn/trunk/examples/berrada/MFLBC_RD_perfomanceMeasurement /tmp/MFLBC_RD_perfomanceMeasurement
cd /tmp/MFLBC_RD_perfomanceMeasurement

YaoI +O3 mflbc_rd
# Copy the file which allows to make the average of the elapsed times of forward and backward.
cp -f 2Y2_mflbc_rd_normal.h Yworkdir/Y2mflbc_rd.h 
YaoI +O3 mflbc_rd 
# Serial execution
echo num threads: serial...
echo $OMP_NUM_THREADS
./mflbc_rd > resultNotParallelFile.txt
YaoI -p +O3 mflbc_rd 

# 1 thread execution
OMP_NUM_THREADS=1 
echo num threads:
echo $OMP_NUM_THREADS
./mflbc_rd > resultParallelFile_1thread.txt

# 2 thread execution
OMP_NUM_THREADS=2
echo num threads:
echo $OMP_NUM_THREADS
./mflbc_rd > resultParallelFile_2thread.txt

# 4 thread execution
OMP_NUM_THREADS=4 
echo num threads:
echo $OMP_NUM_THREADS
./mflbc_rd > resultParallelFile_4thread.txt

# 8 thread execution
OMP_NUM_THREADS=8 
echo num threads:
echo $OMP_NUM_THREADS
./mflbc_rd > resultParallelFile_8thread.txt


# Generate the matlab files
echo "A=[1; 2; 4; 8];" >> mflbc_rd_matlabFile.m
#echo "A=[1 1 1 1 1 1; 2 2 2 2 2 2; 4 4 4 4 4 4; 8 8 8 8 8 8];" >> mflbc_rd_matlabFile.m

echo "B=[" >> mflbc_rd_matlabFile.m
awk '/counter 250/ {print $4}' resultNotParallelFile.txt >> mflbc_rd_matlabFile.m
echo "; " >> mflbc_rd_matlabFile.m
awk '/counter 250/ {print $4}' resultParallelFile_2thread.txt >> mflbc_rd_matlabFile.m
echo "; " >> mflbc_rd_matlabFile.m
awk '/counter 250/ {print $4}' resultParallelFile_4thread.txt >> mflbc_rd_matlabFile.m
echo "; " >> mflbc_rd_matlabFile.m
awk '/counter 250/ {print $4}' resultParallelFile_8thread.txt >> mflbc_rd_matlabFile.m
echo "]; " >> mflbc_rd_matlabFile.m

echo " " >> mflbc_rd_matlabFile.m
echo "p1 =  plot(A(:,1), B(:,1), '-kx'); % mflbc_rd " >> mflbc_rd_matlabFile.m
echo "  hold on" >> mflbc_rd_matlabFile.m
#echo "p2 =  plot(A(:,2), B(:,2), '-ko'); % shallow 50x50 Amdahl" >> mflbc_rd_matlabFile.m
#echo "  hold on" >> mflbc_rd_matlabFile.m
#echo "p3 =  plot(A(:,3), B(:,3), '--kx'); % shallow 100x100 Real" >> mflbc_rd_matlabFile.m
#echo "  hold on" >> mflbc_rd_matlabFile.m
#echo "p4 =  plot(A(:,4), B(:,4), '--ko'); % shallow 100x100 Amdahl" >> mflbc_rd_matlabFile.m
#echo "  hold on" >> mflbc_rd_matlabFile.m
#echo "p5 =  plot(A(:,5), B(:,5), ':kx'); % shallow 200x200 Real" >> mflbc_rd_matlabFile.m
#echo "  hold on" >> mflbc_rd_matlabFile.m
#echo "p6 =  plot(A(:,6), B(:,6), ':ko'); % shallow 200x200 Amdahl" >> mflbc_rd_matlabFile.m
#echo "  hold on" >> mflbc_rd_matlabFile.m
echo " " >> mflbc_rd_matlabFile.m
echo "xlabel('Cores' , 'FontSize' ,22);" >> mflbc_rd_matlabFile.m
echo "ylabel('Time' , 'FontSize', 22);" >> mflbc_rd_matlabFile.m
echo " " >> mflbc_rd_matlabFile.m
echo "h1 = legend([p1],'mflbc_rd',1);" >> mflbc_rd_matlabFile.m
echo "set(h1, 'Location', 'NorthWest');" >> mflbc_rd_matlabFile.m
#echo "legend([p1,p2,p3,p4,p5,p6],'50x50 real','50x50 Amdahl','100x100 real','100x100 Amdahl','200x200 real','200x200 Amdahl',1);" >> mflbc_rd_matlabFile.m
echo " " >> mflbc_rd_matlabFile.m
echo "saveas(gcf, 'mflbc_rd_matlabFile_print', 'fig');" >> mflbc_rd_matlabFile.m
echo "saveas(gcf, 'mflbc_rd_matlabFile_print', 'eps');" >> mflbc_rd_matlabFile.m
echo "quit;" >> mflbc_rd_matlabFile.m


awk '/counter 250/ {print $4}' resultParallelFile_1thread.txt


# Lanciare matlab
#matlab
matlab -r "mflbc_rd_matlabFile"


