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

Use all cores by default in grdfilter #8523

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Do not use all cores by default in potential modules. Some tests are …
…failing.

Integrate the ideas of #8319
  • Loading branch information
joa-quim committed Jun 18, 2024
commit 5c7807db08cf3172b34a949cf30342f71ae309ae
5 changes: 3 additions & 2 deletions doc/rst/source/explain_core.rst_
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**-x**\ [[-]\ *n*] :ref:`(more ...) <core_full>`
Limit number of cores used in multi-threaded algorithms (OpenMP required for most of modules,
or Glib for grdfilter, gmt|grdgravmag3d).
Limit number of cores used in multi-threaded algorithms. Multi-threaded behavior is enabled by default.
That covers the modules that implement the OpenMP API (required at compiling stage) and GThreads (Glib)
for the grdfilter module.
16 changes: 10 additions & 6 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2607,8 +2607,8 @@ GMT_LOCAL int gmtinit_parse_U_option (struct GMT_CTRL *GMT, char *item) {
}

/*! -x[[-]<ncores>] */
GMT_LOCAL int gmtinit_parse_x_option (struct GMT_CTRL *GMT, char *arg) { /* Only effective if MP is enabled */
#ifdef GMT_MP_ENABLED
GMT_LOCAL int gmtinit_parse_x_option (struct GMT_CTRL *GMT, char *arg) {
GMT->common.x.active = true;
if (!arg) return (GMT_PARSE_ERROR); /* -x requires a non-NULL argument */
if (arg[0] == '\0') /* Use all processors */
Expand All @@ -2622,9 +2622,9 @@ GMT_LOCAL int gmtinit_parse_x_option (struct GMT_CTRL *GMT, char *arg) {
GMT->common.x.n_threads = MAX(gmtlib_get_num_processors() - abs (GMT->common.x.n_threads), 1); /* Max-n but at least one */
if (GMT->current.setting.max_cores) /* Limit to max core defaults setting */
GMT->common.x.n_threads = GMT->current.setting.max_cores;
#endif
return (GMT_NOERROR);
}
#endif

/*! . */
GMT_LOCAL int gmtinit_parse_colon_option (struct GMT_CTRL *GMT, char *item) {
Expand Down Expand Up @@ -9151,9 +9151,12 @@ int gmt_default_error (struct GMT_CTRL *GMT, char option) {
case 's': error += GMT->common.s.active == false; break;
case 't': error += GMT->common.t.active == false; break;
case 'w': error += GMT->common.w.active == false; break;
#if defined(GMT_MP_ENABLED)
case 'x': error += GMT->common.x.active == false; break;
case 'x': error += GMT->common.x.active == false;
#if !defined(GMT_MP_ENABLED)
error --;
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Option -x: GMT is not compiled with parallel support. Only one core is used\n");
#endif
break;
case ':': error += GMT->common.colon.active == false; break;

default:
Expand Down Expand Up @@ -18792,12 +18795,13 @@ int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, cha
error += gmt_M_more_than_once (GMT, GMT->common.w.active) || gmtinit_parse_w_option (GMT, item);
break;

#ifdef GMT_MP_ENABLED
case 'x':
error += (gmt_M_more_than_once (GMT, GMT->common.x.active) || gmtinit_parse_x_option (GMT, item));
GMT->common.x.active = true;
break;
#if !defined(GMT_MP_ENABLED)
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Option -x: GMT is not compiled with parallel support. Only one core is used\n");
#endif
break;

case ':':
error += (gmt_M_more_than_once (GMT, GMT->common.colon.active) || gmtinit_parse_colon_option (GMT, item));
Expand Down
6 changes: 3 additions & 3 deletions src/grdfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,9 @@ static int parse (struct GMT_CTRL *GMT, struct GRDFILTER_CTRL *Ctrl, struct GMT_
#ifdef HAVE_GLIB_GTHREAD
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
if (Ctrl->F.custom && GMT->common.x.n_threads > 1) {
//GMT->common.x.n_threads = 1;
//GMT->common.x.active = false;
//GMT_Report (GMT->parent, GMT_MSG_WARNING, "Sorry, custom filtering does not support multiple threads. Reset to 1.\n" );
GMT->common.x.n_threads = 1;
GMT->common.x.active = false;
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Sorry, custom filtering does not support multiple threads. Reset to 1.\n" );
}
if (!GMT->common.x.active) {
GMT->common.x.n_threads = API->n_cores;
Expand Down
5 changes: 0 additions & 5 deletions src/potential/gmtgravmag3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,6 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
}
}

#ifdef HAVE_GLIB_GTHREAD
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
if (!GMT->common.x.active) GMT->common.x.n_threads = API->n_cores;
#endif

n_errors += gmt_M_check_condition(GMT, Ctrl->S.active && (Ctrl->S.radius <= 0.0 || gmt_M_is_dnan (Ctrl->S.radius)),
"Option -S: Radius is NaN or negative\n");
n_errors += gmt_M_check_condition(GMT, !Ctrl->T.active && !Ctrl->M.active, "Options -T or -M are mandatory\n");
Expand Down
5 changes: 0 additions & 5 deletions src/potential/grdgravmag3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,6 @@ static int parse(struct GMT_CTRL *GMT, struct GRDGRAVMAG3D_CTRL *Ctrl, struct GM
}
}

#ifdef HAVE_GLIB_GTHREAD
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
if (!GMT->common.x.active) GMT->common.x.n_threads = API->n_cores;
#endif

n_errors += gmt_M_check_condition(GMT, !Ctrl->In.file[0], "Must specify input file\n");
n_errors += gmt_M_check_condition(GMT, Ctrl->S.active && (Ctrl->S.radius <= 0.0 || gmt_M_is_dnan(Ctrl->S.radius)),
"Option -S: Radius is NaN or negative\n");
Expand Down
Loading