source: CIVL/examples/omp/HydroC/compute_deltat.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 A simple 2D hydro code
3 (C) Romain Teyssier : CEA/IRFU -- original F90 code
4 (C) Pierre-Francois Lavallee : IDRIS -- original F90 code
5 (C) Guillaume Colin de Verdiere : CEA/DAM -- for the C version
6*/
7/*
8
9This software is governed by the CeCILL license under French law and
10abiding by the rules of distribution of free software. You can use,
11modify and/ or redistribute the software under the terms of the CeCILL
12license as circulated by CEA, CNRS and INRIA at the following URL
13"http://www.cecill.info".
14
15As a counterpart to the access to the source code and rights to copy,
16modify and redistribute granted by the license, users are provided only
17with a limited warranty and the software's author, the holder of the
18economic rights, and the successive licensors have only limited
19liability.
20
21In this respect, the user's attention is drawn to the risks associated
22with loading, using, modifying and/or developing or reproducing the
23software by the user in light of its specific status of free software,
24that may mean that it is complicated to manipulate, and that also
25therefore means that it is reserved for developers and experienced
26professionals having in-depth computer knowledge. Users are therefore
27encouraged to load and test the software's suitability as regards their
28requirements in conditions enabling the security of their systems and/or
29data to be ensured and, more generally, to use and operate it in the
30same conditions as regards security.
31
32The fact that you are presently reading this means that you have had
33knowledge of the CeCILL license and that you accept its terms.
34
35*/
36
37#include <stdio.h>
38#include <string.h>
39#include <malloc.h>
40// #include <unistd.h>
41#include <math.h>
42
43#ifdef HMPP
44#undef HMPP
45#endif
46
47#include "parametres.h"
48#include "compute_deltat.h"
49#include "utils.h"
50#include "perfcnt.h"
51#include "equation_of_state.h"
52
53#define DABS(x) (real_t) fabs((x))
54
55inline void
56ComputeQEforRow(const int j,
57 const real_t Hsmallr,
58 const int Hnx,
59 const int Hnxt,
60 const int Hnyt,
61 const int Hnxyt,
62 const int Hnvar,
63 const int slices, const int Hstep,
64 real_t * uold,
65 real_t q[Hnvar][Hstep][Hnxyt], real_t e[Hstep][Hnxyt]
66 ) {
67 int i, s;
68
69#define IHV(i, j, v) ((i) + Hnxt * ((j) + Hnyt * (v)))
70
71#pragma omp parallel for shared(q, e) private(s, i) COLLAPSE
72 for (s = 0; s < slices; s++) {
73 for (i = 0; i < Hnx; i++) {
74 real_t eken;
75 real_t tmp;
76 int idxuID = IHV(i + ExtraLayer, j + s, ID);
77 int idxuIU = IHV(i + ExtraLayer, j + s, IU);
78 int idxuIV = IHV(i + ExtraLayer, j + s, IV);
79 int idxuIP = IHV(i + ExtraLayer, j + s, IP);
80 q[ID][s][i] = MAX(uold[idxuID], Hsmallr);
81 q[IU][s][i] = uold[idxuIU] / q[ID][s][i];
82 q[IV][s][i] = uold[idxuIV] / q[ID][s][i];
83 eken = half * (Square(q[IU][s][i]) + Square(q[IV][s][i]));
84 tmp = uold[idxuIP] / q[ID][s][i] - eken;
85 q[IP][s][i] = tmp;
86 e[s][i] = tmp;
87 }
88 }
89 {
90 int nops = slices * Hnx;
91 FLOPS(5 * nops, 3 * nops, 1 * nops, 0 * nops);
92 }
93#undef IHV
94#undef IHVW
95}
96
97// to force a parallel reduction with OpenMP
98#define WOMP
99
100inline void
101courantOnXY(real_t *cournox,
102 real_t *cournoy,
103 const int Hnx,
104 const int Hnxyt,
105 const int Hnvar, const int slices, const int Hstep, real_t c[Hstep][Hnxyt], real_t q[Hnvar][Hstep][Hnxyt],
106 real_t *tmpm1,
107 real_t *tmpm2
108 )
109{
110#ifdef WOMP
111 int s, i;
112 // real_t maxValC = zero;
113 real_t tmp1 = *cournox, tmp2 = *cournoy;
114
115#pragma omp parallel for shared(tmpm1, tmpm2) private(s,i) reduction(max:tmp1) reduction(max:tmp2)
116 for (s = 0; s < slices; s++) {
117 for (i = 0; i < Hnx; i++) {
118 tmp1 = MAX(tmp1, c[s][i] + DABS(q[IU][s][i]));
119 tmp2 = MAX(tmp2, c[s][i] + DABS(q[IV][s][i]));
120 }
121 }
122 *cournox = tmp1;
123 *cournoy = tmp2;
124 {
125 int nops = (slices) * Hnx;
126 FLOPS(2 * nops, 0 * nops, 2 * nops, 0 * nops);
127 }
128#else
129 int i, s;
130 real_t tmp1, tmp2;
131 for (s = 0; s < slices; s++) {
132 for (i = 0; i < Hnx; i++) {
133 tmp1 = c[s][i] + DABS(q[IU][s][i]);
134 tmp2 = c[s][i] + DABS(q[IV][s][i]);
135 *cournox = MAX(*cournox, tmp1);
136 *cournoy = MAX(*cournoy, tmp2);
137 }
138 }
139 {
140 int nops = (slices) * Hnx;
141 FLOPS(2 * nops, 0 * nops, 5 * nops, 0 * nops);
142 }
143#endif
144#undef IHVW
145}
146
147void compute_deltat_init_mem(const hydroparam_t H, hydrowork_t * Hw, hydrovarwork_t * Hvw)
148{
149 Hvw->q = (real_t (*)) DMalloc(H.nvar * H.nxyt * H.nxystep);
150 Hw->e = (real_t (*)) DMalloc( H.nxyt * H.nxystep);
151 Hw->c = (real_t (*)) DMalloc( H.nxyt * H.nxystep);
152 Hw->tmpm1 = (real_t *) DMalloc(H.nxystep);
153 Hw->tmpm2 = (real_t *) DMalloc(H.nxystep);
154
155}
156
157void compute_deltat_clean_mem(const hydroparam_t H, hydrowork_t * Hw, hydrovarwork_t * Hvw)
158{
159 DFree(&Hvw->q, H.nvar * H.nxyt * H.nxystep);
160 DFree(&Hw->e, H.nxyt * H.nxystep);
161 DFree(&Hw->c, H.nxyt * H.nxystep);
162 DFree(&Hw->tmpm1, H.nxystep);
163 DFree(&Hw->tmpm2, H.nxystep);
164}
165
166void
167compute_deltat(real_t *dt, const hydroparam_t H, hydrowork_t * Hw, hydrovar_t * Hv, hydrovarwork_t * Hvw) {
168 real_t cournox, cournoy;
169 int j, jend, slices, Hstep, Hmin, Hmax;
170 real_t (*e)[H.nxyt];
171 real_t (*c)[H.nxystep];
172 real_t (*q)[H.nxystep][H.nxyt];
173 WHERE("compute_deltat");
174
175 // compute time step on grid interior
176 cournox = zero;
177 cournoy = zero;
178
179 c = (real_t (*)[H.nxystep]) Hw->c;
180 e = (real_t (*)[H.nxystep]) Hw->e;
181 q = (real_t (*)[H.nxystep][H.nxyt]) Hvw->q;
182
183 Hstep = H.nxystep;
184 Hmin = H.jmin + ExtraLayer;
185 Hmax = H.jmax - ExtraLayer;
186 for (j = Hmin; j < Hmax; j += Hstep) {
187 jend = j + Hstep;
188 if (jend >= Hmax)
189 jend = Hmax;
190 slices = jend - j; // numbre of slices to compute
191 ComputeQEforRow(j, H.smallr, H.nx, H.nxt, H.nyt, H.nxyt, H.nvar, slices, Hstep, Hv->uold, q, e);
192 equation_of_state(0, H.nx, H.nxyt, H.nvar, H.smallc, H.gamma, slices, Hstep, e, q, c);
193 courantOnXY(&cournox, &cournoy, H.nx, H.nxyt, H.nvar, slices, Hstep, c, q, Hw->tmpm1, Hw->tmpm2);
194 // fprintf(stdout, "[%2d]\t%g %g %g %g\n", H.mype, cournox, cournoy, H.smallc, H.courant_factor);
195 }
196
197 *dt = H.courant_factor * H.dx / MAX(cournox, MAX(cournoy, H.smallc));
198 FLOPS(1, 1, 2, 0);
199 // fprintf(stdout, "[%2d]\t%g %g %g %g %g %g\n", H.mype, cournox, cournoy, H.smallc, H.courant_factor, H.dx, *dt);
200} // compute_deltat
201
202//EOF
Note: See TracBrowser for help on using the repository browser.