check this code: fn main() { initwithlevel(Level::Info).unwrap(); let args: Args =…
- User
check this code:
fn main() { init_with_level(Level::Info).unwrap();
let args: Args = Args::parse(); args.check().unwrap_or_else(|e| { error!("{}", e); std::process::exit(1); }); info!("{:?}", args); rayon::ThreadPoolBuilder::new() .num_threads(args.threads) .build_global() .unwrap(); let start = std::time::Instant::now(); info!("Parsing records..."); let bed = reader(&args.bed).unwrap(); let isoseq = reader(&args.reads).unwrap(); let (tracks, _) = parse_tracks(&bed, INTRON).unwrap(); let (reads, lines) = parse_tracks(&isoseq, EXON).unwrap(); let consensus = Arc::new(consensus(tracks)); let bucket = Arc::new(DashMap::<Pocket, Vec<Arc<str>>>::new()); let ir_info = Arc::new(ConcurrentVec::<IntronRetentionInfo>::new()); reads .par_iter() .flat_map(|(chr, txs)| { let cn = consensus.get(chr).unwrap(); // need to catch an error here txs.par_iter().filter_map(move |tx| pseudomap(cn, tx)) }) .for_each(|(id, pocket, status)| { bucket.entry(pocket).or_default().push(id); let local_info = ir_info.clone(); local_info.push(status); }); write_objs(&bucket, lines); println!("{:?}", ir_info); let elapsed = start.elapsed(); info!("Elapsed: {:?}", elapsed);}
I got this error:
Job 1, 'cargo run --release -- -b ../te…' terminated by signal SIGSEGV (Address boundary error)
- Assistant
- User
do you have another idea instead of using ConcurrentVec?
- Assistant
Yes, if
ConcurrentVecis causing issues or if it's a non-standard component that you'd rather avoid using, you can consider several alternatives for handling concurrent vector-like data in Rust. These alternatives are based on safe and often-used concurrent data structures provided by well-known crates. Here are a few suggestions: - User
here:
reads .par_iter() .flat_map(|(chr, txs)| { let cn = consensus.get(chr).unwrap(); // need to catch an error here txs.par_iter().filter_map(move |tx| pseudomap(cn, tx)) }) .for_each(|(id, pocket, status)| { bucket.entry(pocket).or_default().push(id); });I am trying to append status to a vector or a HashSet but since I use rayon at the beginning, this structure needs to be concurrent, any idea? Take in mind that this needs to be most efficient and fast way possible
- Assistant
- User
check this code:
fn main() { init_with_level(Level::Info).unwrap();
let args: Args = Args::parse(); args.check().unwrap_or_else(|e| { error!("{}", e); std::process::exit(1); }); info!("{:?}", args); rayon::ThreadPoolBuilder::new() .num_threads(args.threads) .build_global() .unwrap(); let start = std::time::Instant::now(); info!("Parsing records..."); let bed = reader(&args.bed).unwrap(); let isoseq = reader(&args.reads).unwrap(); let (tracks, _) = parse_tracks(&bed, INTRON).unwrap(); let (reads, lines) = parse_tracks(&isoseq, EXON).unwrap(); let consensus = Arc::new(consensus(tracks)); let bucket = Arc::new(DashMap::<Pocket, Vec<Arc<str>>>::new()); let ir_info = DashSet::<IntronRetentionInfo>::new(); reads .par_iter() .flat_map(|(chr, txs)| { let cn = consensus.get(chr).unwrap(); // need to catch an error here txs.par_iter().filter_map(move |tx| pseudomap(cn, tx)) }) .for_each(|(id, pocket, status)| { if pocket == Pocket::IntronRetention { ir_info.insert(status); } bucket.entry(pocket).or_default().push(id); }); write_objs(&bucket, lines); println!("{:?}", ir_info); let elapsed = start.elapsed(); info!("Elapsed: {:?}", elapsed); - Assistant
In your code, wrapping
consensusin anArc<T>(atomically reference-counted type) would be necessary if you need to share ownership ofconsensusacross multiple threads while ensuring thread safety. The allows multiple threads to hold references to without running into race conditions or other threading problems because it ensures that the underlying data is not dropped until all references to it are out of scope.