I'm running a simulation for several repetitions and I'm trying to see if it would be possible to parallellise these repetitions to improve computation time.
Currently I simply run the simulation several times in a for loop, but ideally these could all be run at the same time, and then the results from each repetition saved to an array for processing.
Currently my code is something like
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
}
My question is, how can I run all these repetitions at the same time in parallel, and save the results from each parallel run in an allResults type array?
Thanks very much.