
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "_as_gen/run_read_mpi_timers.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download__as_gen_run_read_mpi_timers.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr__as_gen_run_read_mpi_timers.py:


Read Shamrock MPI timers
===========================

.. GENERATED FROM PYTHON SOURCE LINES 6-17

.. code-block:: Python
   :lineno-start: 7


    import numpy as np

    import shamrock

    # If we use the shamrock executable to run this script instead of the python interpreter,
    # we should not initialize the system as the shamrock executable needs to handle specific MPI logic
    if not shamrock.sys.is_initialized():
        shamrock.change_loglevel(1)
        shamrock.sys.init("0:0")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    -> modified loglevel to 0 enabled log types :  
    log status :  
     - Loglevel: 1, enabled log types : 
    [xxx] Info: xxx ( logger::info )  
    [xxx] : xxx ( logger::normal )  
    [xxx] Warning: xxx ( logger::warn )  
    [xxx] Error: xxx ( logger::err )  




.. GENERATED FROM PYTHON SOURCE LINES 18-21

.. code-block:: Python
   :lineno-start: 18

    before_mpi_timers = shamrock.comm.get_timers()
    print(f"before_mpi_timers = {before_mpi_timers}")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    before_mpi_timers = {'total': 2.7099999933000163e-07, 'MPI_Barrier': 2.7099999933000163e-07}




.. GENERATED FROM PYTHON SOURCE LINES 22-23

Force some MPI time in the most rude way possible

.. GENERATED FROM PYTHON SOURCE LINES 23-26

.. code-block:: Python
   :lineno-start: 23

    for i in range(1000):
        shamrock.sys.mpi_barrier()








.. GENERATED FROM PYTHON SOURCE LINES 27-30

.. code-block:: Python
   :lineno-start: 27

    after_mpi_timers = shamrock.comm.get_timers()
    print(f"after_mpi_timers = {after_mpi_timers}")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    after_mpi_timers = {'total': 2.6085999991209974e-05, 'MPI_Barrier': 2.6085999991209974e-05}




.. GENERATED FROM PYTHON SOURCE LINES 31-32

Compute the delta

.. GENERATED FROM PYTHON SOURCE LINES 32-36

.. code-block:: Python
   :lineno-start: 32

    delta = shamrock.comm.mpi_timers_delta(before_mpi_timers, after_mpi_timers)

    for k in sorted(delta):
        print(f"{k} = {delta[k]} s")




.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    MPI_Allgather = 0.0 s
    MPI_Allgatherv = 0.0 s
    MPI_Allreduce = 0.0 s
    MPI_Barrier = 2.5814999991879972e-05 s
    MPI_Exscan = 0.0 s
    MPI_File_close = 0.0 s
    MPI_File_open = 0.0 s
    MPI_File_read = 0.0 s
    MPI_File_read_at = 0.0 s
    MPI_File_set_view = 0.0 s
    MPI_File_write = 0.0 s
    MPI_File_write_all = 0.0 s
    MPI_File_write_at = 0.0 s
    MPI_Gather = 0.0 s
    MPI_Gatherv = 0.0 s
    MPI_Get_count = 0.0 s
    MPI_Irecv = 0.0 s
    MPI_Isend = 0.0 s
    MPI_Probe = 0.0 s
    MPI_Recv = 0.0 s
    MPI_Send = 0.0 s
    MPI_Test = 0.0 s
    MPI_Type_size = 0.0 s
    MPI_Wait = 0.0 s
    MPI_Waitall = 0.0 s
    total = 2.5814999991879972e-05 s





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.679 seconds)

**Estimated memory usage:**  210 MB


.. _sphx_glr_download__as_gen_run_read_mpi_timers.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: run_read_mpi_timers.ipynb <run_read_mpi_timers.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: run_read_mpi_timers.py <run_read_mpi_timers.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: run_read_mpi_timers.zip <run_read_mpi_timers.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
