(git:e70887f)
Loading...
Searching...
No Matches
fft_utils.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2026 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: BSD-3-Clause */
6/*----------------------------------------------------------------------------*/
7#ifndef FFT_UTILS_H
8#define FFT_UTILS_H
9
10#include "fft_timer.h"
11
12#include <complex.h>
13#include <omp.h>
14#include <stdio.h>
15#include <string.h>
16
17#define FFT_FORWARD 1
18#define FFT_BACKWARD -1
19
20/*******************************************************************************
21 * \brief Returns the number of threads used for FFT planning.
22 * Outside an OpenMP parallel region the maximum number of threads is
23 * used. Inside a parallel region a single thread is used to avoid
24 * nested parallelism and concurrently executed shared plans.
25 * \author Frederick Stein
26 ******************************************************************************/
27static inline int fft_team_size(void) {
28 return omp_in_parallel() ? 1 : omp_get_max_threads();
29}
30
31/*******************************************************************************
32 * \brief Returns the smaller of two given integer (missing from the C standard)
33 * \author Ole Schuett
34 ******************************************************************************/
35static inline int imin(int x, int y) { return (x < y ? x : y); }
36
37/*******************************************************************************
38 * \brief Returns the larger of two given integer (missing from the C standard)
39 * \author Ole Schuett
40 ******************************************************************************/
41static inline int imax(int x, int y) { return (x > y ? x : y); }
42
43/*******************************************************************************
44 * \brief Returns the smaller of two given integer (missing from the C standard)
45 * \author Frederick Stein
46 ******************************************************************************/
47static inline double dmin(double x, double y) { return (x < y ? x : y); }
48
49/*******************************************************************************
50 * \brief Returns the larger of two given integer (missing from the C standard)
51 * \author Frederick Stein
52 ******************************************************************************/
53static inline double dmax(double x, double y) { return (x > y ? x : y); }
54
55/*******************************************************************************
56 * \brief Equivalent of Fortran's MODULO which always returns a positive number.
57 * https://gcc.gnu.org/onlinedocs/gfortran/MODULO.html
58 * \author Ole Schuett
59 ******************************************************************************/
60static inline int modulo(int a, int m) { return ((a % m + m) % m); }
61
62/*******************************************************************************
63 * \brief Calculates the product of three numbers.
64 * \author Frederick Stein
65 ******************************************************************************/
66static inline long int product3(const int array3[3]) {
67 return (long int)array3[0] * array3[1] * array3[2];
68}
69
70#endif /* FFT_UTILS_H */
71
72// EOF
static long int product3(const int array3[3])
Calculates the product of three numbers.
Definition fft_utils.h:66
static int imin(int x, int y)
Returns the smaller of two given integer (missing from the C standard).
Definition fft_utils.h:35
static int fft_team_size(void)
Returns the number of threads used for FFT planning. Outside an OpenMP parallel region the maximum nu...
Definition fft_utils.h:27
static int modulo(int a, int m)
Equivalent of Fortran's MODULO which always returns a positive number. https://gcc....
Definition fft_utils.h:60
static double dmin(double x, double y)
Returns the smaller of two given integer (missing from the C standard).
Definition fft_utils.h:47
static int imax(int x, int y)
Returns the larger of two given integer (missing from the C standard).
Definition fft_utils.h:41
static double dmax(double x, double y)
Returns the larger of two given integer (missing from the C standard).
Definition fft_utils.h:53