ompOptions¶
Sets various OpenMP options.
Synopsis¶
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 will not be evaluated in parallel by PyIMSL functions.
getFunctionsThreadSafe
(Output)- Sets the integer pointed to by
getFunctionsThreadSafe
to zero if user functions are not assumed to be thread-safe and to one if they are assumed to be thread-safe.
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 assume 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 performs a chi-squared test on a randomly generated sample. A
call to the function ompOptions
is used to indicate that function
cdf
is thread-safe and so can be safely evaluated by multiple,
simultaneous threads.
from __future__ import print_function
from pyimsl.stat.ompOptions import ompOptions
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.normalCdf import normalCdf
from pyimsl.stat.chiSquaredTest import chiSquaredTest
from pyimsl.stat.randomNormal import randomNormal
def cdf(x):
return normalCdf(x)
ompOptions(setFunctionsThreadSafe=1)
randomSeedSet(123457)
x = randomNormal(1000)
p_value = chiSquaredTest(cdf, 10, x)
print("p-value = %7.4f\n" % (p_value))
a = []
ompOptions(getFunctionsThreadSafe=a)
print("getFunctionThreadSafe =", a[0])
Output¶
p-value = 0.1546
getFunctionThreadSafe = 1