parallel.py

Define parallel functions for Edge Finite Element Method (EFEM) of lowest order in tetrahedral meshes, namely, Nedelec elements.

petgem.parallel.parallel.func_start_as_many(func_items_args)[source]

Compute function as many arguments.

Parameters:func_item_args (str) – function arguments.
Returns:arguments.
Return type:arguments.

Note

Equivalent to:

func = func_item_args[0]

items = func_item_args[1]

args = func_item_args[2:]

return func(items[0],items[1],...,args[0],args[1],...)

petgem.parallel.parallel.func_start_as_single(func_item_args)[source]

Compute function as single argument.

Parameters:func_item_args (str) – function arguments.
Returns:arguments.
Return type:arguments.

Note

Equivalent to:

func = func_item_args[0]

item = func_item_args[1]

args = func_item_args[2:]

return func(item,args[0],args[1],...)

petgem.parallel.parallel.get_num_processors(num_proc)[source]

Compute the number of processors that had been insert by the user against available processors in the platform.

Params int num_proc:
 number of processors to set parallel environment.
Returns:number of processors to set parallel environment.
Return type:int

Note

if num_proc > available_processors then nProcesses=available_processors

petgem.parallel.parallel.parallel_map(func, iterable, *args, **kwargs)[source]

Parallel mapping of a function. Equivalent to:

return [function(x, args[0], args[1],...) for x in iterable]

Parameters:
  • func (str) – function name.
  • iterable (int) – iterable variable.
  • args (argument) – function arguments.
  • kwargs (argument) – keyword arguments.

Keyword arguments are defined as follows:

  • parallel = True/False: Force parallelization on/off
  • chunksize = see multiprocessing.Pool().map
  • pool = multiprocessing.Pool() Pass an existing pool.
  • processes = see multiprocessing.Pool() processes argument

Note

The original version of this function was adapted from J.F. Sebastian and from parmap python module.

petgem.parallel.parallel.parallel_map_async(func, iterable, *args, **kwargs)[source]

This function is the multiprocessing.Pool.map_async version that supports multiple arguments.

>>> [function(x, args[0], args[1],...) for x in iterable]
Parameters:
  • parallel (bool) – Force parallelization on/off.
  • chunksize (int) – see multiprocessing.pool.Pool.
  • callback (function) – see multiprocessing.pool.Pool.
  • error_callback (function) – see multiprocessing.pool.Pool.
  • pool (multiprocessing.pool.Pool) – Pass an existing pool.
  • processes (int) – Number of processes to use in the pool.
petgem.parallel.parallel.parallel_starmap(func, iterables, *args, **kwargs)[source]

Parallel start_mapping of a function. Equivalent to:

return [function(x1,x2,x3,..., args[0], args[1],...) for (x1,x2,x3...) in iterable].

Parameters:
  • func (str) – function name.
  • iterables (int) – iterable variables.
  • args (argument) – function arguments.
  • kwargs (argument) – keyword arguments.

Keyword arguments are defined as follows:

  • parallel = True/False: Force parallelization on/off
  • chunksize = see multiprocessing.Pool().map
  • pool = multiprocessing.Pool() Pass an existing pool.
  • processes = see multiprocessing.Pool() processes argument

Note

The original version of this function was adapted from J.F. Sebastian and from parmap python module.

petgem.parallel.parallel.unitary_test()[source]

Unitary test for parallel.py script.