This repository has been archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
utilities.cpp
executable file
·85 lines (65 loc) · 2 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*============================================================================
OpenEXR for Matlab
Distributed under the MIT License (the "License");
see accompanying file LICENSE for details
or copy at http://opensource.org/licenses/MIT
Originated from HDRITools - High Dynamic Range Image Tools
Copyright 2011 Program of Computer Graphics, Cornell University
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
-----------------------------------------------------------------------------
Authors:
Jinwei Gu <jwgu AT cs DOT cornell DOT edu>
Edgar Velazquez-Armendariz <eva5 AT cs DOT cornell DOT edu>
Manuel Leonhardt <leom AT hs-furtwangen DOT de>
============================================================================*/
#if defined(_WIN32)
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#elif USE_SYSCONF
#include <unistd.h>
#endif
#include <mex.h>
#include <ImfThreading.h>
#include "utilities.h"
namespace
{
// Actual function to get the number of CPUs
inline int get_num_cpus()
{
#if defined(_WIN32)
SYSTEM_INFO info;
GetSystemInfo(&info);
const int n = (int)info.dwNumberOfProcessors;
return n > 0 ? n : 1;
#elif USE_SYSCONF
const int n = sysconf(_SC_NPROCESSORS_ONLN);
return n > 0 ? n : 1;
#else
// Nothing better
return 1;
#endif
}
} // namespace
int OpenEXRforMatlab::getNumCPUs()
{
static int numCPUs = get_num_cpus();
return numCPUs;
}
// Exit callback
extern "C" void mexEXRExitCallback(void)
{
OPENEXR_IMF_INTERNAL_NAMESPACE::setGlobalThreadCount(0);
}
void OpenEXRforMatlab::mexEXRInit()
{
static bool initialized = false;
if (!initialized) {
// Use up to 75% of CPUs to avoid oversubscription
const int numCPUs = (3*getNumCPUs() + 3) / 4;
OPENEXR_IMF_INTERNAL_NAMESPACE::setGlobalThreadCount(numCPUs);
mexAtExit(mexEXRExitCallback);
initialized = true;
}
}