PSCF v1.3
Reduce.cpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "Reduce.h"
9#include <util/containers/Array.h>
10#include <cmath>
11
12namespace Pscf {
13namespace Prdc {
14namespace Cuda {
15namespace Reduce {
16
17 /*
18 * Get maximum of array elements.
19 */
20 double max(Array<double> const & in)
21 {
22 int n = in.capacity();
23 double max = in[0];
24 for (int i = 1; i < n; i++) {
25 if (in[i] > max) max = in[i];
26 }
27 return max;
28 }
29
30 /*
31 * Get maximum absolute magnitude of array elements.
32 */
33 double maxAbs(Array<double> const & in)
34 {
35 int n = in.capacity();
36 double val;
37 double max = std::abs(in[0]);
38 for (int i = 1; i < n; i++) {
39 val = std::abs(in[i]);
40 if (val > max) max = val;
41 }
42 return max;
43 }
44
45 /*
46 * Get minimum of array elements.
47 */
48 double min(Array<double> const & in)
49 {
50 int n = in.capacity();
51 double min = in[0];
52 for (int i = 1; i < n; i++) {
53 if (in[i] < min) min = in[i];
54 }
55 return min;
56 }
57
58 /*
59 * Get minimum absolute magnitude of array elements.
60 */
61 double minAbs(Array<double> const & in)
62 {
63 int n = in.capacity();
64 double val;
65 double min = std::abs(in[0]);
66 for (int i = 1; i < n; i++) {
67 val = std::abs(in[i]);
68 if (val < min) min = val;
69 }
70 return min;
71 }
72
73 /*
74 * Compute sum of array elements (GPU kernel wrapper).
75 */
76 double sum(Array<double> const & in)
77 {
78 int n = in.capacity();
79 double sum = 0.0;
80 for (int i = 0; i < n; i++) {
81 sum += in[i];
82 }
83 return sum;
84 }
85
86 /*
87 * Compute inner product of two real arrays.
88 */
89 double innerProduct(Array<double> const & a,
90 Array<double> const & b)
91 {
92 int n = a.capacity();
93 UTIL_CHECK(b.capacity() == n);
94 double sum = 0.0;
95 for (int i = 0; i < n; i++) {
96 sum += a[i]*b[i];
97 }
98 return sum;
99 }
100
101} // Reduce
102} // Cpu
103} // Prdc
104} // Pscf
Array container class template.
Definition Array.h:34
int capacity() const
Return allocated size.
Definition Array.h:159
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
Functions that perform parallel reductions on the GPU.
Definition Reduce.cpp:15
Fields, FFTs, and utilities for periodic boundary conditions (CUDA)
Definition Reduce.cpp:14
Periodic fields and crystallography.
Definition CField.cpp:11
PSCF package top-level namespace.
Definition param_pc.dox:1