Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
System.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/basic.h>
36
37#if defined(OGDF_SYSTEM_OSX)
38# include <stdlib.h>
39#elif defined(OGDF_SYSTEM_UNIX) || defined(__MINGW32__)
40# include <malloc.h>
41#endif
42
43// detect processor architecture we're compiling for
44//
45// OGDF_ARCH_X86 Intel / AMD x86 32-bit processors
46// OGDF_ARCH_X64 Intel / AMD x86 64-bit processors
47// OGDF_ARCH_IA64 Intel Itanium
48// OGDF_ARCH_PPC PowerPC
49// OGDF_ARCH_SPARC SUN SPARC
50// OGDF_ARCH_SPARC_V9 SUN SPARC V9
51
52#if defined(_M_X64) || defined(__x86_64__)
53# define OGDF_ARCH_X64
54#elif defined(_M_IX86) || defined(__i386__)
55# define OGDF_ARCH_X86
56#elif defined(_M_IA64) || defined(__ia64__)
57# define OGDF_ARCH_IA64
58#elif defined(_M_MPPC) || defined(_M_PPC) || defined(__powerpc__)
59# define OGDF_ARCH_PPC
60#elif defined(__sparc__)
61# define OGDF_ARCH_SPARC
62#elif defined(__sparc_v9__)
63# define OGDF_ARCH_SPARC_V9
64#endif
65
66namespace ogdf {
67
69
76enum class CPUFeature {
77 MMX,
78 SSE,
79 SSE2,
80 SSE3,
81 SSSE3,
82 SSE4_1,
83 SSE4_2,
84 VMX,
85 SMX,
86 EST,
87 MONITOR
88};
89
91
94enum class CPUFeatureMask : unsigned int {
95 MMX = 1 << static_cast<int>(CPUFeature::MMX),
96 SSE = 1 << static_cast<int>(CPUFeature::SSE),
97 SSE2 = 1 << static_cast<int>(CPUFeature::SSE2),
98 SSE3 = 1 << static_cast<int>(CPUFeature::SSE3),
99 SSSE3 = 1 << static_cast<int>(CPUFeature::SSSE3),
100 SSE4_1 = 1 << static_cast<int>(CPUFeature::SSE4_1),
101 SSE4_2 = 1 << static_cast<int>(CPUFeature::SSE4_2),
102 VMX = 1 << static_cast<int>(CPUFeature::VMX),
103 SMX = 1 << static_cast<int>(CPUFeature::SMX),
104 EST = 1 << static_cast<int>(CPUFeature::EST),
105 MONITOR = 1 << static_cast<int>(CPUFeature::MONITOR)
106};
107
108OGDF_EXPORT unsigned int operator|=(unsigned int& i, CPUFeatureMask fm);
109
111
122public:
128
129 static void* alignedMemoryAlloc16(size_t size) {
130#ifdef OGDF_SYSTEM_WINDOWS
131# ifdef __MINGW64__
132 return __mingw_aligned_malloc(size, 16);
133# else
134 return _aligned_malloc(size, 16);
135# endif
136#elif defined(OGDF_SYSTEM_OSX)
137 // malloc returns 16 byte aligned memory on OS X.
138 return malloc(size);
139#else
140 return memalign(16, size);
141#endif
142 }
143
144 static void alignedMemoryFree(void* p) {
145#ifdef OGDF_SYSTEM_WINDOWS
146# ifdef __MINGW64__
148# else
149 _aligned_free(p);
150# endif
151#else
152 free(p);
153#endif
154 }
155
157 static int pageSize() { return s_pageSize; }
158
160 static long long physicalMemory();
161
163 static long long availablePhysicalMemory();
164
166 static size_t memoryUsedByProcess();
167
168#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
170 static size_t peakMemoryUsedByProcess();
171#endif
172
174
185
188
191
193
197 static size_t memoryAllocatedByMalloc();
198
200
205
206#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
208
215
218
220 static double elapsedSeconds(const int64_t& startCounter, const int64_t& endCounter);
221#endif
222
224
231
233
238
239
241
245
247 static int getProcessID();
248
250
257
259 static int cpuFeatures() { return s_cpuFeatures; }
260
263 return (s_cpuFeatures & (1 << static_cast<int>(feature))) != 0;
264 }
265
267 static int cacheSizeKBytes() { return s_cacheSize; }
268
270 static int cacheLineBytes() { return s_cacheLine; }
271
273 static int numberOfProcessors() { return s_numberOfProcessors; }
274
276
277private:
278 static unsigned int s_cpuFeatures;
279 static int s_cacheSize;
280 static int s_cacheLine;
282 static int s_pageSize;
283
284#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
286#endif
287
288public:
290 static void init();
291};
292
293}
Basic declarations, included by all source files.
System specific functionality.
Definition System.h:121
static size_t memoryInGlobalFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the global free list of OGDF's memory manager.
static int getProcessID()
Returns the process ID of the current process.
static size_t memoryAllocatedByMalloc()
Returns the amount of memory (in bytes) allocated on the heap (e.g., with malloc).
static size_t peakMemoryUsedByProcess()
Returns the maximal amount of memory (in bytes) used by the process (Windows/Cygwin only).
static size_t memoryUsedByProcess()
Returns the amount of memory (in bytes) allocated by the process.
static void alignedMemoryFree(void *p)
Definition System.h:144
static int s_cacheLine
Bytes in a cache line.
Definition System.h:280
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition System.h:273
static size_t memoryInThreadFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the thread's free list of OGDF's memory manager.
static void init()
Static initilization routine (automatically called).
static int s_numberOfProcessors
Number of processors (cores) available.
Definition System.h:281
static int cpuFeatures()
Returns the bit vector describing the CPU features supported on current system.
Definition System.h:259
static void getHPCounter(int64_t &counter)
Returns the current value of the high-performance counter in counter.
static unsigned int s_cpuFeatures
Supported CPU features.
Definition System.h:278
static int s_pageSize
The page size of virtual memory.
Definition System.h:282
static int64_t usedRealTime(int64_t &t)
Returns the elapsed time (in milliseconds) between t and now.
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition System.h:270
static size_t memoryAllocatedByMemoryManager()
Returns the amount of memory (in bytes) allocated by OGDF's memory manager.
static int64_t realTime()
Returns the current time point of the real time wall clock.
static size_t memoryInFreelistOfMalloc()
Returns the amount of memory (in bytes) contained in free chunks on the heap.
static int64_t s_HPCounterFrequency
Frequency of high-performance counter.
Definition System.h:285
static long long availablePhysicalMemory()
Returns the size of available (free) physical memory (in bytes).
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition System.h:262
static long long physicalMemory()
Returns the total size of physical memory (in bytes).
static void * alignedMemoryAlloc16(size_t size)
Definition System.h:129
static int pageSize()
Returns the page size of virtual memory (in bytes).
Definition System.h:157
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition System.h:267
static double elapsedSeconds(const int64_t &startCounter, const int64_t &endCounter)
Returns the elapsed time (in seconds) between startCounter and endCounter.
static int s_cacheSize
Cache size in KBytes.
Definition System.h:279
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
CPUFeatureMask
Bit mask for CPU features.
Definition System.h:94
CPUFeature
Special features supported by a x86/x64 CPU.
Definition System.h:76
@ SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3)
@ EST
Enhanced Intel SpeedStep Technology.
@ SSE4_2
Streaming SIMD Extensions 4.2 (SSE4.2)
@ MMX
Intel MMX Technology.
@ SSE
Streaming SIMD Extensions (SSE)
@ SSE4_1
Streaming SIMD Extensions 4.1 (SSE4.1)
@ VMX
Virtual Machine Extensions.
@ SSE3
Streaming SIMD Extensions 3 (SSE3)
@ SMX
Safer Mode Extensions.
@ SSE2
Streaming SIMD Extensions 2 (SSE2)
@ MONITOR
Processor supports MONITOR/MWAIT instructions.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
unsigned int operator|=(unsigned int &i, CPUFeatureMask fm)