Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1926 gridstat openmp #1977

Merged
merged 30 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ed6934b
Feature 1926. Introduce OpenMP in GridStat.
mo-mglover Oct 18, 2021
86c1a50
Feature 1926. Add MET_OPENMP flag to automake setup.
mo-mglover Nov 4, 2021
b3a063a
Feature 1926. Indentation tweaks.
mo-mglover Nov 4, 2021
e0257c6
Feature 1926. Revert temporary C++17 temporary file code tweak.
mo-mglover Nov 5, 2021
7d81d41
Feature 1926. Add _OPENMP ifdef for omp.h.
mo-mglover Nov 18, 2021
3ff12fe
Feature 1926. Revert tweak to CXX optimisation level with MET_DEVELOP…
mo-mglover Nov 22, 2021
9a045e0
Per #1926, switch the OpenMP configuration option from being like MET…
JohnHalleyGotway Nov 22, 2021
4c176c4
Per #1926, just like --enable-grib2 and --enable-python, add a test p…
JohnHalleyGotway Nov 22, 2021
7043995
Feature #1926: Ensure OpenMP flag is passed to the linker. Revert to …
mo-mglover Nov 26, 2021
81c98b9
Feature #1926. Write thread count via logging, not cout.
mo-mglover Nov 30, 2021
1abb2be
Feature #1926: Add note about --enable-openmp in installation.rst
mo-mglover Nov 30, 2021
d6969c6
Per #1926, adding a call to Grid-Stat to run on 2 threads. This shoul…
JohnHalleyGotway Dec 2, 2021
2b37a69
Per #1926, updating GridStatConfig_rtma to switch width = 1 to 3. Thi…
JohnHalleyGotway Dec 2, 2021
4b2982f
Per #1926, tweak the openmp log message slightly.
JohnHalleyGotway Dec 3, 2021
3c1a5db
Per #1926, switch from manual --enable-openmp support in autoconf to …
JohnHalleyGotway Dec 3, 2021
b595de4
Per #1926, after switching to the AC_OPENMP() macro, these changes to…
JohnHalleyGotway Dec 3, 2021
359d823
Merge branch 'develop' into feature_1926_gridstat_openmp
JohnHalleyGotway Dec 3, 2021
ecaa653
Per #1926, since openmp support will now be compiled by default, swit…
JohnHalleyGotway Dec 3, 2021
9594505
Feature #1926. Use `default(none)` to force explicit `private` or `s…
mo-mglover Dec 6, 2021
e8d928b
Feature #1926: Default to single thread if OMP_NUM_THREADS is left un…
mo-mglover Dec 6, 2021
dd35aa4
Feature #1926: Add OpenMP initialisation to other tools calling fract…
mo-mglover Dec 6, 2021
e0d7840
Update met/src/basic/vx_util/handle_openmp.cc
mo-mglover Dec 16, 2021
78e4354
Update met/src/basic/vx_util/Makefile.am
mo-mglover Dec 16, 2021
b2a6c1e
Feature #1926: Lengthen OMP_NUM_THREADS debug message, plus user guid…
mo-mglover Dec 16, 2021
f39313d
Set up the Runtime Environment Variables Section and started adding i…
Dec 17, 2021
63b1fce
Updated documenation and fixed typos
Dec 21, 2021
3e89e56
removed openmp.rst in favor of having the information contained in a …
Dec 22, 2021
83688f5
Fixed typo
Dec 22, 2021
d73d537
Merge branch 'develop' into feature_1926_gridstat_openmp
JohnHalleyGotway Jan 12, 2022
821ca68
Merge branch 'develop' into feature_1926_gridstat_openmp
JohnHalleyGotway Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions met/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ AC_SUBST([PYTHON_LIBS])
# Check for the MET_DEVELOPMENT environment variable

AM_CONDITIONAL([ENABLE_DEVELOPMENT], [test -n "$MET_DEVELOPMENT"])
AM_CONDITIONAL([ENABLE_OPENMP], [test -n "$MET_OPENMP"])

# Add MET_BASE to the CPPFLAGS

Expand All @@ -1067,9 +1068,17 @@ AC_SUBST(FC_LIBS, [-lgfortran])
# For Intel compilers, "-g" slows down runtimes considerably (MET #1778).
# For development, retain the "-g" option. Otherwise, discard it.

AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CFLAGS="-g -O2"}], [: ${CFLAGS="-O2"}])
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CXXFLAGS="-g"} ], [: ${CXXFLAGS=""}] )
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${FFLAGS="-g -O2"}], [: ${FFLAGS="-O2"}])
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CFLAGS_OPT="-g -O2"}], [: ${CFLAGS_OPT="-O2"}])
AM_COND_IF([ENABLE_DEVELOPMENT], [: ${CXXFLAGS_OPT="-g"} ], [: ${CXXFLAGS_OPT="-O3"}] )
Copy link
Collaborator

@JohnHalleyGotway JohnHalleyGotway Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional... changing ${CXXFLAGS=""} to ${CXXFLAGS_OPT="-03"}?
I believe that when in "development" mode, we want to disable optimization for easier debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot! No, it wasn't intentional. Will put that right and push up the correction.

AM_COND_IF([ENABLE_DEVELOPMENT], [: ${FFLAGS_OPT="-g -O2"}], [: ${FFLAGS_OPT="-O2"}])

AM_COND_IF([ENABLE_OPENMP], [: ${CFLAGS_OMP="-fopenmp"}], [: ${CFLAGS_OMP=""}])
AM_COND_IF([ENABLE_OPENMP], [: ${CXXFLAGS_OMP="-fopenmp"}], [: ${CXXFLAGS_OMP=""}])
AM_COND_IF([ENABLE_OPENMP], [: ${FFLAGS_OMP="-fopenmp"}], [: ${FFLAGS_OMP=""}])

CFLAGS="$CFLAGS_OPT $CFLAGS_OMP"
CXXFLAGS="$CXXFLAGS_OPT $CXXFLAGS_OMP"
FFLAGS="$FFLAGS_OPT $FFLAGS_OMP"

# Checks for programs.

Expand Down
165 changes: 88 additions & 77 deletions met/src/basic/vx_util/data_plane_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using namespace std;
#include <string.h>
#include <unistd.h>

#include "omp.h"

#include "data_plane_util.h"
#include "interp_util.h"
#include "two_to_one.h"
Expand Down Expand Up @@ -247,83 +249,92 @@ void fractional_coverage(const DataPlane &dp, DataPlane &frac_dp,
}
}

// Build the grid template
GridTemplateFactory gtf;
GridTemplate* gt = gtf.buildGT(shape, width, wrap_lon);

mlog << Debug(3)
<< "Computing fractional coverage field using the "
<< t.get_str() << " threshold and the "
<< interpmthd_to_string(InterpMthd_Nbrhd) << "(" << gt->size()
<< ") " << gt->getClassName() << " interpolation method.\n";

// Initialize the fractional coverage field
frac_dp = dp;
frac_dp.set_constant(bad_data_double);

// Compute the fractional coverage meeting the threshold criteria
for(x=0; x<dp.nx(); x++) {
for(y=0; y<dp.ny(); y++) {

// For a new column, reset the grid template and counts.
if(y == 0) {

// Initialize counts
n_vld = n_thr = 0;

// Sum all the points
for(gp = gt->getFirstInGrid(x, y, dp.nx(), dp.ny());
gp != NULL;
gp = gt->getNextInGrid()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld++;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr++;
}
}
// Subtract off the bottom edge, shift up, and add the top.
else {

// Subtract points from the the bottom edge
for(gp = gt->getFirstInBotEdge();
gp != NULL;
gp = gt->getNextInBotEdge()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld--;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr--;
}

// Increment Y
gt->incBaseY(1);

// Add points from the the top edge
for(gp = gt->getFirstInTopEdge();
gp != NULL;
gp = gt->getNextInTopEdge()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld++;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr++;
}
}

// Check for enough valid data and compute fractional coverage
if((double)(n_vld)/gt->size() >= vld_t && n_vld != 0) {
frac_dp.set((double) n_thr/n_vld, x, y);
}

} // end for y

// Increment X
if(x < (dp.nx() - 1)) gt->incBaseX(1);

} // end for x

delete gt;
#pragma omp parallel default(shared) private(x,y,n_vld,n_thr,gp,v)
{

// Build the grid template
GridTemplateFactory gtf;
GridTemplate* gt = gtf.buildGT(shape, width, wrap_lon);

#pragma omp single
{
mlog << Debug(3)
<< "Computing fractional coverage field using the "
<< t.get_str() << " threshold and the "
<< interpmthd_to_string(InterpMthd_Nbrhd) << "(" << gt->size()
<< ") " << gt->getClassName() << " interpolation method.\n";

// Initialize the fractional coverage field
frac_dp = dp;
frac_dp.set_constant(bad_data_double);
}

// Compute the fractional coverage meeting the threshold criteria
#pragma omp for schedule (static)
for(x=0; x<dp.nx(); x++) {
for(y=0; y<dp.ny(); y++) {

// For a new column, reset the grid template and counts.
if(y == 0) {

// Initialize counts
n_vld = n_thr = 0;

// Sum all the points
for(gp = gt->getFirstInGrid(x, y, dp.nx(), dp.ny());
gp != NULL;
gp = gt->getNextInGrid()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld++;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr++;
}
}
// Subtract off the bottom edge, shift up, and add the top.
else {

// Subtract points from the the bottom edge
for(gp = gt->getFirstInBotEdge();
gp != NULL;
gp = gt->getNextInBotEdge()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld--;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr--;
}

// Increment Y
gt->incBaseY(1);

// Add points from the the top edge
for(gp = gt->getFirstInTopEdge();
gp != NULL;
gp = gt->getNextInTopEdge()) {
if(is_bad_data(v = dp.get(gp->x, gp->y))) continue;
n_vld++;
if(t.check(v,
(use_climo ? cmn->get(gp->x, gp->y) : bad),
(use_climo ? csd->get(gp->x, gp->y) : bad))) n_thr++;
}
}

// Check for enough valid data and compute fractional coverage
if((double)(n_vld)/gt->size() >= vld_t && n_vld != 0) {
frac_dp.set((double) n_thr/n_vld, x, y);
}

} // end for y

// Increment X
if(x < (dp.nx() - 1)) gt->incBaseX(1);

} // end for x

delete gt;

} // End of omp parallel

return;
}
Expand Down
11 changes: 11 additions & 0 deletions met/src/tools/core/grid_stat/grid_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ using namespace std;
#include <sys/types.h>
#include <unistd.h>

#include "omp.h"

#include "grid_stat.h"

#include "vx_statistics.h"
Expand Down Expand Up @@ -185,6 +187,15 @@ static bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf,

int main(int argc, char *argv[]) {

#ifdef _OPENMP
#pragma omp parallel
#pragma omp single
{
// Report number of threads if compiled with OpenMP
std::cout << "Running on " << omp_get_num_threads() << " threads.\n";
mo-mglover marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

// Set handler to be called for memory allocation error
set_new_handler(oom);

Expand Down