【发布时间】:2019-02-25 14:44:47
【问题描述】:
我正在运行多次重复的模拟,我正在尝试查看是否可以并行化这些重复以缩短计算时间。
目前我只是在一个for循环中运行了几次模拟,但理想情况下,这些可以同时运行,然后将每次重复的结果保存到一个数组中进行处理。
目前我的代码类似于
public static void getAllTheData(){
int nReps = 10;
double[][] allResults = new double[nReps][]
//this for loop is what I want to parallellise
for(int r = 0; r < nReps; r++){
//run the simulation to completion here
simulation.doStuffToCompletion()
allResults[r] = simulation.getValues()
}
//average allResults here and do further analysis
}
我的问题是,如何同时并行运行所有这些重复,并将每次并行运行的结果保存在 allResults 类型的数组中?
非常感谢。
【问题讨论】:
标签: java optimization parallel-processing