-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
193 lines (155 loc) · 4.77 KB
/
main.cpp
File metadata and controls
193 lines (155 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <math.h>
#include <mpi.h>
#include <netcdf.h>
#include <stdio.h>
#include <vector>
#include "main.h"
#include "boost_def.h"
#include "ncio.h"
#include "string_util.h"
#include "variables.h"
#include "par.h"
/** Processors index to process. */
ma1iu istart;
ma1iu iend;
ma1iu jstart;
ma1iu jend;
ma3f tmask;
ma3f e3t_0;
using namespace std;
int mpiRank;
int mpiSize;
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &mpiRank);
MPI_Comm_size(MPI_COMM_WORLD, &mpiSize);
if (mpiSize != LON_MPI * LAT_MPI) {
printf("LON_MPI * LAT_MPI = %d, should be %d\n", LON_MPI * LAT_MPI, mpiSize);
MPI_Finalize();
exit(1);
}
// Init the RGB attenuation coefficients
init_zrgb();
vector<string> list_chl_files = get_files(chl_pattern);
vector<string> list_qsr_files = get_files(qsr_pattern);
#ifdef VVL
vector<string> list_e3t_files = get_files(e3t_pattern);
#endif
// count the number of read for the given file
// ichl = index of the file in the list of files
// stepchl = time step being read in the file
// nchl = number of time steps in the file
size_t stepchl = 0;
int ichl = 0;
size_t nchl = get_ntime_file(list_chl_files[ichl].c_str());
size_t stepqsr = 0;
int iqsr = 0;
size_t nqsr = get_ntime_file(list_qsr_files[iqsr].c_str());
#ifdef VVL
size_t stepe3t = 0;
int ie3t = 0;
size_t ne3t = get_ntime_file(list_e3t_files[ie3t].c_str());
#endif
// iterator for the output
int iout = 0;
int stepout = 0;
// initialisation of the MPI decomposition.
init_mpi_domains();
int nx = get_nx(mpiRank);
int ny = get_ny(mpiRank);
// Init. the input arrays
ma3f tmask(boost::extents[NZ][ny][nx]);
ma3f e3t(boost::extents[NZ][ny][nx]);
ma3f chl(boost::extents[NZ][ny][nx]);
ma2f qsr(boost::extents[ny][nx]);
ma3f par(boost::extents[NZ][ny][nx]);
#ifdef PARFRAC
ma3f parfrac(boost::extents[NFRAC][ny][nx]);
read_parfrac(parfrac, parfrac_file, parfrac_var);
#endif
// Reading variable for e3t
read_var(e3t, mesh_mask, "e3t_0", 0);
read_var(tmask, mesh_mask, "tmask", 0);
if (mpiRank == 0)
printf("+++++++++++++++++++++++++++++++ Starting computations\n");
for (int time = 0; time < NTIME; time++) {
if (stepchl == nchl) {
ichl++;
stepchl = 0;
nchl = get_ntime_file(list_chl_files[ichl].c_str());
}
if (stepqsr == nqsr) {
iqsr++;
stepqsr = 0;
nqsr = get_ntime_file(list_qsr_files[iqsr].c_str());
}
#ifdef VVL
if (stepe3t == ne3t) {
ie3t++;
stepe3t = 0;
ne3t = get_ntime_file(list_e3t_files[ie3t].c_str());
}
#endif
if(mpiRank == 0) printf("++++++ time = %d\n", time);
read_var(qsr, list_qsr_files[iqsr].c_str(), qsr_var, stepqsr);
read_var(chl, list_chl_files[ichl].c_str(), chl_var, stepchl, conversion_chl);
#ifdef VVL
read_var(e3t, list_e3t_files[ie3t].c_str(), e3t_var, stepe3t);
#endif
#ifdef PARFRAC
int ifrac = time % NFRAC;
if(mpiRank == 0) printf("ifrac = %d\n", ifrac);
for (int j = 0; j < ny; j++) {
for (int i = 0; i < nx; i++) {
if(tmask[0][j][i] == 0) continue;
qsr[j][i] *= parfrac[ifrac][j][i];
}
}
#endif
// computation of PAR.
compute_par_c(par, chl, qsr, e3t, tmask);
if (iout == 0) {
define_output_file(stepout);
}
write_step(stepout, iout, par, time);
iout++;
if (iout == output_frequency) {
iout = 0;
stepout++;
}
stepchl++;
stepqsr++;
#ifdef VVL
stepe3t++;
#endif
}
// read the model mesh_mask
MPI_Finalize();
}
void init_mpi_domains(void) {
istart.resize(boost::extents[LON_MPI]);
iend.resize(boost::extents[LON_MPI]);
jstart.resize(boost::extents[LAT_MPI]);
jend.resize(boost::extents[LAT_MPI]);
int ncellx = NX / LON_MPI;
int ncelly = NY / LAT_MPI;
// init the MPI layers in longitude
istart[0] = 0;
iend[LON_MPI - 1] = NX - 1;
for (int i = 0; i < LON_MPI - 1; i++) {
iend[i] = ncellx * (1 + i) - 1;
istart[i + 1] = iend[i] + 1;
}
jstart[0] = 0;
jend[LAT_MPI - 1] = NY - 1;
for (int i = 0; i < LAT_MPI - 1; i++) {
jend[i] = ncelly * (1 + i) - 1;
jstart[i + 1] = jend[i] + 1;
}
if (mpiRank == 0) {
printf("++++++++++++++++++++++++ Init MPI decomposition\n");
for (int i = 0; i < LON_MPI * LAT_MPI; i++) {
printf("++++ i=%d, istart=%ld, iend=%ld, jstart=%ld, jend=%ld\n", i, get_istart(i), get_iend(i), get_jstart(i), get_jend(i));
}
}
}