MapdlPool#

class ansys.mapdl.core.pool.MapdlPool(n_instances=None, wait=True, run_location=None, ip=None, port=50052, progress_bar=True, restart_failed=True, remove_temp_dir_on_exit=True, names=None, override=True, start_instance=None, exec_file=None, timeout=30, **kwargs)#

Create a pool of MAPDL instances.

Note

Requires MAPDL 2020 R2 or later.

Parameters:
n_instancesint, optional

Number of instances to create. This argument can be optional if the number of instances can be inferred from the ip and/or port arguments. See these arguments documentation for more information.

waitbool, optional

Wait for pool to be initialized. Otherwise, pool will start in the background and all resources may not be available instantly.

run_locationstr, optional

Base directory to create additional directories for each MAPDL instance. Defaults to a temporary working directory.

ipstr, list[str], optional

IP address(es) to connect to where the MAPDL instances are running. You can use one IP, if you have multiple instances running on it, but in that case you must specify all the ports using the argument port. If using a list of IPs, the number of ports in ‘port’ argument should match the number of IPs.

portint, list[int], optional

The ports where the MAPDL instances are started on or can be connected to. If you are connecting to a single remote instance (only one IP in ip argument), you must specify a number of ports equal to the number of instances you want to connect to. If you are connecting to multiple instances (multiple IPs in ip argument), the amount of ports, should match the number of IPs.

If only one port is specified and you are starting the MAPDL instances locally (start_instance is True), this port is the port for the first instance. The rest of the instances ports are unitarian increments of port, as long as these ports are free from other processes usage. If you are not starting the MAPDL instances local, PyMAPDL does not check whether these ports are busy or not. Defaults to 50052.

progress_barbool, optional

Show a progress bar when starting the pool. Defaults to True. Will not be shown when wait=False.

restart_failedbool, optional

Restarts any failed instances in the pool. Defaults to True.

remove_temp_dir_on_exitbool, optional

When run_location is None, this launcher creates a new MAPDL working directory within the user temporary directory, obtainable with tempfile.gettempdir(). When this parameter is True, this directory will be deleted when MAPDL is exited. Default False. If you change the working directory, PyMAPDL does not delete the original working directory nor the new one.

namesstr, Callable, optional

You can specify the names of the directories where the instances are created. A string or a function (callable) that accepts an integer and return an string can be used. If you use a string, “_{i}” is appended to that string, where “i” is the index of each instance in the pool. By default, the instances directories are named as “Instances_{i}”.

override: bool, optional

Attempts to delete the lock file at the run_location. Useful when a prior MAPDL session has exited prematurely and the lock file has not been deleted.

start_instancebool, optional

Set it to False to make PyMAPDL to connect to remote instances instead of launching them. In that case, you need to supply the MAPDL instances ports as a list of int s.

exec_file: str, optional

The location of the MAPDL executable. Will use the cached location when left at the default None.

**kwargsdict, optional

Additional keyword arguments. For a complete listing, see the description for the ansys.mapdl.core.launcher.launch_mapdl() method.

Examples

Simply create a pool of 10 instances to run in the temporary directory.

>>> from ansys.mapdl.core import MapdlPool
>>> pool = MapdlPool(10)
Creating Pool: 100%|########| 10/10 [00:01<00:00,  1.43it/s]

Create several instances with 1 CPU each running at the current directory within their own isolated directories.

>>> import os
>>> my_path = os.getcmd()
>>> pool = MapdlPool(10, nproc=1, run_location=my_path)
Creating Pool: 100%|########| 10/10 [00:01<00:00,  1.43it/s]

Create a pool while specifying the MAPDL executable in Windows.

>>> exec_file = 'C:/Program Files/ANSYS Inc/v212/ansys/bin/winx64/ANSYS212.exe'
>>> pool = MapdlPool(10, exec_file=exec_file)
Creating Pool: 100%|########| 10/10 [00:01<00:00,  1.43it/s]

Create a pool while specifying the MAPDL executable in Linux.

>>> exec_file = '/ansys_inc/v211/ansys/bin/ansys211'
>>> pool = MapdlPool(10, exec_file=exec_file)
Creating Pool: 100%|########| 10/10 [00:01<00:00,  1.43it/s]

Create a pool of instances in multiple instances and with different ports:

>>> pool = MapdlPool(ip=["123.0.0.1", "123.0.0.2", "123.0.0.3", "123.0.0.4"], port=[50052, 50053, 50055, 50060])
Creating Pool: 100%|########| 4/4 [00:01<00:00,  1.23it/s]

Methods

MapdlPool.exit([block])

Close out all instances in the pool.

MapdlPool.map(func[, iterable, ...])

Run a function for each instance of mapdl within the pool.

MapdlPool.next([return_index])

Return a context manager that returns available instances.

MapdlPool.next_available([return_index, as_ctx])

Wait until an instance of MAPDL is available and return that instance.

MapdlPool.run_batch(files[, clear_at_start, ...])

Run a batch of input files on the pool.

MapdlPool.wait_for_ready([timeout])

Wait until pool is ready.

Attributes

MapdlPool.ready

Return true if all the instances are ready (not exited)