Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
044c386b
Commit
044c386b
authored
5 months ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
eof: cleanup
parent
44c7e28e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!282
M214003/develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/EOFs.cc
+67
-66
67 additions, 66 deletions
src/EOFs.cc
src/eof_mode.cc
+1
-2
1 addition, 2 deletions
src/eof_mode.cc
with
68 additions
and
68 deletions
src/EOFs.cc
+
67
−
66
View file @
044c386b
...
...
@@ -53,7 +53,6 @@ scale_eigvec_time(Varray<double> &out, int tsID, int nts, size_t npack, const st
{
double
sum
=
0.0
;
for
(
int
j
=
0
;
j
<
nts
;
++
j
)
sum
+=
data
[
j
][
i
]
*
covar
[
tsID
][
j
];
out
[
pack
[
i
]]
=
sum
;
}
/*
...
...
@@ -118,7 +117,7 @@ public:
{
bool
init
=
false
;
bool
first_call
=
true
;
Varray
<
double
>
eig
_val
;
Varray
<
double
>
eig
enValues
;
Varray2D
<
double
>
covar
;
Varray2D
<
double
>
data
;
};
...
...
@@ -126,7 +125,7 @@ public:
size_t
numMissVals
=
0
;
int
varID
,
levelID
;
int
nts
=
1
;
int
grid
_s
pace
=
0
,
time
_s
pace
=
0
;
int
grid
S
pace
=
0
,
time
S
pace
=
0
;
double
sum_w
=
1.0
;
CdoStreamID
streamID1
;
...
...
@@ -143,20 +142,20 @@ public:
int
calendar
=
CALENDAR_STANDARD
;
T_WEIGHT_MODE
weight
_m
ode
;
T_EIGEN_MODE
eigen
_m
ode
;
T_WEIGHT_MODE
weight
M
ode
;
T_EIGEN_MODE
eigen
M
ode
;
size_t
num
_e
igen
_f
unctions
=
0
;
size_t
num
E
igen
F
unctions
=
0
;
int
numVars
;
int
n
_eig
;
int
n
umEigen
;
int
ngrids
;
size_t
npack
=
SIZE_MAX
;
VarList
varList1
;
std
::
vector
<
size_t
>
pack
;
Varray
<
double
>
in
;
std
::
vector
<
std
::
vector
<
eofdata_t
>>
eof
d
ata
;
std
::
vector
<
std
::
vector
<
eofdata_t
>>
eof
D
ata
2D
;
Varray
<
double
>
weights
;
...
...
@@ -168,10 +167,10 @@ public:
auto
operfunc
=
cdo_operator_f1
(
operatorID
);
operator_input_arg
(
"Number of eigen functions to write out"
);
n
_eig
=
parameter_to_int
(
cdo_operator_argv
(
0
));
n
umEigen
=
parameter_to_int
(
cdo_operator_argv
(
0
));
eigen
_m
ode
=
get_eigenmode
();
weight
_m
ode
=
get_weightmode
();
eigen
M
ode
=
get_eigenmode
();
weight
M
ode
=
get_weightmode
();
streamID1
=
cdo_open_read
(
0
);
vlistID1
=
cdo_stream_inq_vlist
(
streamID1
);
...
...
@@ -214,61 +213,61 @@ public:
if
((
size_t
)
nts
<
gridsizemax
||
operfunc
==
EOF_TIME
)
{
time
_s
pace
=
1
;
grid
_s
pace
=
0
;
time
S
pace
=
1
;
grid
S
pace
=
0
;
}
else
{
time
_s
pace
=
0
;
grid
_s
pace
=
1
;
time
S
pace
=
0
;
grid
S
pace
=
1
;
}
}
else
if
(
operfunc
==
EOF_SPATIAL
)
{
time
_s
pace
=
0
;
grid
_s
pace
=
1
;
time
S
pace
=
0
;
grid
S
pace
=
1
;
}
// reset the requested number of eigen-function to the maximum if neccessary
if
(
time
_s
pace
)
if
(
time
S
pace
)
{
if
(
n
_eig
>
nts
)
if
(
n
umEigen
>
nts
)
{
cdo_warning
(
"Solving in time-space:"
);
cdo_warning
(
"Number of eigen-functions to write out is bigger than number of time-steps."
);
cdo_warning
(
"Setting n
_eig
to %d."
,
nts
);
cdo_warning
(
"Setting n
umEigen
to %d."
,
nts
);
cdo_warning
(
"If You want to force a solution in grid-space use operator eofspatial"
);
n
_eig
=
nts
;
n
umEigen
=
nts
;
}
num
_e
igen
_f
unctions
=
nts
;
num
E
igen
F
unctions
=
nts
;
}
else
if
(
grid
_s
pace
)
else
if
(
grid
S
pace
)
{
if
(((
double
)
gridsizemax
)
*
gridsizemax
>
(
double
)
SIZE_MAX
)
cdo_abort
(
"Grid space too large!"
);
if
((
size_t
)
n
_eig
>
gridsizemax
)
if
((
size_t
)
n
umEigen
>
gridsizemax
)
{
cdo_warning
(
"Solving in spatial space"
);
cdo_warning
(
"Number of eigen-functions to write out is bigger than grid size"
);
cdo_warning
(
"Setting n
_eig
to %zu"
,
gridsizemax
);
cdo_warning
(
"Setting n
umEigen
to %zu"
,
gridsizemax
);
cdo_warning
(
"If You want to force a solution in time-space use operator eoftime"
);
n
_eig
=
gridsizemax
;
n
umEigen
=
gridsizemax
;
}
num
_e
igen
_f
unctions
=
gridsizemax
;
num
E
igen
F
unctions
=
gridsizemax
;
}
if
(
Options
::
cdoVerbose
)
cdo_print
(
"Calculating %d eigenvectors and %zu eigenvalues in %s"
,
n
_eig
,
num
_e
igen
_f
unctions
,
(
grid
_s
pace
==
1
)
?
"grid_space"
:
"time_space"
);
cdo_print
(
"Calculating %d eigenvectors and %zu eigenvalues in %s"
,
n
umEigen
,
num
E
igen
F
unctions
,
(
grid
S
pace
==
1
)
?
"grid_space"
:
"time_space"
);
weights
=
Varray
<
double
>
(
gridsizemax
,
1.0
);
if
(
weight
_m
ode
==
WEIGHT_ON
)
if
(
weight
M
ode
==
WEIGHT_ON
)
{
auto
wstatus
=
gridcell_weights
(
gridID1
,
weights
);
if
(
wstatus
!=
0
)
{
weight
_m
ode
=
WEIGHT_OFF
;
weight
M
ode
=
WEIGHT_OFF
;
cdo_warning
(
"Using constant grid cell area weights!"
);
}
}
...
...
@@ -277,15 +276,15 @@ public:
pack
=
std
::
vector
<
size_t
>
(
gridsizemax
);
in
=
Varray
<
double
>
(
gridsizemax
);
eof
d
ata
=
std
::
vector
<
std
::
vector
<
eofdata_t
>>
(
numVars
);
eof
D
ata
2D
.
resize
(
numVars
);
for
(
varID
=
0
;
varID
<
numVars
;
++
varID
)
{
auto
nlevs
=
varList1
.
vars
[
varID
].
nlevels
;
eof
d
ata
[
varID
].
resize
(
nlevs
);
eof
D
ata
2D
[
varID
].
resize
(
nlevs
);
if
(
time
_s
pace
)
for
(
levelID
=
0
;
levelID
<
nlevs
;
++
levelID
)
eof
d
ata
[
varID
][
levelID
].
data
.
resize
(
nts
);
if
(
time
S
pace
)
for
(
levelID
=
0
;
levelID
<
nlevs
;
++
levelID
)
eof
D
ata
2D
[
varID
][
levelID
].
data
.
resize
(
nts
);
}
if
(
Options
::
cdoVerbose
)
cdo_print
(
"Allocated eigenvalue/eigenvector structures with nts=%d gridsize=%zu"
,
nts
,
gridsizemax
);
...
...
@@ -322,7 +321,7 @@ public:
}
}
if
(
weight
_m
ode
==
WEIGHT_ON
)
if
(
weight
M
ode
==
WEIGHT_ON
)
{
sum_w
=
0.0
;
for
(
size_t
i
=
0
;
i
<
npack
;
++
i
)
sum_w
+=
weights
[
pack
[
i
]];
...
...
@@ -342,15 +341,16 @@ public:
if
(
ipack
!=
npack
)
cdo_abort
(
"Missing values unsupported!"
);
}
if
(
grid_space
)
auto
&
eofData
=
eofData2D
[
varID
][
levelID
];
if
(
gridSpace
)
{
if
(
!
eof
d
ata
[
varID
][
levelID
]
.
init
)
if
(
!
eof
D
ata
.
init
)
{
eof
d
ata
[
varID
][
levelID
]
.
covar
.
resize
(
npack
);
for
(
size_t
i
=
0
;
i
<
npack
;
++
i
)
eof
d
ata
[
varID
][
levelID
]
.
covar
[
i
].
resize
(
npack
,
0.0
);
eof
D
ata
.
covar
.
resize
(
npack
);
for
(
size_t
i
=
0
;
i
<
npack
;
++
i
)
eof
D
ata
.
covar
[
i
].
resize
(
npack
,
0.0
);
}
auto
&
covar
=
eof
d
ata
[
varID
][
levelID
]
.
covar
;
auto
&
covar
=
eof
D
ata
.
covar
;
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(npack, covar, in, pack)
#endif
...
...
@@ -361,21 +361,21 @@ public:
for
(
size_t
jpack
=
ipack
;
jpack
<
npack
;
++
jpack
)
covar_i
[
jpack
]
+=
in_i
*
in
[
pack
[
jpack
]];
}
}
else
if
(
time
_s
pace
)
else
if
(
time
S
pace
)
{
eof
d
ata
[
varID
][
levelID
]
.
data
[
tsID
].
resize
(
npack
);
auto
&
data
=
eof
d
ata
[
varID
][
levelID
]
.
data
[
tsID
];
eof
D
ata
.
data
[
tsID
].
resize
(
npack
);
auto
&
data
=
eof
D
ata
.
data
[
tsID
];
for
(
size_t
ipack
=
0
;
ipack
<
npack
;
ipack
++
)
data
[
ipack
]
=
in
[
pack
[
ipack
]];
}
eof
d
ata
[
varID
][
levelID
]
.
init
=
true
;
eof
D
ata
.
init
=
true
;
}
tsID
++
;
}
if
(
grid
_s
pace
)
nts
=
tsID
;
if
(
grid
S
pace
)
nts
=
tsID
;
if
(
tsID
==
1
)
cdo_abort
(
"File consists of only one timestep!"
);
...
...
@@ -427,7 +427,7 @@ public:
taxisDefVdatetime
(
taxisID2
,
vDateTime
);
cdo_def_timestep
(
streamID2
,
tsID
);
if
(
tsID
<
n
_eig
)
if
(
tsID
<
n
umEigen
)
{
taxisDefVdatetime
(
taxisID3
,
vDateTime
);
cdo_def_timestep
(
streamID3
,
tsID
);
...
...
@@ -443,21 +443,22 @@ public:
for
(
levelID
=
0
;
levelID
<
nlevs
;
++
levelID
)
{
const
auto
&
data
=
eofdata
[
varID
][
levelID
].
data
;
auto
&
covar
=
eofdata
[
varID
][
levelID
].
covar
;
auto
&
eofData
=
eofData2D
[
varID
][
levelID
];
const
auto
&
data
=
eofData
.
data
;
auto
&
covar
=
eofData
.
covar
;
if
(
eof
d
ata
[
varID
][
levelID
]
.
first_call
)
if
(
eof
D
ata
.
first_call
)
{
eof
d
ata
[
varID
][
levelID
]
.
first_call
=
false
;
eof
D
ata
.
first_call
=
false
;
if
(
Options
::
cdoVerbose
)
cdo_print
(
"Calculating covar matrices for %d levels of var%i (%s)"
,
nlevs
,
varID
+
1
,
vname
);
if
(
Options
::
cdoVerbose
)
cdo_print
(
"processing level %d"
,
levelID
+
1
);
if
(
grid
_s
pace
)
if
(
grid
S
pace
)
{
if
(
npack
)
eof
d
ata
[
varID
][
levelID
].
eig_val
.
resize
(
npack
);
if
(
npack
)
eof
D
ata
.
eigenValues
.
resize
(
npack
);
for
(
size_t
ipack
=
0
;
ipack
<
npack
;
++
ipack
)
{
...
...
@@ -475,14 +476,14 @@ public:
}
}
}
else
if
(
time
_s
pace
)
else
if
(
time
S
pace
)
{
if
(
Options
::
cdoVerbose
)
cdo_print
(
"allocating covar with %dx%d elements | npack=%zu"
,
nts
,
nts
,
npack
);
covar
.
resize
(
nts
);
for
(
int
i
=
0
;
i
<
nts
;
++
i
)
covar
[
i
].
resize
(
nts
);
eof
d
ata
[
varID
][
levelID
].
eig_val
.
resize
(
nts
);
eof
D
ata
.
eigenValues
.
resize
(
nts
);
#ifdef _OPENMP
#pragma omp parallel for default(none) shared(nts, data, covar, weights, npack, pack, sum_w) schedule(static)
...
...
@@ -503,12 +504,12 @@ public:
}
// Solve the eigen problem
auto
&
eig
_val
=
eof
d
ata
[
varID
][
levelID
].
eig_val
;
if
(
eigen
_m
ode
==
JACOBI
)
auto
&
eig
enValues
=
eof
D
ata
.
eigenValues
;
if
(
eigen
M
ode
==
JACOBI
)
// TODO: use return status (>0 okay, -1 did not converge at all)
parallel_eigen_solution_of_symmetric_matrix
(
covar
,
eig
_val
,
num
_e
igen
_f
unctions
,
__func__
);
parallel_eigen_solution_of_symmetric_matrix
(
covar
,
eig
enValues
,
num
E
igen
F
unctions
,
__func__
);
else
eigen_solution_of_symmetric_matrix
(
covar
,
eig
_val
,
num
_e
igen
_f
unctions
,
__func__
);
eigen_solution_of_symmetric_matrix
(
covar
,
eig
enValues
,
num
E
igen
F
unctions
,
__func__
);
// NOW: covar contains the eigenvectors, eig_val the eigenvalues
...
...
@@ -517,24 +518,24 @@ public:
// for ( int i = 0; i < n; i++ ) eig_val[i] *= sum_w;
}
// first_call
if
(
tsID
<
n
_eig
)
if
(
tsID
<
n
umEigen
)
{
if
(
grid
_s
pace
)
if
(
grid
S
pace
)
scale_eigvec_grid
(
out
,
tsID
,
npack
,
pack
,
weights
,
covar
,
sum_w
);
else
if
(
time
_s
pace
)
else
if
(
time
S
pace
)
scale_eigvec_time
(
out
,
tsID
,
nts
,
npack
,
pack
,
weights
,
covar
,
data
,
missval
,
sum_w
);
numMissVals
=
varray_num_mv
(
gridsize
,
out
,
missval
);
cdo_def_field
(
streamID3
,
varID
,
levelID
);
cdo_write_field
(
streamID3
,
out
.
data
(),
numMissVals
);
}
// loop n
_eig
}
// loop n
umEigen
auto
eig
_val
=
eof
d
ata
[
varID
][
levelID
].
eig_val
.
data
();
auto
eig
enValues
=
eof
D
ata
.
eigenValues
.
data
();
numMissVals
=
(
fp_is_equal
(
eig
_val
[
tsID
],
missval
))
?
1
:
0
;
numMissVals
=
(
fp_is_equal
(
eig
enValues
[
tsID
],
missval
))
?
1
:
0
;
cdo_def_field
(
streamID2
,
varID
,
levelID
);
cdo_write_field
(
streamID2
,
&
eig
_val
[
tsID
],
numMissVals
);
cdo_write_field
(
streamID2
,
&
eig
enValues
[
tsID
],
numMissVals
);
}
// loop nlevs
}
// loop nvars
}
...
...
This diff is collapsed.
Click to expand it.
src/eof_mode.cc
+
1
−
2
View file @
044c386b
...
...
@@ -34,8 +34,7 @@ get_eigenmode(void)
if
(
omp_get_max_threads
()
>
1
&&
eigen_mode
==
DANIELSON_LANCZOS
)
{
cdo_warning
(
"Requested parallel computation with %i Threads "
,
omp_get_max_threads
());
cdo_warning
(
" but environmental setting CDO_SVD_MODE causes sequential "
);
cdo_warning
(
" Singular value decomposition"
);
cdo_warning
(
" but environmental setting CDO_SVD_MODE causes sequential Singular value decomposition"
);
}
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment