Skip to content

Commit

Permalink
Parallelization of the binning process
Browse files Browse the repository at this point in the history
- Stack overflow during the `binning` call
- Go over the shared memory by different threads
- Only the TOD and PIX have to be shared, not
  the directory' structure
  • Loading branch information
algebrato committed May 1, 2021
1 parent da21507 commit 6f4a267
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 28 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ approx = "0.4.0"
colored = "2.0.0"
clap = "2.33.3"

[cfg]
doctest = true
[package.metadata.docs.rs]
# Enable certain features when building docs for docs.rs
features = [ "proptest-support", "compare" ]
16 changes: 15 additions & 1 deletion src/directory.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Create directory structure

mod iteratorscustom;

use crate::Obs;
Expand Down Expand Up @@ -52,7 +54,7 @@ impl DirStruct {
.map(|res| res.map(|e| e.path()))
.collect::<Result<Vec<_>, io::Error>>()?;
// mc ci sono tutte le directory montecarlo
_mc_samples = mc.len() - 49 - 6 - 1 - 1;
_mc_samples = mc.len();
for i in mc {
if i.is_dir() {
let freq_mc = read_dir(i)?
Expand Down Expand Up @@ -241,3 +243,15 @@ impl DirStruct {
self.mc_path.clone()
}
}

impl DirStruct {
pub fn clone(&self) -> Self {
DirStruct {
_outer_directory: self._outer_directory.clone(),
mc_path: self.mc_path.clone(),
_mc_samples: self._mc_samples.clone(),
start_date: self.start_date.clone(),
_observation_time: self.start_date.clone()
}
}
}
1 change: 1 addition & 0 deletions src/iteratorscustom.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Create a float iterator given the `start`, `stop` and the number of elements `steps`
pub struct FloatIterator {
current: u64,
current_back: u64,
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*!
# Strip MapMaking library
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur facilisis consectetur arcu. Etiam semper, sem sit amet lacinia dignissim, mauris eros rutrum massa, a imperdiet orci urna vel elit. Nulla at sagittis lacus. Curabitur eu gravida turpis. Mauris blandit porta orci. Aliquam fringilla felis a sem aliquet rhoncus. Suspendisse porta, mi vel euismod porta, mi ex cursus diam, quis iaculis sapien massa eget massa. Fusce sit amet neque vel turpis interdum tempus et non nisl. Nunc aliquam nunc vitae justo accumsan pretium. Morbi eget urna quis ex pellentesque molestie. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Integer vehicula vehicula tortor sit amet dignissim. Duis finibus, felis ut fringilla tincidunt, mi lectus fermentum eros, ut laoreet justo lacus id urna.
Duis iaculis faucibus mollis. Maecenas dignissim efficitur ex. Sed pulvinar justo a arcu lobortis imperdiet. Suspendisse placerat venenatis volutpat. Aenean eu nulla vitae libero porta dignissim ut sit amet ante. Vestibulum porttitor sodales nibh, nec imperdiet tortor accumsan quis. Ut sagittis arcu eu efficitur varius. Etiam at ex condimentum, volutpat ipsum sed, posuere nibh. Sed posuere fringilla mi in commodo. Ut sodales, elit volutpat finibus dapibus, dui lacus porttitor enim, ac placerat erat ligula quis ipsum. Morbi sagittis et nisl mollis fringilla. Praesent commodo faucibus erat, nec congue lectus finibus vitae. Sed eu ipsum in lorem congue vehicula.
# Using the Strip MapMaking
Duis iaculis faucibus mollis. Maecenas dignissim efficitur ex. Sed pulvinar justo a arcu lobortis imperdiet. Suspendisse placerat venenatis volutpat. Aenean eu nulla vitae libero porta dignissim ut sit amet ante. Vestibulum porttitor sodales nibh, nec imperdiet tortor accumsan quis. Ut sagittis arcu eu efficitur varius. Etiam at ex condimentum, volutpat ipsum sed, posuere nibh. Sed posuere fringilla mi in commodo. Ut sodales, elit volutpat finibus dapibus, dui lacus porttitor enim, ac placerat erat ligula quis ipsum. Morbi sagittis et nisl mollis fringilla. Praesent commodo faucibus erat, nec congue lectus finibus vitae. Sed eu ipsum in lorem congue vehicula.
*/

pub mod directory;
pub mod iteratorscustom;

Expand All @@ -12,7 +25,11 @@ use std::io::Write;
use colored::Colorize;
use num::ToPrimitive;
use rand::Rng;

/// Structure of the observation

#[derive(Debug)]
#[repr(C)]
pub struct Obs {
start: String,
stop: String,
Expand All @@ -24,6 +41,7 @@ pub struct Obs {
tod: Vec<Vec<f64>>,
}


// ```
// Documentation
// Creation function
Expand Down
47 changes: 29 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ mod directory;
use colored::*;

use directory::DirStruct;
use rand::thread_rng;
use std::path::Path;
use mapmaking::Obs;

use std::thread;

//use mapmaking::iteratorscustom::FloatIterator;
use gnuplot::{Figure, Caption, Color};

Expand All @@ -23,32 +26,40 @@ fn main() {
.get_matches();

let directory_path = program.value_of("tod_path").unwrap_or("example_tods/");
let mc_id_arg = program.value_of("mc_id").unwrap_or("0");
//let mc_id_arg = program.value_of("mc_id").unwrap_or("0");


let directory_tree = DirStruct::new(Path::new(directory_path), String::from("1")).unwrap();
let my_obs = directory_tree.create_observations(mc_id_arg);
println!("{}", "OBS CREATA".red().bold());

println!("");
println!("{}", "Information about the observation".bright_green());
println!("Monte Carlo samples loaded: {}", my_obs.get_mcid().len());
println!("Number of Detectors: {}", my_obs.get_detector().len());
println!("Number of Point Vectors: {}", my_obs.get_pix().len());
println!("Number of ToDs: {}", my_obs.get_tod().len());
/*Start the analysis of the monte carlo iteration: `mc_id_arg` */
let _t1 = thread::spawn(move ||
{
let _my_obs = directory_tree.create_observations("000000");
println!("{}", "OBS CREATA".red().bold());

println!("");
println!("{}", "Information about the observation".bright_green());
println!("Monte Carlo samples loaded: {}", _my_obs.get_mcid().len());
println!("Number of Detectors: {}", _my_obs.get_detector().len());
println!("Number of Point Vectors: {}", _my_obs.get_pix().len());
println!("Number of ToDs: {}", _my_obs.get_tod().len());

_my_obs.binning();
});

_t1.join().unwrap();

let (hit, signal) = my_obs.binning();

// Plot things
// // Plot things

let mut fg = Figure::new();
// let mut fg = Figure::new();

fg.axes2d().points(
hit,
signal,
&[Caption("Binned Map"), Color("black")]
);
// fg.axes2d().points(
// hit,
// signal,
// &[Caption("Binned Map"), Color("black")]
// );

fg.show().unwrap();
// fg.show().unwrap();

}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file removed tests/dir_test/2022010113/test.dat
Empty file.
Empty file.
Empty file.
Empty file removed tests/dir_test/2022010114/test.dat
Empty file.
13 changes: 6 additions & 7 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ use mapmaking::iteratorscustom::FloatIterator;

#[test]
fn test_direcotry() {
let path = Path::new("tests/");
// let test_directory_tree = DirStruct::new(path, String::from("1")).unwrap();
let cd = std::env::current_dir().unwrap();
println!("DIR: {:?}", cd);
let path = Path::new("tests/dir_test/");
println!("{:?}", path);

// assert_eq!(
// test_directory_tree._get_obs_time(),
// String::from("1")
// );
let dir_tree = DirStruct::new(path, String::from("1")).unwrap();
let obs= dir_tree.create_observations("000000");

assert_eq!(2+2, 4)
}

#[test]
Expand Down

0 comments on commit 6f4a267

Please sign in to comment.