MapdlPool#

class ansys.mapdl.core.pool.MapdlPool(n_instances, wait=True, run_location=None, port=50052, progress_bar=True, restart_failed=True, remove_temp_files=True, names=None, override=True, start_instance=None, exec_file=None, **kwargs)[source]#

Create a pool of MAPDL instances.

Note

Requires MAPDL 2020 R2 or later.

Parameters:
n_instanceint

Number of instances to create.

restart_failedbool, optional

Restarts failed instances. Defaults to True.

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.

portint, optional

Starting port for the MAPDL instances. 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.

remove_temp_filesbool, optional

This launcher creates a new MAPDL working directory for each instance of MAPDL within the temporary user directory, obtainable with tempfile.gettempdir(), for MAPDL files. When this parameter is True, this directory will be deleted when MAPDL is exited. Default False.

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}”.

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.

**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]

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_available([return_index])

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.