Skip to content

Commit

Permalink
peakfit: Limit multiprocessing to 2 processes during fitting (Fixes #743
Browse files Browse the repository at this point in the history
)

Can be overridden with new env var QUASAR_N_PROCESSES=all
  • Loading branch information
stuart-cls committed Sep 25, 2024
1 parent 8add9b5 commit 751e359
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doc/widgets/peakfit.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ Common uses of these constraints would be:
- Limiting the *center* position to some range of x values
- Setting a minimum *amplitude* to force positive peaks
- Setting a maximum *sigma* to exclude unreasonably wide peaks

Advanced
--------

Unlike the majority of widgets, **Peak Fit** uses multiple processes during fitting to improve
responsiveness and performance. By default this is limited to 2 extra processes, but this can be
overridden by setting the environment variable `QUASAR_N_PROCESSES` to the desired number, or `all`
to use the default value returned by `os.cpu_count()`.
5 changes: 4 additions & 1 deletion orangecontrib/spectroscopy/widgets/owpeakfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from functools import reduce
import concurrent.futures
import multiprocessing
import os

from lmfit import Parameters, Model
from lmfit.model import ModelResult
Expand Down Expand Up @@ -36,7 +37,9 @@
best_fit_results, pool_initializer, pool_fit, pool_fit2

# number of processes used for computation
N_PROCESSES = None
# Use 2 or less unless overridden by QUASAR_N_PROCESSES
env_proc = os.getenv('QUASAR_N_PROCESSES')
N_PROCESSES = None if env_proc == "all" else int(env_proc) if env_proc else min(2, multiprocessing.cpu_count())


def fit_results_table(output, model_result, orig_data):
Expand Down

0 comments on commit 751e359

Please sign in to comment.