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

.. only:: html

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

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

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

.. _sphx_glr_howto_parallel_processing.py:


===================
Parallel Processing
===================

.. GENERATED FROM PYTHON SOURCE LINES 8-11

You should be able to treat models like any other function in terms of
parallelization.  This example shows using the built-in :mod:`multiprocessing` to do
process-based parallelization of an explicit system.

.. GENERATED FROM PYTHON SOURCE LINES 11-27

.. code-block:: Python


    from multiprocessing import Pool

    import condor


    class Model(condor.ExplicitSystem):
        x = input()
        output.y = -x**2 + 2*x + 1


    with Pool(5) as p:
        models = p.map(Model, [1, 2, 3])

    for model in models:
        print(model.input, model.output)




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

 .. code-block:: none

    ModelInput(x=1) ModelOutput(y=array([2.]))
    ModelInput(x=2) ModelOutput(y=array([1.]))
    ModelInput(x=3) ModelOutput(y=array([-2.]))





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

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


.. _sphx_glr_download_howto_parallel_processing.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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