Octopus
operate.c
Go to the documentation of this file.
1/*
2 Copyright (C) 2006 X. Andrade
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
21#include <config.h>
22
23#include <stddef.h>
24
25#include <assert.h>
26#include <vectors.h>
27
28#include <string.h>
29
43void FC_FUNC_(doperate_ri_vec,
44 DOPERATE_RI_VEC)(const int *opn, const double *restrict w,
45 const int *opnri, const int *opri,
46 const int *rimap_inv, const int *rimap_inv_max,
47 const double *restrict fi, const int *ldfp,
48 const int *stream,
49 double *restrict fo) {
50 const size_t ldf = ldfp[0];
51
52 /* check whether we got aligned vectors or not */
53 int aligned = 1;
54 aligned = aligned && (((long long)fi) % (8 * VEC_SIZE) == 0);
55 aligned = aligned && (((long long)fo) % (8 * VEC_SIZE) == 0);
56 aligned = aligned && ((1 << ldf) % VEC_SIZE == 0);
57
58 if (aligned && stream[0]) {
59#define ALIGNED
60#define STREAM
61#include "operate_inc.c"
62#undef STREAM
63#undef ALIGNED
64
65 } else if (aligned) {
66#define ALIGNED
67#include "operate_inc.c"
68#undef ALIGNED
69
70 } else {
71 /* not aligned */
72#include "operate_inc.c"
73 }
74}
75
76void FC_FUNC_(doperate_ri_sym_vec,
77 DOPERATE_RI_SYM_VEC)(const int *opn, const double *restrict wpair, const double *restrict wcenter,
78 const int *opnri, const int *opri_pos, const int *opri_neg,
79 const int *rimap_inv, const int *rimap_inv_max,
80 const double *restrict fi, const int *ldfp,
81 const int *stream,
82 double *restrict fo) {
83 const size_t ldf = ldfp[0];
84
85 /* check whether we got aligned vectors or not */
86 int aligned = 1;
87 aligned = aligned && (((long long)fi) % (8 * VEC_SIZE) == 0);
88 aligned = aligned && (((long long)fo) % (8 * VEC_SIZE) == 0);
89 aligned = aligned && ((1 << ldf) % VEC_SIZE == 0);
90
91 if (aligned && stream[0]) {
92#define ALIGNED
93#define STREAM
94#include "operate_sym_inc.c"
95#undef STREAM
96#undef ALIGNED
97
98 } else if (aligned) {
99#define ALIGNED
100#include "operate_sym_inc.c"
101#undef ALIGNED
102
103 } else {
104 /* not aligned */
105 #include "operate_sym_inc.c"
106 }
107}
108
109void FC_FUNC_(doperate_ri_antisym_vec,
110 DOPERATE_RI_ANTISYM_VEC)(const int *opn, const double *restrict wpair,
111 const int *opnri, const int *opri_pos, const int *opri_neg,
112 const int *rimap_inv, const int *rimap_inv_max,
113 const double *restrict fi, const int *ldfp,
114 const int *stream,
115 double *restrict fo) {
116 const size_t ldf = ldfp[0];
117
118 /* check whether we got aligned vectors or not */
119 int aligned = 1;
120 aligned = aligned && (((long long)fi) % (8 * VEC_SIZE) == 0);
121 aligned = aligned && (((long long)fo) % (8 * VEC_SIZE) == 0);
122 aligned = aligned && ((1 << ldf) % VEC_SIZE == 0);
123
124 if (aligned && stream[0]) {
125#define ALIGNED
126#define STREAM
127#include "operate_antisym_inc.c"
128#undef STREAM
129#undef ALIGNED
130
131 } else if (aligned) {
132#define ALIGNED
133#include "operate_antisym_inc.c"
134#undef ALIGNED
135
136 } else {
137 /* not aligned */
138#include "operate_antisym_inc.c"
139 }
141
142
143/* the same as doperate_ri_vec, but allows giving each an appropriate Fortan
144 interface in which fi and fo are actually complex in Fortran Could be inline,
145 but in that case pgcc will not put it in the symbol table. */
146void FC_FUNC_(zoperate_ri_vec,
147 ZOPERATE_RI_VEC)(const int *opn, const double *restrict w,
148 const int *opnri, const int *opri,
149 const int *rimap_inv, const int *rimap_inv_max,
150 const double *restrict fi, const int *ldfp,
151 const int *stream,
152 double *restrict fo) {
153 FC_FUNC_(doperate_ri_vec, DOPERATE_RI_VEC)
154 (opn, w, opnri, opri, rimap_inv, rimap_inv_max, fi, ldfp, stream, fo);
157void FC_FUNC_(zoperate_ri_sym_vec,
158 ZOPERATE_RI_SYM_VEC)(const int *opn, const double *restrict w,
159 const double *restrict wcenter,
160 const int *opnri, const int *opri_pos, const int *opri_neg,
161 const int *rimap_inv, const int *rimap_inv_max,
162 const double *restrict fi, const int *ldfp,
163 const int *stream,
164 double *restrict fo) {
165 FC_FUNC_(doperate_ri_sym_vec, DOPERATE_RI_SYM_VEC)
166 (opn, w, wcenter, opnri, opri_pos, opri_neg, rimap_inv, rimap_inv_max, fi, ldfp, stream, fo);
167}
168
169void FC_FUNC_(zoperate_ri_antisym_vec,
170 ZOPERATE_RI_ANTISYM_VEC)(const int *opn, const double *restrict w,
171 const int *opnri, const int *opri_pos, const int *opri_neg,
172 const int *rimap_inv, const int *rimap_inv_max,
173 const double *restrict fi, const int *ldfp,
174 const int *stream,
175 double *restrict fo) {
176 FC_FUNC_(doperate_ri_antisym_vec, DOPERATE_RI_SYM_VEC)
177 (opn, w, opnri, opri_pos, opri_neg, rimap_inv, rimap_inv_max, fi, ldfp, stream, fo);
178}
179
180
181void FC_FUNC_(dgauss_seidel,
182 DGAUSS_SEIDEL)(const int *opn, const double *restrict w,
183 const int *opnri, const int *opri,
184 const int *rimap_inv, const int *rimap_inv_max,
185 const double *restrict factor, double *pot,
186 const double *restrict rho) {
187
188 const int n = opn[0];
189 const int nri = opnri[0];
190
191 int l, i, j;
192 const int *index;
193 register double a0;
194 register const double fac = *factor;
195
196 for (l = 0; l < nri; l++) {
197 index = opri + n * l;
198 i = rimap_inv[l];
199
200 for (; i < rimap_inv_max[l]; i++) {
201 a0 = w[0] * pot[i + index[0]];
202 for (j = 1; j < n; j++)
203 a0 += w[j] * pot[i + index[j]];
204 pot[i] += fac * (a0 - rho[i]);
205 }
206 }
207}
208
209
210// Returns the compile-time vectorization level
211void get_vectorization_level(char * level) {
212 char * vector = VECTORIZATION_LEVEL;
213 size_t len = strlen(vector) + 1;
214 strncpy(level, vector, len);
215}
216
void FC_FUNC_(doperate_ri_sym_vec, DOPERATE_RI_SYM_VEC) const
Definition: operate.c:2193
void get_vectorization_level(char *level)
Definition: operate.c:3534
const ptrdiff_t nri
ptrdiff_t l
ptrdiff_t i
ptrdiff_t j
const int *restrict index
Definition: operate_inc.c:30