diff options
| author | Andrew Guschin <guschin@altlinux.org> | 2024-10-09 04:50:31 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin@altlinux.org> | 2024-10-09 04:50:31 +0400 |
| commit | 8cc7dc96334f82c5f00317e9e4574145396fa4ad (patch) | |
| tree | 5ca2bce6b26cc7f889ab7fb13027e988007ac11f /graph-checker/src/main.rs | |
| parent | 7bef94da59261074164a388fecd78f306877a499 (diff) | |
almost done
Diffstat (limited to 'graph-checker/src/main.rs')
| -rw-r--r-- | graph-checker/src/main.rs | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/graph-checker/src/main.rs b/graph-checker/src/main.rs index 677e037..f738806 100644 --- a/graph-checker/src/main.rs +++ b/graph-checker/src/main.rs @@ -1,8 +1,8 @@ // use std::io::{self, BufRead}; -use rayon::prelude::*; +// use rayon::prelude::*; use sqlx::migrate::MigrateDatabase; // use std::sync::{Arc, Mutex}; -use std::time::Instant; +// use std::time::Instant; use tokio; mod graph; @@ -22,22 +22,56 @@ async fn main() -> Result<(), sqlx::Error> { } let db = sqlx::SqlitePool::connect(&database_url).await?; let _ = sqlx::query!( - "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL);" + "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL, ind_dom INT NOT NULL, forced_geod INT NOT NULL);" ) .execute(&db) .await; let gi = GengIterator::new(6); + let mut res = Vec::new(); + + const BATCH_SIZE: usize = 10000; + + loop { + let graphs = gi.take(BATCH_SIZE); + let tasks: Vec<_> = graphs + .map(|g| { + let db = db.clone(); + tokio::spawn(async move { + let (g6, ind_dom, fg) = compute::dominating_numbers(g).await; + let ind_dom = ind_dom.unwrap_or(0); + let fg = fg.unwrap_or(0); + let _ = sqlx::query!( + "INSERT INTO graphs (g6, ind_dom, forced_geod) VALUES (?, ?, ?);", + g6, ind_dom, fg + ).execute(&db).await; + }) + }) + .collect(); + let mut part = futures::future::join_all(tasks).await; + if part.len() < BATCH_SIZE { + res.append(&mut part); + break; + } + res.append(&mut part); + } + + // let elapsed = start.elapsed(); + // let time = elapsed.as_nanos(); + // let res = res.iter().map(|e| e.as_ref().unwrap()).collect::<Vec<_>>(); + println!("len = {}", res.len()); + // println!("Time elapsed: {}s", time as f64 / 1e9); + // let res: Vec<_> = // gi.par_bridge().map(compute::dominating_numbers).collect(); // let res: Vec<_> = gi.map(compute::dominating_numbers).collect(); - for pair in &res { - if let Some(cardinality) = pair.1 { - println!("{} {:?} {:?}", pair.0, cardinality, pair.2); - } - } + // for pair in &res { + // if let Some(cardinality) = pair.1 { + // println!("{} {:?} {:?}", pair.0, cardinality, pair.2); + // } + // } // let start = Instant::now(); // let res = gi |