---
title: lightning.fabric.plugins.environments.mpi.MPIEnvironment
description: An environment for running on clusters with processes created through MPI.
canonical: >-
  https://lightning.ai/docs/fabric/stable/full-api-reference/api/generated/lightning.fabric.plugins.environments.mpi.MPIEnvironment
---
# lightning.fabric.plugins.environments.mpi.MPIEnvironment {#lightning-fabric-plugins-environments-mpi-mpienvironment}

### `class lightning.fabric.plugins.environments.mpi.MPIEnvironment` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment}

Bases: [`ClusterEnvironment`](/docs/fabric/2.6.6/full-api-reference/api/generated/lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment.md#lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment "lightning.fabric.plugins.environments.cluster_environment.ClusterEnvironment")

An environment for running on clusters with processes created through MPI.

Requires the installation of the mpi4py package. See also: [https://github.com/mpi4py/mpi4py](https://github.com/mpi4py/mpi4py)

#### `static detect()` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.detect}

Returns `True` if the mpi4py package is installed and MPI returns a world size greater than 1.

Return type:

[`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")

#### `global_rank()` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.global_rank}

The rank (index) of the currently running process across all nodes and devices.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `local_rank()` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.local_rank}

The rank (index) of the currently running process inside of the current node.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `node_rank()` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.node_rank}

The rank (index) of the node on which the current process runs.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `world_size()` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.world_size}

The number of processes across all devices and nodes.

Return type:

[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")

#### `property creates_processes_externally: bool` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.creates_processes_externally}

Whether the environment creates the subprocesses or not.

#### `property main_address: str` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.main_address}

The main address through which all processes connect and communicate.

#### `property main_port: int` {#lightning.fabric.plugins.environments.mpi.MPIEnvironment.main_port}

An open and configured port in the main node through which all processes communicate.

---

**Navigation**

- Parent: [Generated](/docs/fabric/2.6.6/full-api-reference/api/generated.md)
