@@ -41,10 +41,12 @@ using T = std::complex<double>;
4141using Real = double ;
4242
4343// Optional PPCG parameter overrides (set from argv) for exploring the block
44- // size (sbsize) and Rayleigh-Ritz frequency (rr_step). A negative value keeps
45- // the default used by the comparison benchmark (sbsize = nband, rr_step = 16).
44+ // size (sbsize), Rayleigh-Ritz frequency (rr_step) and strategy. A negative
45+ // value keeps the default used by the comparison benchmark (sbsize = nband,
46+ // rr_step = 16, strategy = BLOCK_SUBSPACE).
4647static int g_sbsize = -1 ;
4748static int g_rr_step = -1 ;
49+ static int g_strategy = -1 ; // 0 = BLOCK_SUBSPACE, 1 = CONJUGATE_GRADIENT
4850
4951// Total heap memory currently allocated (bytes). Used to compare the peak
5052// working memory of the solvers: PPCG keeps a bounded subspace, while
@@ -224,8 +226,10 @@ static Result run_ppcg(const std::vector<T>& H, int n, int nband, const std::vec
224226 long mem0 = heap_bytes ();
225227 const int sbsize = (g_sbsize > 0 ) ? g_sbsize : nband;
226228 const int rr_step = (g_rr_step > 0 ) ? g_rr_step : 16 ;
229+ const hsolver::PpcgStrategy strategy =
230+ (g_strategy == 1 ) ? hsolver::PpcgStrategy::CONJUGATE_GRADIENT : hsolver::PpcgStrategy::BLOCK_SUBSPACE ;
227231 hsolver::DiagoPPCG<T, hsolver::base_device::DEVICE_CPU > solver (1e-8 , 500 , sbsize, rr_step, false ,
228- hsolver::PpcgStrategy:: BLOCK_SUBSPACE );
232+ strategy );
229233 auto h_op = [&H, n](T* in, T* out, int ld, int nc) { dense_h_multiply (H.data (), n, in, out, ld, nc); };
230234 auto t0 = std::chrono::high_resolution_clock::now ();
231235 solver.diag (h_op, nullptr , n, nband, n, psi.data (), eval.data (), ethr, prec.data ());
@@ -342,7 +346,8 @@ int main(int argc, char** argv)
342346 int sparsity;
343347 };
344348 // Without arguments a small default grid is used. To benchmark a single
345- // (possibly large) problem, pass: <n> <nband> <sparsity_pct> [sbsize] [rr_step]
349+ // (possibly large) problem, pass: <n> <nband> <sparsity_pct> [sbsize] [rr_step] [strategy]
350+ // where strategy: 0 = BLOCK_SUBSPACE (default), 1 = CONJUGATE_GRADIENT.
346351 std::vector<Case> cases;
347352 if (argc >= 4 )
348353 {
@@ -362,6 +367,10 @@ int main(int argc, char** argv)
362367 {
363368 g_rr_step = std::atoi (argv[5 ]);
364369 }
370+ if (argc >= 7 )
371+ {
372+ g_strategy = std::atoi (argv[6 ]);
373+ }
365374
366375 std::printf (" \n === Solver comparison (identical H, psi0, ethr) ===\n " );
367376 std::printf (" %-5s %-5s %-6s %-10s %-14s %-10s %-12s\n " , " n" , " nband" , " spars" , " solver" , " wall_time(s)" ,
0 commit comments