Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Special Functionality

Check build mode

This example shows how to check the build mode of the ogdf and user programs.

int main() {
#ifdef OGDF_DEBUG
bool debugMode = true;
#else
bool debugMode = false;
#endif
std::cout << "This user program is compiled in " << (debugMode ? "Debug" : "Release") << " mode." << std::endl;
std::cout << "The OGDF is compiled in " << (ogdf::debugMode ? "Debug" : "Release") << " mode." << std::endl;
std::cout << "Check your configuration!" << std::endl;
return 1;
}
std::cout << "Everything is fine!" << std::endl;
return 0;
}

As hinted at in this example the internal differentiation between Debug and Release build mode in the OGDF is handled via the preprocessor macro OGDF_DEBUG. Also, any compiled instance of the ogdf will expose the build mode it was compiled in via the flag ogdf::debugMode. This allows users to make sure the build configuration of their user code matches that of the ogdf library.

Displaying information about the system

This example shows how to query information about the system.

using namespace ogdf;
const char *yn(bool b)
{
return b ? "yes" : "no";
}
int main()
{
std::cout
<< "---------------------------------------" << std::endl
<< " System-specific information " << std::endl
<< "---------------------------------------" << std::endl
<< std::endl
<< "Cache / processors:" << std::endl
<< "-------------------" << std::endl
<< "Processors: " << System::numberOfProcessors() << std::endl
<< "L2-Cache: " << System::cacheSizeKBytes() << " KBytes" << std::endl
<< "Cache-Line: " << System::cacheLineBytes() << " Bytes" << std::endl
<< std::endl
<< "Supported technologies:" << std::endl
<< "-----------------------" << std::endl
<< "MMX: " << yn(System::cpuSupports(CPUFeature::MMX)) << std::endl
<< "SSE: " << yn(System::cpuSupports(CPUFeature::SSE)) << std::endl
<< "SSE2: " << yn(System::cpuSupports(CPUFeature::SSE2)) << std::endl
<< "SSE3: " << yn(System::cpuSupports(CPUFeature::SSE3)) << std::endl
<< "SSSE3: " << yn(System::cpuSupports(CPUFeature::SSSE3)) << std::endl
<< "SSE4.1: " << yn(System::cpuSupports(CPUFeature::SSE4_1)) << std::endl
<< "SSE4.2: " << yn(System::cpuSupports(CPUFeature::SSE4_2)) << std::endl
<< "VMX: " << yn(System::cpuSupports(CPUFeature::VMX)) << std::endl
<< "SMX: " << yn(System::cpuSupports(CPUFeature::SMX)) << std::endl
<< "EST: " << yn(System::cpuSupports(CPUFeature::EST)) << std::endl
<< std::endl
<< "Memory management:" << std::endl
<< "------------------" << std::endl
<< "Total physical memory: " << System::physicalMemory() / 1024 / 1024 << " MBytes" << std::endl
<< " available: " << System::availablePhysicalMemory() / 1024 / 1024 << " MBytes" << std::endl
<< " used by process: " << System::memoryUsedByProcess() / 1024 << " KBytes" << std::endl
#if defined(OGDF_SYSTEM_WINDOWS) || defined(__CYGWIN__)
<< " peak amount: " << System::peakMemoryUsedByProcess() / 1024 << " KBytes" << std::endl
#endif
<< std::endl
<< "allocated by malloc: " << System::memoryAllocatedByMalloc() / 1024 << " KBytes" << std::endl
<< " in freelist: " << System::memoryInFreelistOfMalloc() / 1024 << " KBytes" << std::endl
<< std::endl
<< "allocated by OGDF: " << System::memoryAllocatedByMemoryManager() / 1024 << " KBytes" << std::endl
<< " in global freelist: " << System::memoryInGlobalFreeListOfMemoryManager() / 1024 << " KBytes" << std::endl
<< " in thread freelist: " << System::memoryInThreadFreeListOfMemoryManager() / 1024 << " KBytes" << std::endl;
return 0;
}

The ogdf::System interface enables you to query information about the system at runtime, including CPU thread count, cache sizes and supported technologies as well as some basic statistics about memory usage on the system. While most of this should probably not concern the average user, it might still be useful to know for more experienced users that by default the ogdf comes with and uses its own memory manager ogdf::PoolMemoryAllocator which will allocate memory in chunks for better runtime at the cost of some (minor) memory overhead. To compile with standard free/malloc memory management using ogdf::MallocMemoryAllocator you can define the preprocessor macro OGDF_MEMORY_MALLOC_TS via cmake. Note also that all ogdf algorithms will run sequentially unless multithreading is explicitly requested.

ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::System::physicalMemory
static long long physicalMemory()
Returns the total size of physical memory (in bytes).
System.h
Decalration of System class which provides unified access to system information.
ogdf::System::peakMemoryUsedByProcess
static size_t peakMemoryUsedByProcess()
Returns the maximal amount of memory (in bytes) used by the process (Windows/Cygwin only).
ogdf::CPUFeature::SSSE3
@ SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3)
ogdf::CPUFeature::EST
@ EST
Enhanced Intel SpeedStep Technology.
ogdf::CPUFeature::SSE4_2
@ SSE4_2
Streaming SIMD Extensions 4.2 (SSE4.2)
ogdf::CPUFeature::SMX
@ SMX
Safer Mode Extensions.
ogdf::System::memoryUsedByProcess
static size_t memoryUsedByProcess()
Returns the amount of memory (in bytes) allocated by the process.
ogdf::CPUFeature::VMX
@ VMX
Virtual Machine Extensions.
ogdf::debugMode
bool debugMode
Set to true iff debug mode is used during compilation of the OGDF.
ogdf::System::memoryInGlobalFreeListOfMemoryManager
static size_t memoryInGlobalFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the global free list of OGDF's memory manager.
ogdf::CPUFeature::SSE4_1
@ SSE4_1
Streaming SIMD Extensions 4.1 (SSE4.1)
ogdf::CPUFeature::SSE3
@ SSE3
Streaming SIMD Extensions 3 (SSE3)
yn
const char * yn(bool b)
Definition: system-info.cpp:6
ogdf::System::cacheSizeKBytes
static int cacheSizeKBytes()
Returns the L2-cache size (in KBytes).
Definition: System.h:267
main
int main()
Definition: gen-acyclic-graph.cpp:7
ogdf::CPUFeature::SSE2
@ SSE2
Streaming SIMD Extensions 2 (SSE2)
ogdf::System::memoryAllocatedByMemoryManager
static size_t memoryAllocatedByMemoryManager()
Returns the amount of memory (in bytes) allocated by OGDF's memory manager.
ogdf::System::cacheLineBytes
static int cacheLineBytes()
Returns the number of bytes in a cache line.
Definition: System.h:270
basic.h
Basic declarations, included by all source files.
ogdf::System::memoryInThreadFreeListOfMemoryManager
static size_t memoryInThreadFreeListOfMemoryManager()
Returns the amount of memory (in bytes) contained in the thread's free list of OGDF's memory manager.
ogdf::System::memoryInFreelistOfMalloc
static size_t memoryInFreelistOfMalloc()
Returns the amount of memory (in bytes) contained in free chunks on the heap.
ogdf::CPUFeature::MMX
@ MMX
Intel MMX Technology.
ogdf::System::memoryAllocatedByMalloc
static size_t memoryAllocatedByMalloc()
Returns the amount of memory (in bytes) allocated on the heap (e.g., with malloc).
ogdf::System::cpuSupports
static bool cpuSupports(CPUFeature feature)
Returns true if the CPU supports feature.
Definition: System.h:262
ogdf::CPUFeature::SSE
@ SSE
Streaming SIMD Extensions (SSE)
ogdf::System::availablePhysicalMemory
static long long availablePhysicalMemory()
Returns the size of available (free) physical memory (in bytes).
ogdf::System::numberOfProcessors
static int numberOfProcessors()
Returns the number of processors (cores) available on the current system.
Definition: System.h:273