title: How to calculate the runtime of MPI program in mpi4py
body: <p>I wrote this code and tried some functions to calculate the time but it shows an error while running.I tried to use the C functions that is used to calculate runtime of each processor by using <code>Wtime()</code> and <code>MPI_Reduce</code>.<code>Wtime()</code> works I guess but the reduce function does not work the way it should.
  The code is</p>
  <pre><code>from mpi4py import MPI
  import mpi4py
  import numpy as np
  
  comm = MPI.COMM_WORLD
  size = comm.size
  rank = comm.Get_rank()
  time1 = mpi4py.MPI.Wtime()
  
  
  a = np.random.randint(10, size=(10, 10))
  if rank == 0:
      b = np.random.randint(10, size=(10, 10))
      print(b)
  else:
      b = None
  
  b = comm.bcast(b, root=0)
  
  c = np.dot(a, b)
  
  if size == 1:
      
      result = np.dot(a, b)
  
  else:
      
      if rank == 0:
          
          a_row = a.shape[0]
      
          if a_row &gt;= size:
              
              split = np.array_split(a, size, axis=0)
              
      else:
          
          split = None
          
      split = comm.scatter(split, root=0)
      
      split = np.dot(split, b)
      
      data = comm.gather(split, root=0)
  
  time2 = mpi4py.MPI.Wtime()
  duration = time2 - time1
  totaltime = comm.reduce(duration,op = sum, root = 0)
  print(&quot;Runtime at %d is %f&quot; %(rank,duration))
  
  if rank == 0:
  
      result = np.vstack(data)
      print(result)
      print(totaltime)
  
  </code></pre>
  <p>The error it shows is</p>
  <pre><code>Runtime at 3 is 0.000574
  Traceback (most recent call last):
    File &quot;matrixmultMPI.py&quot;, line 48, in &lt;module&gt;
      totaltime = comm.reduce(duration,op = sum, root = 0)
    File &quot;mpi4py/MPI/Comm.pyx&quot;, line 1613, in mpi4py.MPI.Comm.reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1322, in mpi4py.MPI.PyMPI_reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1254, in mpi4py.MPI.PyMPI_reduce_intra
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1126, in mpi4py.MPI.PyMPI_reduce_p2p
  TypeError: 'float' object is not iterable
  Traceback (most recent call last):
    File &quot;matrixmultMPI.py&quot;, line 48, in &lt;module&gt;
      totaltime = comm.reduce(duration,op = sum, root = 0)
    File &quot;mpi4py/MPI/Comm.pyx&quot;, line 1613, in mpi4py.MPI.Comm.reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1322, in mpi4py.MPI.PyMPI_reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1254, in mpi4py.MPI.PyMPI_reduce_intra
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1126, in mpi4py.MPI.PyMPI_reduce_p2p
  TypeError: 'float' object is not iterable
  Traceback (most recent call last):
    File &quot;matrixmultMPI.py&quot;, line 48, in &lt;module&gt;
      totaltime = comm.reduce(duration,op = sum, root = 0)
    File &quot;mpi4py/MPI/Comm.pyx&quot;, line 1613, in mpi4py.MPI.Comm.reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1322, in mpi4py.MPI.PyMPI_reduce
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1254, in mpi4py.MPI.PyMPI_reduce_intra
    File &quot;mpi4py/MPI/msgpickle.pxi&quot;, line 1126, in mpi4py.MPI.PyMPI_reduce_p2p
  TypeError: 'float' object is not iterable
  
  
  </code></pre>
  <p>What's wrong with it and how do I go about it!!?</p>