map#

MapdlPool.map(func, iterable=None, progress_bar=True, close_when_finished=False, timeout=None, wait=True)#

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

Parameters:
funcfunction

User function with an instance of mapdl as the first argument. The remaining arguments should match the number of items in each iterable (if any).

iterablelist, tuple, optional

An iterable containing a set of arguments for func. If None, will run func once for each instance of mapdl.

progress_barbool, optional

Show a progress bar when running the batch. Defaults to True.

close_when_finishedbool, optional

Exit the MAPDL instances when the pool is finished. Default False.

timeoutfloat, optional

Maximum runtime in seconds for each iteration. If None, no timeout. If specified, each iteration will be only allowed to run timeout seconds, and then killed and treated as a failure.

waitbool, optional

Block execution until the batch is complete. Default True.

Returns:
list

A list containing the return values for func. Failed runs will not return an output. Since the returns are not necessarily in the same order as iterable, you may want to add some sort of tracker to the return of your user function``func``.

Examples

Run several input files while storing the final routine. Note how the user function to be mapped must use mapdl as the first argument. The function can have any number of additional arguments.

>>> completed_indices = []
>>> def func(mapdl, input_file, index):
        # input_file, index = args
        mapdl.clear()
        output = mapdl.input(input_file)
        completed_indices.append(index)
        return mapdl.parameters.routine
>>> inputs = [(examples.vmfiles['vm%d' % i], i) for i in range(1, 10)]
>>> output = pool.map(func, inputs, progress_bar=False, wait=True)
['Begin level',
 'Begin level',
 'Begin level',
 'Begin level',
 'Begin level',
 'Begin level',
 'Begin level',
 'Begin level',
 'Begin level']