about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-11 13:21:05 +0000
committerPjotr <wrk@bosa.lan>2026-11-11 13:21:05 +0000
commitca7efa231bbd818b5166e38b59e3c81ea30821b3 (patch)
treeca02a03ebbf576afc1ea45ff3e251bd1c967056b /src
parentf4d2d719f90774e85bc47eca041bc469f0f0951d (diff)
downloadgenenetwork4-ca7efa231bbd818b5166e38b59e3c81ea30821b3.tar.gz
bulklmm: BULKLMM_BLOCKS as a config option, default 4
The marker blocks a single-trait scan is split into were the driver's
default (Threads.nthreads()) and changed with --threads. They are a
separate knob now:

  BULKLMM_THREADS   Julia threads (--threads)               default 4
  BULKLMM_BLOCKS    independent marker blocks, scanned       default 4
                    in parallel (1 = serial scan)

Blocks are exact either way -- LOD 9.589938 and the same permutation
thresholds at 1 and 4 -- so the knob only buys wall clock. The reply says
what ran ("split into 4 independent blocks and scanned on 4 Julia
thread(s) (BULKLMM_BLOCKS / BULKLMM_THREADS ...)"), because the answer to
"is it multicore?" should be in the response and not in the log.
Diffstat (limited to 'src')
-rw-r--r--src/bulklmm.rs4
-rw-r--r--src/config.rs11
-rw-r--r--src/routes/bulklmm.rs13
3 files changed, 26 insertions, 2 deletions
diff --git a/src/bulklmm.rs b/src/bulklmm.rs
index 46f6102..0b167d9 100644
--- a/src/bulklmm.rs
+++ b/src/bulklmm.rs
@@ -189,6 +189,7 @@ pub async fn compute(
     reml: bool,
     assumption: &str,
     threads: u32,
+    blocks: u32,
 ) -> Result<Output, BulklmmError> {
     let unique = format!(
         "{}-{}",
@@ -201,6 +202,7 @@ pub async fn compute(
     let result_path = work_dir.join(format!("{unique}-bulklmm.csv"));
     let perm_path = work_dir.join(format!("{unique}-bulklmm-perm.csv"));
     let threads_str = threads.to_string();
+    let blocks_str = blocks.to_string();
     let threads_for_env = threads.to_string();
     let nperm_str = nperm.to_string();
     let seed_str = seed.to_string();
@@ -223,6 +225,8 @@ pub async fn compute(
         result_path.to_string_lossy().into_owned(),
         "--assumption".to_string(),
         assumption.to_string(),
+        "--blocks".to_string(),
+        blocks_str,
         "--seed".to_string(),
         seed_str,
     ];
diff --git a/src/config.rs b/src/config.rs
index 42b74e7..cf5476e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -158,6 +158,10 @@ pub struct Config {
     pub bulklmm_depot: String,
     pub bulklmm_script: String,
     pub bulklmm_threads: u32,
+    /// Independent marker blocks scanned in parallel (`BULKLMM_BLOCKS`,
+    /// default 4). `1` is a plain serial scan; the LODs and thresholds are
+    /// identical either way.
+    pub bulklmm_blocks: u32,
     pub bulklmm_cache_dir: String,
     /// The script that draws a BulkLMM scan (`BULKLMM_PLOTTER`).
     pub bulklmm_plotter: String,
@@ -341,6 +345,10 @@ impl Config {
             "scripts/bulklmm_scan.jl".to_string(),
         );
         values.insert("BULKLMM_THREADS".to_string(), "4".to_string());
+        // Independent marker blocks scanned in parallel: a BulkLMM `scan()` is
+        // serial in Julia, so this is where a single-trait scan gets its
+        // parallelism. 1 is a plain serial scan and gives the same answer.
+        values.insert("BULKLMM_BLOCKS".to_string(), "4".to_string());
         values.insert(
             "BULKLMM_PLOTTER".to_string(),
             "scripts/plot-bulklmm.py".to_string(),
@@ -425,6 +433,7 @@ impl Config {
             "BULKLMM_DEPOT",
             "BULKLMM_SCRIPT",
             "BULKLMM_THREADS",
+            "BULKLMM_BLOCKS",
             "BULKLMM_CACHE_DIR",
             "BULKLMM_PLOTTER",
         ] {
@@ -478,6 +487,7 @@ impl Config {
             bulklmm_depot: values["BULKLMM_DEPOT"].clone(),
             bulklmm_script: values["BULKLMM_SCRIPT"].clone(),
             bulklmm_threads: values["BULKLMM_THREADS"].parse().unwrap_or(4),
+            bulklmm_blocks: values["BULKLMM_BLOCKS"].parse().unwrap_or(4),
             bulklmm_cache_dir: values["BULKLMM_CACHE_DIR"].clone(),
             bulklmm_plotter: values["BULKLMM_PLOTTER"].clone(),
             genotype_files_dir: values["GENOTYPE_FILES"].clone(),
@@ -734,6 +744,7 @@ mod tests {
             "BULKLMM_DEPOT",
             "BULKLMM_SCRIPT",
             "BULKLMM_THREADS",
+            "BULKLMM_BLOCKS",
             "BULKLMM_CACHE_DIR",
             "BULKLMM_PLOTTER",
         ] {
diff --git a/src/routes/bulklmm.rs b/src/routes/bulklmm.rs
index f244e5d..098ddb3 100644
--- a/src/routes/bulklmm.rs
+++ b/src/routes/bulklmm.rs
@@ -73,7 +73,8 @@ pub struct BulklmmRequest {
     /// `null` (default: variance components estimated once, under the null) or
     /// `alt` (per marker, slower and more accurate).
     pub assumption: Option<String>,
-    /// Cores for Julia (`--threads`), default from `BULKLMM_THREADS`.
+    /// Julia threads (`--threads`), default `BULKLMM_THREADS` (4). The marker
+    /// blocks scanned in parallel come from `BULKLMM_BLOCKS` (4).
     pub cores: Option<u32>,
     /// Normalisation of the trait values, as on `/compute/rqtl`.
     pub normalize: Option<String>,
@@ -145,6 +146,7 @@ pub async fn compute_bulklmm(
     let seed = request.seed.unwrap_or(0);
     let reml = request.reml.unwrap_or(false);
     let threads = request.cores.unwrap_or(config.bulklmm_threads).clamp(1, 32);
+    let blocks = config.bulklmm_blocks.clamp(1, 64);
 
     let mut notes: Vec<String> = Vec::new();
     // A basket is another source for `samples`.
@@ -514,6 +516,7 @@ pub async fn compute_bulklmm(
                 reml,
                 &assumption,
                 threads,
+                blocks,
             )
             .await
             .map_err(|error| match error {
@@ -587,7 +590,13 @@ pub async fn compute_bulklmm(
             "Rows are positional: marker, chr, pos (Mb), lod, beta, h2. BulkLMM fits one LMM per \
              marker with a global kinship matrix (not GEMMA's leave-one-chromosome-out), by ML \
              or REML, and reports the effect size `beta` and the null heritability `h2`.",
-        );
+        )
+        .with_note(&format!(
+            "Parallelism: BulkLMM's single-trait scan() is serial in Julia, so the markers are \
+             split into {blocks} independent blocks and scanned on {threads} Julia thread(s) \
+             (BULKLMM_BLOCKS / BULKLMM_THREADS; blocks 1 is a plain serial scan and gives the \
+             same LODs). Where the cores really pay is many traits at once."
+        ));
     if let Some(group) = request.group.clone() {
         envelope = envelope.with_next(
             &format!("/groups/{}", path_segment(&group)),