Parallel simulations written in one file

I am trying to run parallel coding of Julia with a frequency of 10,000 (each simulation does not depend on everyone else) in the cluster. Each simulation has one number for output (along with 3 columns of information about which simulation the number produced). Therefore, for me it is a little silly to make each simulation print in a separate file.

Can I safely ask all these simulations to write in one file, or can this cause an error if two simulation files are written to the file at the same time? What is the best solution?

+5
source share
1 answer

Here is a brief example of how you can set up a set of 10,000 independent simulations for parallel work in Julia using pmap() :

 @everywhere function simulate(i) # we compute the simulation results here. In this case we just return # the simulation number and a random value x = rand() return (i,x) end x = pmap(simulate,1:10000) # x is the array of tuples returned from all the simulations showall(x) # ... or we could write x to a file or do something else with it 

@everywhere required so that the simulate() function is available to all processes, not just one process. pmap() calls simulate() once for each of the values ​​in the second parameter in parallel and returns an array of all the results obtained using simulate() .

+4
source

Source: https://habr.com/ru/post/1210932/


All Articles