(* numOrbs % clustSize must be 0 *)
gPaoCost[clustSize_]:=(
numOrbs = 360;
nAux = 600;
nPao = 800;
nSc = 750; (* Remove linear dependices so smaller than nPao *)
total = 0;
numPairstreated = 0;
numI = numOrbs / clustSize;
For[i = 0, i < numI, i++,
For[j = 0, j < numI, j++,
cholesk=nAux^3;(* Metric -> L *)
SC = nPao^3 + nPao^2 * nSc + nSc^2 * nPao + nSc^3; (* Semi canon: EVD(S) + U^T F U + EVD(F) *)
SCXtrans = nAux * (clustSize + clustSize)*nPao * nSc;(*(X|(I + J) A) * U *)
Coeffs=nAux^3 + nAux^2 * clustSize *nSc;(* L^{-1} * (X|I  A) *)
Giajb = clustSize^2 * nSc ^2 * nAux; (* (IA | X) * C^{X}_{JB} *)
total += cholesk + SC + SCXtrans + Coeffs + Giajb;(* Sum them up *)
];
];
Return[total];
);
gOSVCost[clustSize_]:=(
numOrbs = 360;
nAux = 600;
nPao = 800;
nOSV = 400;
nSc = 400;
total = 0;
numPairstreated = 0;
numI = numOrbs / clustSize;
For[i = 0, i < numI, i++,
For[j = 0, j < numI, j++,
StoOSV = nPao^2 * nOSV + nOSV^2 * nPao; (* U^T * Spao * U *)
SEVD = nOSV^3;
Newbasis = nOSV * nSc^2; (* OSV U * Usc *)
FtoSC = nPao^2 * nSc + nSc^2 * nPao; (* U^T * Fpao * U *)
FEVD = nSc^3; 
SC = StoOSV + SEVD + Newbasis + FtoSC + FEVD; 
cholesk=nAux^3;(* Metric -> L *)
SCXtrans = nAux * (clustSize + clustSize)*nPao * nSc;(*(X|(I + J) A) * U *)
Coeffs=nAux^3 + nAux^2 * clustSize *nSc;(* L^{-1} * (X|I  A) *)
Giajb = clustSize^2 * nSc ^2 * nAux; (* (IA | X) * C^{X}_{JB} *)
total += cholesk + SC + SCXtrans + Coeffs + Giajb;(* Sum them up *)
];
];
Return[total];
);


(* numOrbs % clustSize must be 0 *)
Paocosts = Table[{i, gPaoCost[i]}, {i,Divisors[360]}];
Paoscale = Table[{Paocosts[[i,1]],N[Paocosts[[1,2]]/Paocosts[[i,2]]]}, {i,1,Length[Paocosts]}];

OSVcosts = Table[{i, gOSVCost[i]}, {i,Divisors[360]}];
OSVscale = Table[{OSVcosts[[i,1]],N[OSVcosts[[1,2]]/OSVcosts[[i,2]]]}, {i,1,Length[OSVcosts]}];

TableForm[Paoscale]
TableForm[OSVscale]
Prepend[Paoscale,{"Size","Scale"}]
Export[ "/Users/work/software/thesis/MP2PNOpaper/data/pao_cluster_scaling.csv",Prepend[Paoscale,{"Size","Scale"}]];
Export["/Users/work/software/thesis/MP2PNOpaper/data/osv_cluster_scaling.csv",Prepend[OSVscale,{"Size","Scale"}]];
ListLogLogPlot[{Paoscale,OSVscale},Joined->True, PlotMarkers->Automatic,PlotStyle->Dashed,PlotRange->All,PlotLegends->{"PAO only", "With OSVs"},Frame->{True, True, False, False}, FrameLabel->{"Avg cluster size","Speedup" }]