gwythreads: Gwyddion Library Reference Manual

## gwythreads gwythreads — Multithread processing control |

## Functions

gboolean | gwy_threads_are_enabled ()
void | gwy_threads_set_enabled ()

## Includes

    #include <libgwyddion/gwyddion.h>

## Description

Gwyddion can utilise multithread processing via OpenMP.

It is disabled by default. If it is enabled, is utilised internally and transparently in Gwyddion functions. No threads are exposed in the API.

The only exception is that when multithread processing is enabled, user-supplied routines called during data processing such as GwyNLFitFunc or GwyCooordTransform2DFunc may be called from multiple threads and must be reentrant. This does not apply to GwySetMessageFunc and GwySetFractionFunc which are always called from the main (GUI) thread.

If you run programs or scripts based on Gwyddion in parallel, for instance in a simulation or batch data processing, it is recommended to keep multithread processing disabled. For GUI programs (like Gwyddion itself) or tasks run serially, it can be useful to enable it.

If Gwyddion was not built with multithread processing support, enabling threads does not do anything and `gwy_threads_are_enabled()` will continue to return `FALSE`.

If Gwyddion is built with OpenMP-enabled FFTW, it calls `fftw_init_threads()` when threads are enabled and can employ multithreaded FFTW. When mixing Gwyddion functions with direct FFTW utilisation, call `fftw_plan_with_nthreads()` with your preferred number of threads before you create a plan.

## Functions

### gwy_threads_are_enabled ()

    gboolean
    gwy_threads_are_enabled (void);

Obtains the state of internal multithread processing.

#### Returns

`TRUE` if multithread processing is enabled; `FALSE` otherwise (this includes the case of Gwyddion not built with multithread processing support at all).

Since: 2.53

### gwy_threads_set_enabled ()

    void
    gwy_threads_set_enabled (gboolean setting);

Enables or disables internal multithread processing.

This function can be called any time during the program life time to switch between single- and multithread processing. It must be called from the main thread while no Gwyddion data processing functions are being executed.

#### Parameters

setting | `TRUE` to enable multithread processing; `FALSE` to disable it. |

Since: 2.53