0
How make method monte carlo in algorithm parallel in c++?
i need you help pls.
1 Antwort
+ 1
e.g. you want to calculate
integral[0,1]dx sin(x).
monte carlo now gives
integral[0,1]dx sin(x) ~SUM[i=0,i<N] (1-0)/N sin(x_i), with N
where you can split the right hand side into e.g. 2 sums which you can calculate separately (via MPI, etc...) and add afterwards
(1-0)/N (SUM[i=0,i<m] sin(x_i) + SUM[i=m,i<N] sin(x_i))
working cpp example (not sure why not working here at playground, maybe missing pthread flag etc.)
https://code.sololearn.com/cjQ8hA94GwpL/#cpp