Octopus
finufft_low.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2026 Octopus developers
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18
19*/
20
39#include <config.h>
40
41#ifdef HAVE_NFFT
42
43#include <limits.h>
44#include <stdlib.h>
45
46#include <finufft.h>
47
56static int oct_finufft_nthreads(void) {
57 const char *env = getenv("FINUFFT_NUM_THREADS");
58 if (env == NULL || *env == '\0') {
59 return 0;
60 }
61
62 char *end = NULL;
63 long value = strtol(env, &end, 10);
64 if (*end != '\0' || value < 0 || value > INT_MAX) {
65 return 0;
66 }
67
68 return (int)value;
69}
70
81void *oct_finufft_opts_init(int nthreads) {
82 finufft_opts *opts = malloc(sizeof(*opts));
83
84 if (opts == NULL) {
85 return NULL;
86 }
87
88 finufft_default_opts(opts);
89 if (nthreads > 0) {
90 opts->nthreads = nthreads;
91 } else {
92 opts->nthreads = oct_finufft_nthreads();
93 }
94
95 return opts;
96}
97
103void oct_finufft_opts_end(void *opts) { free(opts); }
104
105#endif