高级并行性:线程池、并行迭代器和进程
在编程领域,并行性是提高程序性能的关键技术之一。本文将深入探讨如何利用线程池、并行迭代器和进程来实现高级并行性,以提升程序的执行效率。
个体竞争与 pmars 调用
在考虑每个个体如何竞争时,我们需要将两个竞争的个体战士序列化到磁盘的临时位置,以便调用 pmars 进行模拟竞争。以下是具体的实现步骤:
1. 序列化战士到磁盘 :
pub fn compete(self, other: Individual) -> Winner {
let dir = TempDir::new("simulate").expect("could not make tempdir");
let l_path = dir.path().join("left-red");
let mut lfp = BufWriter::new(File::create(l_path).expect("could not write lfp"));
self.serialize(&mut lfp).expect("could not serialize");
drop(lfp);
let r_path = dir.path().join("right-red");
let mut rfp = BufWriter::new(File::create(r_path).expect("could not write rfp"));
other.serialize(&mut rfp).expect("
超级会员免费看
订阅专栏 解锁全文
1062

被折叠的 条评论
为什么被折叠?



