Closed sourabhmet closed 3 years ago
# Your code here # Parallel computation of pi in Ruby PI25DT = 3.141592653589793238462643 NINTERVALS = 10000 $rank = MPI::Comm::WORLD.rank() $size = MPI::Comm::WORLD.size() $startwtime = MPI.wtime() $h = 1.0 / NINTERVALS $sum = 0.0 ($rank + 1).step(NINTERVALS, $size) do |i| x = $h * (i - 0.5) $sum += (4.0 / (1.0 + x**2)) end mypi = $h * $sum $pi = MPI::Comm::WORLD.reduce(mypi, MPI::Op::SUM, 0) if $rank == 0 then printf "pi is ~= %.16f, error = %.16f\n", $pi, ($pi - PI25DT).abs $endwtime = MPI.wtime() puts "wallclock time = #{$endwtime-$startwtime}" end
I am trying to run ruby code, I am also importing MPI in it. but I am getting the error
Please help, It looks the problem is with MPI, how can I resolve it.
Dear @sourabhmet. How is this related to psy-simple?
P.S.: I am not an expert in Ruby, so maybe better ask the question on stackoverflow?
Thanks @Chilipp
Code Sample, a copy-pastable example if possible
Problem description
I am trying to run ruby code, I am also importing MPI in it. but I am getting the error
Please help, It looks the problem is with MPI, how can I resolve it.