Skip to content

Commit 5c7807d

Browse files
committed
Do not use all cores by default in potential modules. Some tests are failing.
Integrate the ideas of #8319
1 parent 9173ce2 commit 5c7807d

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

doc/rst/source/explain_core.rst_

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**-x**\ [[-]\ *n*] :ref:`(more ...) <core_full>`
2-
Limit number of cores used in multi-threaded algorithms (OpenMP required for most of modules,
3-
or Glib for grdfilter, gmt|grdgravmag3d).
2+
Limit number of cores used in multi-threaded algorithms. Multi-threaded behavior is enabled by default.
3+
That covers the modules that implement the OpenMP API (required at compiling stage) and GThreads (Glib)
4+
for the grdfilter module.

src/gmt_init.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,8 +2607,8 @@ GMT_LOCAL int gmtinit_parse_U_option (struct GMT_CTRL *GMT, char *item) {
26072607
}
26082608

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

26292629
/*! . */
26302630
GMT_LOCAL int gmtinit_parse_colon_option (struct GMT_CTRL *GMT, char *item) {
@@ -9151,9 +9151,12 @@ int gmt_default_error (struct GMT_CTRL *GMT, char option) {
91519151
case 's': error += GMT->common.s.active == false; break;
91529152
case 't': error += GMT->common.t.active == false; break;
91539153
case 'w': error += GMT->common.w.active == false; break;
9154-
#if defined(GMT_MP_ENABLED)
9155-
case 'x': error += GMT->common.x.active == false; break;
9154+
case 'x': error += GMT->common.x.active == false;
9155+
#if !defined(GMT_MP_ENABLED)
9156+
error --;
9157+
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Option -x: GMT is not compiled with parallel support. Only one core is used\n");
91569158
#endif
9159+
break;
91579160
case ':': error += GMT->common.colon.active == false; break;
91589161

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

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

1880218806
case ':':
1880318807
error += (gmt_M_more_than_once (GMT, GMT->common.colon.active) || gmtinit_parse_colon_option (GMT, item));

src/grdfilter.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -896,9 +896,9 @@ static int parse (struct GMT_CTRL *GMT, struct GRDFILTER_CTRL *Ctrl, struct GMT_
896896
#ifdef HAVE_GLIB_GTHREAD
897897
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
898898
if (Ctrl->F.custom && GMT->common.x.n_threads > 1) {
899-
//GMT->common.x.n_threads = 1;
900-
//GMT->common.x.active = false;
901-
//GMT_Report (GMT->parent, GMT_MSG_WARNING, "Sorry, custom filtering does not support multiple threads. Reset to 1.\n" );
899+
GMT->common.x.n_threads = 1;
900+
GMT->common.x.active = false;
901+
GMT_Report (GMT->parent, GMT_MSG_WARNING, "Sorry, custom filtering does not support multiple threads. Reset to 1.\n" );
902902
}
903903
if (!GMT->common.x.active) {
904904
GMT->common.x.n_threads = API->n_cores;

src/potential/gmtgravmag3d.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,6 @@ static int parse(struct GMT_CTRL *GMT, struct GMTGRAVMAG3D_CTRL *Ctrl, struct GM
453453
}
454454
}
455455

456-
#ifdef HAVE_GLIB_GTHREAD
457-
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
458-
if (!GMT->common.x.active) GMT->common.x.n_threads = API->n_cores;
459-
#endif
460-
461456
n_errors += gmt_M_check_condition(GMT, Ctrl->S.active && (Ctrl->S.radius <= 0.0 || gmt_M_is_dnan (Ctrl->S.radius)),
462457
"Option -S: Radius is NaN or negative\n");
463458
n_errors += gmt_M_check_condition(GMT, !Ctrl->T.active && !Ctrl->M.active, "Options -T or -M are mandatory\n");

src/potential/grdgravmag3d.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,6 @@ static int parse(struct GMT_CTRL *GMT, struct GRDGRAVMAG3D_CTRL *Ctrl, struct GM
448448
}
449449
}
450450

451-
#ifdef HAVE_GLIB_GTHREAD
452-
/* Make the default equal to the OMP case where we use all threads if not stated otherwise. */
453-
if (!GMT->common.x.active) GMT->common.x.n_threads = API->n_cores;
454-
#endif
455-
456451
n_errors += gmt_M_check_condition(GMT, !Ctrl->In.file[0], "Must specify input file\n");
457452
n_errors += gmt_M_check_condition(GMT, Ctrl->S.active && (Ctrl->S.radius <= 0.0 || gmt_M_is_dnan(Ctrl->S.radius)),
458453
"Option -S: Radius is NaN or negative\n");

0 commit comments

Comments
 (0)