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

Default to 1 interactive thread #57087

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 10 additions & 10 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
break;
case 't': // threads
errno = 0;
jl_options.nthreadpools = 1;
long nthreads = -1, nthreadsi = 0;
jl_options.nthreadpools = 2;
// By default, main threads = -1 (== "auto"), interactive = 1
long nthreads = -1, nthreadsi = 1;
Comment on lines +627 to +628
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
// By default, main threads = -1 (== "auto"), interactive = 1
long nthreads = -1, nthreadsi = 1;
// By default:
// default threads = -1 (== "auto")
long nthreads = -1;
// interactive threads = 1, or 0 if generating output
long nthreadsi jl_generating_output() ? 0 : 1;


if (!strncmp(optarg, "auto", 4)) {
jl_options.nthreads = -1;
if (optarg[4] == ',') {
Expand All @@ -633,10 +635,9 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
else {
errno = 0;
nthreadsi = strtol(&optarg[5], &endptr, 10);
if (errno != 0 || endptr == &optarg[5] || *endptr != 0 || nthreadsi < 1 || nthreadsi >= INT16_MAX)
jl_errorf("julia: -t,--threads=auto,<m>; m must be an integer >= 1");
if (errno != 0 || endptr == &optarg[5] || *endptr != 0 || nthreadsi < 0 || nthreadsi >= INT16_MAX)
jl_errorf("julia: -t,--threads=auto,<m>; m must be an integer >= 0");
}
jl_options.nthreadpools++;
}
}
else {
Expand All @@ -650,17 +651,16 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
errno = 0;
char *endptri;
nthreadsi = strtol(&endptr[1], &endptri, 10);
if (errno != 0 || endptri == &endptr[1] || *endptri != 0 || nthreadsi < 1 || nthreadsi >= INT16_MAX)
jl_errorf("julia: -t,--threads=<n>,<m>; n and m must be integers >= 1");
// Allow 0 for interactive
if (errno != 0 || endptri == &endptr[1] || *endptri != 0 || nthreadsi < 0 || nthreadsi >= INT16_MAX)
jl_errorf("julia: -t,--threads=<n>,<m>; m must be an integer ≥ 0");
}
jl_options.nthreadpools++;
}
jl_options.nthreads = nthreads + nthreadsi;
}
int16_t *ntpp = (int16_t *)malloc_s(jl_options.nthreadpools * sizeof(int16_t));
ntpp[0] = (int16_t)nthreads;
if (jl_options.nthreadpools == 2)
ntpp[1] = (int16_t)nthreadsi;
ntpp[1] = (int16_t)nthreadsi;
jl_options.nthreads_per_pool = ntpp;
break;
case 'p': // procs
Expand Down
3 changes: 2 additions & 1 deletion src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,8 @@ void jl_init_threading(void)
// and `jl_n_threads_per_pool`.
jl_n_threadpools = 2;
int16_t nthreads = JULIA_NUM_THREADS;
int16_t nthreadsi = 0;
// if generating output default to 0 interactive threads, otherwise default to 1
int16_t nthreadsi = jl_generating_output() ? 0 : 1;
char *endptr, *endptri;

if (jl_options.nthreads != 0) { // --threads specified
Expand Down
Loading