Chapter 12: Utilities > omp_options

omp_options

Sets various OpenMP options.

Synopsis with Optional Arguments

#include <imsl.h>

void imsl_omp_options (

IMSL_SET_FUNCTIONS_THREAD_SAFE, int setting,

IMSL_GET_FUNCTIONS_THREAD_SAFE, int *psetting,

0)

Return Value

The return value for this function is void.

Optional Arguments

IMSL_SET_FUNCTIONS_THREAD_SAFE, int setting   (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  IMSL C Math Library functions.

IMSL_GET_FUNCTIONS_THREAD_SAFE, int *psetting   (Output)
Sets the integer pointed to by psetting  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 IMSL C Math Library 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 IMSL C Math Library assumes user supplied functions are not thread-safe and thus will not evaluate them in parallel. To change this assumption, use the optional argument IMSL_SET_FUNCTIONS_THREAD_SAFE 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. A call to the function imsl_omp_options is used to indicate that function fcn is thread-safe and so can be safely evaluated by multiple, simultaneous threads.

#include <stdio.h>

#include <math.h>

#include <imsl.h>

 

float fcn(float x);

 

int main()

{

    float q;

    float exact;

   

    imsl_omp_options(IMSL_SET_FUNCTIONS_THREAD_SAFE, 1, 0);

   

    /* Evaluate the integral and print result */

    q = imsl_f_int_fcn (fcn, 0.0, 2.0, 0);

    exact = exp(2.0) + 1.0;

    printf("integral = %10.3f\nexact    = %10.3f\n", q, exact);

}

 

float fcn(float x)

{

    return x * (exp(x));

}

 

Output

integral =      8.389

exact    =      8.389


RW_logo.jpg
Contact Support