Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
f0b3cb18
Commit
f0b3cb18
authored
Aug 02, 2011
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added getNumberOfCPUs() function
parent
6be846aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
core.hpp
modules/core/include/opencv2/core/core.hpp
+3
-0
system.cpp
modules/core/src/system.cpp
+42
-0
No files found.
modules/core/include/opencv2/core/core.hpp
View file @
f0b3cb18
...
...
@@ -263,6 +263,9 @@ CV_EXPORTS_W int64 getCPUTickCount();
*/
CV_EXPORTS_W
bool
checkHardwareSupport
(
int
feature
);
//! returns the number of CPUs (including hyper-threading)
CV_EXPORTS_W
int
getNumberOfCPUs
();
/*!
Allocates memory buffer
...
...
modules/core/src/system.cpp
View file @
f0b3cb18
...
...
@@ -85,6 +85,13 @@
#include <stdarg.h>
#if defined __linux__ || defined __APPLE__
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
namespace
cv
{
...
...
@@ -365,6 +372,41 @@ int getThreadNum(void)
#endif
}
int
getNumberOfCPUs
(
void
)
{
#if defined WIN32 || defined _WIN32
SYSTEM_INFO
sysinfo
;
GetSystemInfo
(
&
sysinfo
);
return
(
int
)
sysinfo
.
dwNumberOfProcessors
;
#elif defined __linux__
return
(
int
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
#elif defined __APPLE__
int
numCPU
=
0
;
int
mib
[
4
];
size_t
len
=
sizeof
(
numCPU
);
/* set the mib for hw.ncpu */
mib
[
0
]
=
CTL_HW
;
mib
[
1
]
=
HW_AVAILCPU
;
// alternatively, try HW_NCPU;
/* get the number of CPUs from the system */
sysctl
(
mib
,
2
,
&
numCPU
,
&
len
,
NULL
,
0
);
if
(
numCPU
<
1
)
{
mib
[
1
]
=
HW_NCPU
;
sysctl
(
mib
,
2
,
&
numCPU
,
&
len
,
NULL
,
0
);
if
(
numCPU
<
1
)
numCPU
=
1
;
}
return
(
int
)
numCPU
;
#else
return
1
;
#endif
}
string
format
(
const
char
*
fmt
,
...
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment