clear all
for it=1:13
    [event,time]=textread(['1003/time',int2str(2^(it-1))],'%13c%f');
    event=unique(event,'rows');
    numEvents=size(event,1);
    numSteps=length(time)/numEvents;
    time=reshape(time,numEvents,numSteps);
    if(it==1)
        [t,i]=sort(time(:,end),1,'descend');
    end
    times(:,it)=time(i,end);
end
event=event(i,:);

figure,set(gcf,'color','w','position',[680 410 950 1070])
colormap('lines')
area(times')
xlabel('N_{procs}'),ylabel('time [s]')
set(gca,'xtick',1:11,'xticklabel',2.^(1:11))
h=legend(event,2);
set(h,'fontsize',12,'location','eastoutside');

times2(1,:)=sum(times([1 6 10],:));
times2(2,:)=sum(times([2 4 11 15 19 20 24 26 27 29 30 34],:));
times2(3,:)=sum(times([31 37 38 39],:));
times2(4,:)=sum(times([5],:));
times2(5,:)=sum(times([3 7 12 14 16 17 18 21 22 23 25 28 32 33 35 36],:));
times2(1,:)=times(1,:)-times(3,:);

size(times2)
times2=times2(:,[1 4 7 10 13]);

event2(1,:)='Local evaluation ';
event2(2,:)='FMM evaluation   ';
event2(3,:)='MPI communication';
event2(4,:)='GPU communication';
event2(5,:)='Tree construction';

figure,set(gcf,'color','w','position',[680 410 950 1070])
colormap('jet')
bar(times2','stacked')
xlabel('Number of processes'),ylabel('Time (sec)')
set(gca,'xticklabel',[1 8 64 512 4096])
legend(event2,2);
times2

times3=sum(times2);
times3=times3(1)./times3;
times3(2,:)=[3.5 4 5 8 25];
times3(2,:)=times3(2,1)./times3(2,:);

figure,set(gcf,'color','w','position',[680 410 950 1070])
bar(1:5,times3','grouped')
xlabel('Number of processes'),ylabel('Parallel efficiency')
set(gca,'xtick',1:5,'xticklabel',[1 8 64 512 4096])
legend('FMM','spectral method')
axis([0 6 0 1.2])