Skip to content

Commit 128418f

Browse files
committedFeb 24, 2011
Fixed #10. Supported GOTO_NUM_THREADS & GOTO_THREADS_TIMEOUT environment variables.
1 parent cd2cbab commit 128418f

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed
 

‎Makefile.rule

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ VERSION = 0.1
7070
# time out to improve performance. This number should be from 4 to 30
7171
# which corresponds to (1 << n) cycles. For example, if you set to 26,
7272
# thread will be running for (1 << 26) cycles(about 25ms on 3.0GHz
73-
# system). Also you can control this mumber by GOTO_THREAD_TIMEOUT
73+
# system). Also you can control this mumber by THREAD_TIMEOUT
7474
# CCOMMON_OPT += -DTHREAD_TIMEOUT=26
7575

7676
# Using special device driver for mapping physically contigous memory

‎README

+10-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ MIPS64:
3232
4.Usages
3333
Link with libopenblas.a or -lopenblas for shared library.
3434

35-
Set the number of threads. for example,
35+
4.1 Set the number of threads with environment variables. for example,
3636
export OPENBLAS_NUM_THREADS=4
37+
or
38+
export GOTO_NUM_THREADS=4
3739
or
3840
export OMP_NUM_THREADS=4
39-
OPENBLAS_NUM_THREAD is prior to OMP_NUM_THREADS.
41+
42+
The priorities are OPENBLAS_NUM_THREAD > GOTO_NUM_THREADS > OMP_NUM_THREADS.
43+
44+
4.2 Set the number of threads with calling functions. for example,
45+
void goto_set_num_threads(int num_threads);
46+
or
47+
void openblas_set_num_threads(int num_threads);
4048

4149
5.Report Bugs
4250
Please add a issue in https://github.com/xianyi/OpenBLAS/issues

‎driver/others/blas_server.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,16 @@ int blas_thread_init(void){
525525
if (thread_timeout < 4) thread_timeout = 4;
526526
if (thread_timeout > 30) thread_timeout = 30;
527527
thread_timeout = (1 << thread_timeout);
528-
}
528+
}else{
529+
p = getenv("GOTO_THREAD_TIMEOUT");
530+
if (p) {
531+
thread_timeout = atoi(p);
532+
if (thread_timeout < 4) thread_timeout = 4;
533+
if (thread_timeout > 30) thread_timeout = 30;
534+
thread_timeout = (1 << thread_timeout);
535+
}
536+
}
537+
529538

530539
for(i = 0; i < blas_num_threads - 1; i++){
531540

@@ -790,6 +799,11 @@ void goto_set_num_threads(int num_threads) {
790799

791800
}
792801

802+
void openblas_set_num_threads(int num_threads) {
803+
goto_set_num_threads(num_threads);
804+
805+
}
806+
793807
/* Compatible function with pthread_create / join */
794808

795809
int gotoblas_pthread(int numthreads, void *function, void *args, int stride) {

‎driver/others/init.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ void gotoblas_affinity_init(void) {
581581
numprocs = 0;
582582
#else
583583
numprocs = readenv("OPENBLAS_NUM_THREADS");
584+
if (numprocs == 0) numprocs = readenv("GOTO_NUM_THREADS");
584585
#endif
585586

586587
if (numprocs == 0) numprocs = readenv("OMP_NUM_THREADS");
@@ -666,7 +667,7 @@ void gotoblas_affinity_init(void) {
666667

667668
setup_mempolicy();
668669

669-
if (readenv("OPENBLAS_MAIN_FREE")) {
670+
if (readenv("OPENBLAS_MAIN_FREE") || readenv("GOTOBLAS_MAIN_FREE")) {
670671
sched_setaffinity(0, sizeof(cpu_orig_mask), &cpu_orig_mask[0]);
671672
}
672673

‎driver/others/memory.c

+7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ int blas_get_cpu_number(void){
231231
p = getenv("OPENBLAS_NUM_THREADS");
232232
if (p) blas_goto_num = atoi(p);
233233
if (blas_goto_num < 0) blas_goto_num = 0;
234+
235+
if (blas_goto_num == 0) {
236+
p = getenv("GOTO_NUM_THREADS");
237+
if (p) blas_goto_num = atoi(p);
238+
if (blas_goto_num < 0) blas_goto_num = 0;
239+
}
240+
234241
#endif
235242

236243
blas_omp_num = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.