code: def comp_pi(n, comm, root=0):
      nprocs = comm.Get_size()
      myrank = comm.Get_rank()
      n = N.array(n, "i")
      comm.Bcast([n, MPI.INT], root=root)
      if n == 0:
          return 0.0
      h = 1.0 / n
      s = 0.0
      for i in range(myrank, n, nprocs):
          x = h * (i + 0.5)
          s += 4.0 / (1.0 + x**2)
      mypi = s * h
      mypi = N.array(mypi, "d")
      pi = N.array(0, "d")
      comm.Reduce(
          [mypi, MPI.DOUBLE], [pi, MPI.DOUBLE], root=root, op=MPI.SUM
      )
      return pi
  
file_path: mpi4py/demo/compute-pi/cpi-dpm.py
imports: import sys
  from mpi4py import MPI
  import numpy
label_desc: Use image node_id 3 for calling a global function with example usage: comp_pi(n, comm, root) and returns: pi, int