-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 0382/WignerSymbol to the benchmarks and re-run everything
- Loading branch information
Showing
9 changed files
with
199 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#![allow(clippy::needless_return)] | ||
|
||
use wigner_benchmarks::wigner_symbol_0382; | ||
|
||
use criterion::{Criterion, criterion_group, criterion_main}; | ||
|
||
fn compute_all_wigner_3j(max_angular: i32) { | ||
for l1 in 0..=max_angular { | ||
for l2 in 0..=max_angular { | ||
for l3 in 0..=max_angular { | ||
for m1 in -l1..=l1 { | ||
for m2 in -l2..=l2 { | ||
for m3 in -l3..=l3 { | ||
unsafe { | ||
wigner_symbol_0382::ws0382_wigner_3j( | ||
2 * l1, 2 * l2, 2 * l3, | ||
2 * m1, 2 * m2, 2 * m3 | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fn compute_large_wigner_3j(l1: i32, l2: i32, l3: i32) { | ||
for m1 in -10..=10 { | ||
for m2 in -10..=10 { | ||
for m3 in -10..=10 { | ||
unsafe { | ||
wigner_symbol_0382::ws0382_wigner_3j( | ||
2 * l1, 2 * l2, 2 * l3, | ||
2 * m1, 2 * m2, 2 * m3 | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
fn bench_wigner3j(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("0382/WignerSymbol"); | ||
group.sample_size(10); | ||
group.sampling_mode(criterion::SamplingMode::Flat); | ||
|
||
unsafe { | ||
wigner_symbol_0382::ws0382_init(600); | ||
} | ||
|
||
for &max_angular in &[4, 8, 12, 16, 20] { | ||
group.bench_function(&format!("max_angular={}", max_angular), |b| { | ||
b.iter(|| compute_all_wigner_3j(max_angular)) | ||
}); | ||
} | ||
|
||
group.bench_function("j = (300, 100, 250)", |b| { | ||
b.iter(|| compute_large_wigner_3j(300, 100, 250)) | ||
}); | ||
|
||
let v = unsafe { | ||
wigner_symbol_0382::ws0382_wigner_3j(2 * 300, 2 * 100, 2 * 250, 0, 2, -2) | ||
}; | ||
dbg!(v); | ||
} | ||
|
||
criterion_group!(wigner3j, bench_wigner3j); | ||
criterion_main!(wigner3j); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
use std::path::Path; | ||
use std::fs::File; | ||
use std::io::Read; | ||
|
||
|
||
fn list_cxx_libs(build: &Path) { | ||
let mut dirs_file = File::open(build.join("cxx_link_dirs.cmake")).unwrap(); | ||
let mut content = String::new(); | ||
dirs_file.read_to_string(&mut content).unwrap(); | ||
for dir in content.lines() { | ||
println!("cargo:rustc-link-search=native={}", dir); | ||
} | ||
|
||
let mut libs_file = File::open(build.join("cxx_link_libs.cmake")).unwrap(); | ||
let mut content = String::new(); | ||
libs_file.read_to_string(&mut content).unwrap(); | ||
for lib in content.lines() { | ||
if !is_excluded_lib(lib) { | ||
println!("cargo:rustc-link-lib={}", lib); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(target_os = "macos")] | ||
fn is_excluded_lib(name: &str) -> bool { | ||
// libclang_rt.osx.a is not found by the linker, and to_library is a bug | ||
// with cmake (trying to parse -lto_library=<...>) | ||
name.contains("libclang_rt.osx.a") || name == "to_library" | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
fn is_excluded_lib(name: &str) -> bool { | ||
// Fiw warnings about redundant linker flag | ||
name == "gcc" || name == "gcc_s" | ||
} | ||
|
||
#[cfg(not(any(target_os = "linux", target_os = "macos")))] | ||
fn is_excluded_lib(_: &str) -> bool { | ||
false | ||
} | ||
|
||
fn main() { | ||
let mut cmake = cmake::Config::new("."); | ||
let out_dir = cmake.build(); | ||
let lib = out_dir.join("lib"); | ||
println!("cargo:rustc-link-search=native={}", lib.display()); | ||
|
||
list_cxx_libs(&out_dir.join("build")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "WignerSymbolSingleton.hpp" | ||
|
||
|
||
extern "C" void ws0382_init(int l_max) { | ||
util::wigner_init(l_max, "Jmax", 3); | ||
} | ||
|
||
extern "C" double ws0382_wigner_3j(int two_j1, int two_j2, int two_j3, int two_m1, int two_m2, int two_m3) { | ||
return util::wigner_3j(two_j1, two_j2, two_j3, two_m1, two_m2, two_m3); | ||
} |