Skip to content

Commit 1ccd57c

Browse files
committed
Merge pull request #497 from eschnett/develop
Introduce openblas_get_num_threads and openblas_get_num_procs
2 parents 07ff001 + 65a847c commit 1ccd57c

7 files changed

Lines changed: 111 additions & 2 deletions

File tree

cblas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ extern "C" {
1313
void openblas_set_num_threads(int num_threads);
1414
void goto_set_num_threads(int num_threads);
1515

16+
/*Get the number of threads on runtime.*/
17+
int openblas_get_num_threads(void);
18+
19+
/*Get the number of physical processors (cores).*/
20+
int openblas_get_num_procs(void);
21+
1622
/*Get the build configure on runtime.*/
1723
char* openblas_get_config(void);
1824

cblas_noconst.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ extern "C" {
1313
void openblas_set_num_threads(int num_threads);
1414
void goto_set_num_threads(int num_threads);
1515

16+
/*Get the number of threads on runtime.*/
17+
int openblas_get_num_threads(void);
18+
19+
/*Get the number of physical processors (cores).*/
20+
int openblas_get_num_procs(void);
21+
1622
/*Get the build configure on runtime.*/
1723
char* openblas_get_config(void);
1824

driver/others/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
TOPDIR = ../..
22
include ../../Makefile.system
33

4-
COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) openblas_error_handle.$(SUFFIX)
4+
COMMONOBJS = memory.$(SUFFIX) xerbla.$(SUFFIX) c_abs.$(SUFFIX) z_abs.$(SUFFIX) openblas_set_num_threads.$(SUFFIX) openblas_get_num_threads.$(SUFFIX) openblas_get_num_procs.$(SUFFIX) openblas_get_config.$(SUFFIX) openblas_get_parallel.$(SUFFIX) openblas_error_handle.$(SUFFIX)
55

66
#COMMONOBJS += slamch.$(SUFFIX) slamc3.$(SUFFIX) dlamch.$(SUFFIX) dlamc3.$(SUFFIX)
77

@@ -103,6 +103,12 @@ blas_server.$(SUFFIX) : $(BLAS_SERVER) ../../common.h ../../common_thread.h ../.
103103
openblas_set_num_threads.$(SUFFIX) : openblas_set_num_threads.c
104104
$(CC) $(CFLAGS) -c $< -o $(@F)
105105

106+
openblas_get_num_threads.$(SUFFIX) : openblas_get_num_threads.c
107+
$(CC) $(CFLAGS) -c $< -o $(@F)
108+
109+
openblas_get_num_procs.$(SUFFIX) : openblas_get_num_procs.c
110+
$(CC) $(CFLAGS) -c $< -o $(@F)
111+
106112
openblas_get_config.$(SUFFIX) : openblas_get_config.c
107113
$(CC) $(CFLAGS) -c $< -o $(@F)
108114

driver/others/memory.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ void set_stack_limit(int limitMB){
241241
*/
242242
#endif
243243

244+
int openblas_get_num_procs(void) {
245+
return get_num_procs();
246+
}
247+
244248
/*
245249
OpenBLAS uses the numbers of CPU cores in multithreading.
246250
It can be set by openblas_set_num_threads(int num_threads);
@@ -323,6 +327,10 @@ int blas_get_cpu_number(void){
323327
}
324328
#endif
325329

330+
int openblas_get_num_threads(void) {
331+
return blas_get_cpu_number();
332+
}
333+
326334
struct release_t {
327335
void *address;
328336
void (*func)(struct release_t *);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2014, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
**********************************************************************************/
33+
34+
#include "common.h"
35+
36+
extern int openblas_get_num_procs(void);
37+
38+
int openblas_get_num_procs_(void) {
39+
return openblas_get_num_procs();
40+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*****************************************************************************
2+
Copyright (c) 2011-2014, The OpenBLAS Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
3. Neither the name of the OpenBLAS project nor the names of
17+
its contributors may be used to endorse or promote products
18+
derived from this software without specific prior written
19+
permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
**********************************************************************************/
33+
34+
#include "common.h"
35+
36+
extern int openblas_get_num_threads(void);
37+
38+
int openblas_get_num_threads_(void) {
39+
return openblas_get_num_threads();
40+
}

exports/gensymbol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181

8282
#both underscore and no underscore
8383
@misc_common_objs = (
84-
openblas_set_num_threads, openblas_get_parallel,
84+
openblas_get_parallel,
85+
openblas_get_num_procs,
86+
openblas_set_num_threads,
87+
openblas_get_num_threads,
8588
);
8689

8790
@misc_no_underscore_objs = (

0 commit comments

Comments
 (0)