use clap::Parser;
use orx_parallel::*;
use std::hint::black_box;
#[derive(Parser)]
struct Args {
#[arg(long, default_value_t = 10_000_000)]
num_applications: usize,
#[arg(long, default_value_t = 0)]
num_threads: usize,
#[arg(long, default_value_t = 0)]
chunk_size: usize,
}
fn compute_risk_score(applicant_id: usize, credit_history_len: usize) -> u64 {
(0..credit_history_len)
.map(|month| {
let n = black_box((applicant_id + month) as u64 % 40);
let mut a = 0;
let mut b = 1;
for _ in 0..n {
let c = a + b;
a = b;
b = c;
}
a
})
.sum()
}
fn main() {
let args = Args::parse();
let _total_risk: u64 = (0..args.num_applications)
.par()
.num_threads(args.num_threads)
.chunk_size(args.chunk_size)
.runner_with_diagnostics()
.map(|id| compute_risk_score(id, (id % 40) + 1))
.reduce(|a, b| a + b)
.unwrap_or(0);
}