ompOptions¶
Sets various OpenMP options.
Synopsis with Optional Arguments¶
ompOptions ()
Return Value¶
The return value for this function is void.
Optional Arguments¶
setFunctionsThreadSafe
, int (Input)If nonzero, user supplied functions are assumed to be thread-safe. This allows user functions to be evaluated in parallel with different arguments.
Default: User supplied functions are not assumed to be thread-safe and are not evaluated in parallel by PyIMSL functions.
getFunctionsThreadSafe
(Output)- Retrieves the current thread-safe setting for user functions. If user functions are not thread-safe, then a value of zero is returned; otherwise a value of one is returned.
Description¶
The performance of some PyIMSL functions can be improved if they evaluate
user supplied functions in parallel. Unfortunately, incorrect results can
occur if the user supplied functions are not thread-safe. By default, the
PyIMSL functions assumes user supplied functions are not thread-safe and
thus will not evaluate them in parallel. To change this assumption, use the
optional argument setFunctionsThreadSafe
with its argument equal to one.
This function can be used multiple times in an application to change the thread-safe assumption.
Example¶
This example computes the integral \(\int_{0}^{2} x e^x dx\). A call to
the function ompOptions
is used to indicate that function fcn
is
thread-safe and so can be safely evaluated by multiple, simultaneous
threads.
from __future__ import print_function
from pyimsl.math.ompOptions import ompOptions
from pyimsl.math.intFcn import intFcn
from math import exp
def fcn(x):
return x * (exp(x))
ompOptions(setFunctionsThreadSafe=1)
# Evaluate the integral and print result */
q = intFcn(fcn, 0.0, 2.0)
exact = exp(2.0) + 1.0
print("integral = %10.3f\nexact = %10.3f\n" % (q, exact))
a = []
ompOptions(getFunctionsThreadSafe=a)
print("getFunctionThreadSafe =", a[0])
Output¶
integral = 8.389
exact = 8.389
getFunctionThreadSafe = 1