22 bool g_initialized =
false;
23 bool g_openmp_enabled =
false;
32 std::cerr <<
"Warning: ZLayout already initialized" << std::endl;
38 g_openmp_enabled =
false;
42 int num_threads = omp_get_max_threads();
43 std::cout <<
"ZLayout: OpenMP enabled with " << num_threads <<
" threads" << std::endl;
44 g_openmp_enabled =
true;
46 std::cout <<
"ZLayout: OpenMP not available in this build" << std::endl;
51 std::cout <<
"ZLayout v" <<
get_version() <<
" initialized successfully" << std::endl;
52 std::cout <<
"Features enabled:" << std::endl;
54 std::cout <<
" - Quadtree spatial indexing" << std::endl;
55 std::cout <<
" - Sharp angle detection" << std::endl;
56 std::cout <<
" - Edge intersection detection" << std::endl;
57 std::cout <<
" - Narrow distance analysis" << std::endl;
59 if (g_openmp_enabled) {
60 std::cout <<
" - OpenMP parallel processing" << std::endl;
66 }
catch (
const std::exception& e) {
67 std::cerr <<
"Error initializing ZLayout: " << e.what() << std::endl;
78 g_initialized =
false;
79 g_openmp_enabled =
false;
81 std::cout <<
"ZLayout cleanup completed" << std::endl;
89 return g_openmp_enabled;
95 std::chrono::high_resolution_clock::time_point
start_time;
98 start_time = std::chrono::high_resolution_clock::now();
102 auto end_time = std::chrono::high_resolution_clock::now();
103 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time -
start_time);
104 return duration.count() / 1000.0;
108 auto end_time = std::chrono::high_resolution_clock::now();
109 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end_time -
start_time);
110 return static_cast<double>(duration.count());
126 std::string int_to_string(
int value) {
127#if defined(_MSC_VER) && _MSC_VER < 1800
129 sprintf(buffer,
"%d", value);
130 return std::string(buffer);
132 return std::to_string(value);
142 info.
compiler =
"GCC " + int_to_string(__GNUC__) +
"." + int_to_string(__GNUC_MINOR__);
143#elif defined(__clang__)
144 info.
compiler =
"Clang " + int_to_string(__clang_major__) +
"." + int_to_string(__clang_minor__);
145#elif defined(_MSC_VER)
146 info.
compiler =
"MSVC " + int_to_string(_MSC_VER);
161#elif defined(__linux__)
163#elif defined(__APPLE__)
184 std::cout <<
"\n=== ZLayout System Information ===" << std::endl;
185 std::cout <<
"Version: " <<
get_version() << std::endl;
186 std::cout <<
"Compiler: " << info.compiler << std::endl;
187 std::cout <<
"Build Type: " << info.build_type << std::endl;
188 std::cout <<
"Platform: " << info.platform << std::endl;
189 std::cout <<
"OpenMP Support: " << (info.openmp_support ?
"Yes" :
"No") << std::endl;
190 std::cout <<
"Max Threads: " << info.max_threads << std::endl;
192 std::cout <<
"=================================" << std::endl;
200 : std::runtime_error(
"ZLayout Error: " + message) {}
204 if (!g_initialized) {
205 throw ZLayoutException(
"Library not initialized. Call zlayout::initialize() first.");
223void* tracked_malloc(
size_t size) {
224 void* ptr = std::malloc(size);
226 g_memory_info.allocated_bytes += size;
227 g_memory_info.peak_bytes = std::max(g_memory_info.peak_bytes, g_memory_info.allocated_bytes);
228 g_memory_info.allocation_count++;
233void tracked_free(
void* ptr,
size_t size) {
236 g_memory_info.allocated_bytes -= size;
241 return g_memory_info;
ZLayoutException(const std::string &message)
static constexpr double TOLERANCE
Default precision tolerance for floating point comparisons.
Main namespace for ZLayout library.
bool initialize(bool enable_openmp=true)
Initialize ZLayout library.
void cleanup()
Cleanup ZLayout library resources.
void assert_initialized()
const char * get_version()
Get library version string.
SystemInfo get_system_info()
MemoryInfo get_memory_info()
static constexpr const char * STRING
ZLayout - Advanced Electronic Design Automation Layout Library.