From 66a0c0a1990e74be3a80bba44c5d877cb7bdacc6 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Thu, 22 Aug 2024 23:19:02 -0400 Subject: [PATCH 01/17] Add PrintSystemInfo functions --- include/HYPREDRV.h | 17 ++++ include/info.h | 1 + src/HYPREDRV.c | 12 +++ src/info.c | 226 +++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 1 + src/matrix.c | 8 +- src/vector.c | 8 +- 7 files changed, 271 insertions(+), 2 deletions(-) diff --git a/include/HYPREDRV.h b/include/HYPREDRV.h index d1712b6..3f30686 100644 --- a/include/HYPREDRV.h +++ b/include/HYPREDRV.h @@ -189,6 +189,23 @@ HYPREDRV_Destroy(HYPREDRV_t*); HYPREDRV_EXPORT_SYMBOL uint32_t HYPREDRV_PrintLibInfo(void); +/** + * @brief Print system information. + * + * Example Usage: + * @code + * uint32_t errorCode = HYPREDRV_PrintSystemInfo(); + * if (errorCode != 0) { + * const char* errorDescription = HYPREDRV_ErrorCodeDescribe(errorCode); + * printf("%s\n", errorDescription); + * // Handle error + * } + * @endcode + */ + +HYPREDRV_EXPORT_SYMBOL uint32_t +HYPREDRV_PrintSystemInfo(void); + /** * @brief Print library information at exit. * diff --git a/include/info.h b/include/info.h index 71f7488..58185d4 100644 --- a/include/info.h +++ b/include/info.h @@ -19,6 +19,7 @@ void PrintUsage(const char*); void PrintLibInfo(void); +void PrintSystemInfo(void); void PrintExitInfo(const char*); #endif /* INFO_HEADER */ diff --git a/src/HYPREDRV.c b/src/HYPREDRV.c index 9b7662b..f3945b5 100644 --- a/src/HYPREDRV.c +++ b/src/HYPREDRV.c @@ -145,6 +145,18 @@ HYPREDRV_PrintLibInfo(void) return ErrorCodeGet(); } +/*----------------------------------------------------------------------------- + * HYPREDRV_PrintSystemInfo + *-----------------------------------------------------------------------------*/ + +uint32_t +HYPREDRV_PrintSystemInfo(void) +{ + PrintSystemInfo(); + + return ErrorCodeGet(); +} + /*----------------------------------------------------------------------------- * HYPREDRV_PrintExitInfo *-----------------------------------------------------------------------------*/ diff --git a/src/info.c b/src/info.c index e6e2ba5..4775b5d 100644 --- a/src/info.c +++ b/src/info.c @@ -5,9 +5,235 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ +#include +#include +#include +#ifdef __APPLE__ +#include +#include +#include +#else +#define __USE_GNU +#include +#include +#endif #include "info.h" #include "HYPRE_config.h" +#ifndef __APPLE__ + +/*-------------------------------------------------------------------------- + * dlpi_callback + * + * Linux: Use dl_iterate_phdr to list dynamic libraries + *--------------------------------------------------------------------------*/ + +int +dlpi_callback(struct dl_phdr_info *info, size_t size, void *data) +{ + if (info->dlpi_name && info->dlpi_name[0]) + { + const char* filename = strrchr(info->dlpi_name, '/'); + filename = filename ? filename + 1 : info->dlpi_name; + printf(" %s => %s (0x%lx)\n", filename, info->dlpi_name, info->dlpi_addr); + } + return 0; +} + +#endif + +/*-------------------------------------------------------------------------- + * PrintSystemInfo + *--------------------------------------------------------------------------*/ + +void +PrintSystemInfo(void) +{ + double bytes_to_GB = (double) (1 << 30); + + printf("================================ System Information ================================\n\n"); + + // 1. CPU cores and model + int numCPU; + char cpuModel[256]; + char gpuInfo[256] = "Unknown"; + +#ifdef __APPLE__ + size_t size = sizeof(numCPU); + sysctlbyname("hw.ncpu", &numCPU, &size, NULL, 0); + + size = sizeof(cpuModel); + sysctlbyname("machdep.cpu.brand_string", &cpuModel, &size, NULL, 0); +#else + numCPU = sysconf(_SC_NPROCESSORS_ONLN); + + char buffer[256]; + FILE* fp = fopen("/proc/cpuinfo", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp)) + { + if (strncmp(buffer, "model name", 10) == 0) + { + char* model = strchr(buffer, ':') + 2; + strncpy(cpuModel, model, sizeof(cpuModel) - 1); + cpuModel[strlen(cpuModel) - 1] = '\0'; // Ensure null-termination + } + } + fclose(fp); + } +#endif + if (strlen(gpuInfo) == 0) + { + strncpy(gpuInfo, "Unknown", sizeof(buffer)); + } + + printf("Number of CPU Cores : %d\n", numCPU); + printf("CPU Model : %s\n", cpuModel); + +#ifndef __APPLE__ + fp = popen("lspci | grep -i 'vga'", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp) != NULL) + { + char *start = strstr(buffer, "VGA compatible controller"); + if (!start) start = strstr(buffer, "3D controller"); + if (!start) start = strstr(buffer, "2D controller"); + + if (start) + { + strncpy(gpuInfo, start + strlen("VGA compatible controller: "), sizeof(buffer) - strlen("VGA compatible controller: ") - 1); + gpuInfo[strlen(gpuInfo) - 1] = '\0'; // Remove newline + printf("GPU Model : %s\n", gpuInfo); + } + else + { + strncpy(gpuInfo, buffer, sizeof(buffer) - 1); + } + } + pclose(fp); + } +#endif + printf("\n"); + + // 2. Memory available and used + printf("Memory Information\n"); + printf("-------------------\n"); +#ifdef __APPLE__ + int64_t memSize; + size_t memSizeLen = sizeof(memSize); + sysctlbyname("hw.memsize", &memSize, &memSizeLen, NULL, 0); + + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_statistics_data_t vmstat; + if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) + { + int64_t freeMemory = (int64_t)vmstat.free_count * sysconf(_SC_PAGESIZE); + int64_t usedMemory = memSize - freeMemory; + + printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); + } +#else + struct sysinfo info; + if (sysinfo(&info) == 0) + { + printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); + } +#endif + + // 3. OS system info, release, version, machine + printf("Operating System\n"); + printf("-----------------\n"); + struct utsname sysinfo; + if (uname(&sysinfo) == 0) + { + printf("System Name : %s\n", sysinfo.sysname); + printf("Node Name : %s\n", sysinfo.nodename); + printf("Release : %s\n", sysinfo.release); + printf("Version : %s\n", sysinfo.version); + printf("Machine Architecture : %s\n\n", sysinfo.machine); + } + + // 4. Compilation Flags Information + printf("Compilation Information\n"); + printf("------------------------\n"); + printf("Date : %s at %s\n", __DATE__, __TIME__); + +#ifdef __OPTIMIZE__ + printf("Optimization : Enabled\n"); +#else + printf("Optimization : Disabled\n"); +#endif +#ifdef DEBUG + printf("Debugging : Enabled\n"); +#else + printf("Debugging : Disabled\n"); +#endif +#ifdef __clang__ + printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); +#elif defined(__GNUC__) + printf("Compiler : GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); +#else + printf("Compiler : Unknown\n"); +#endif +#if defined(_OPENMP) + printf("OpenMP : Supported (Version: %d)\n", _OPENMP); +#endif +#if defined(__x86_64__) + printf("Target architecture : x86_64\n"); +#elif defined(__i386__) + printf("Target architecture : x86 (32-bit)\n"); +#elif defined(__aarch64__) + printf("Target architecture : ARM64\n"); +#elif defined(__arm__) + printf("Target architecture : ARM\n"); +#else + printf("Target architecture : Unknown\n"); +#endif +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + printf("Endianness : Little-endian\n"); +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + printf("Endianness : Big-endian\n"); +#else + printf("Endianness : Unknown\n"); +#endif + printf("\n"); + + // 5. Current working directory + printf("Current Working Directory\n"); + printf("--------------------------\n"); + char cwd[1024]; + if (getcwd(cwd, sizeof(cwd)) != NULL) + { + printf("%s\n\n", cwd); + } + + // 6. Dynamic libraries used + printf("Dynamic Libraries Loaded\n"); + printf("------------------------\n"); +#ifdef __APPLE__ + uint32_t dcount = _dyld_image_count(); + for (uint32_t i = 0; i < dcount; i++) + { + const char* name = _dyld_get_image_name(i); + const struct mach_header* header = _dyld_get_image_header(i); + const char* filename = strrchr(name, '/'); + + filename = filename ? filename + 1 : name; + printf(" %s => %s (0x%lx)\n", filename, name, (unsigned long)header); + } +#else + dl_iterate_phdr(dlpi_callback, NULL); +#endif + + printf("================================ System Information ================================\n\n"); +} + /*-------------------------------------------------------------------------- * PrintLibInfo *--------------------------------------------------------------------------*/ diff --git a/src/main.c b/src/main.c index 2d255e4..4d515dd 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,7 @@ int main(int argc, char **argv) *-----------------------------------------------------------*/ if (!myid) HYPREDRV_PrintLibInfo(); + if (!myid) HYPREDRV_PrintSystemInfo(); if (!myid) printf("Running on %d MPI rank%s\n", nprocs, nprocs > 1 ? "s" : ""); /*----------------------------------------------------------- diff --git a/src/matrix.c b/src/matrix.c index 120c26c..37125e7 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -100,7 +100,13 @@ IJMatrixReadMultipartBinary(const char *prefixname, { sprintf(filename, "%s.%05d.bin", prefixname, partids[part]); fp = fopen(filename, "rb"); - fread(header, sizeof(uint64_t), 11, fp) == 11; + if (fread(header, sizeof(uint64_t), 11, fp) != 11) + { + ErrorCodeSet(ERROR_FILE_UNEXPECTED_ENTRY); + ErrorMsgAdd("Could not read header from %s", filename); + fclose(fp); + return; + } /* Read row and column indices */ if (header[1] == sizeof(HYPRE_BigInt)) diff --git a/src/vector.c b/src/vector.c index b9bea4d..1ff571c 100644 --- a/src/vector.c +++ b/src/vector.c @@ -96,7 +96,13 @@ IJVectorReadMultipartBinary(const char *prefixname, { sprintf(filename, "%s.%05d.bin", prefixname, partids[part]); fp = fopen(filename, "rb"); - fread(header, sizeof(uint64_t), 8, fp) == 8; + if (fread(header, sizeof(uint64_t), 8, fp) != 8) + { + ErrorCodeSet(ERROR_FILE_UNEXPECTED_ENTRY); + ErrorMsgAdd("Could not read header from %s", filename); + fclose(fp); + return; + } /* Read vector coefficients */ if (header[1] == sizeof(HYPRE_Complex)) From f48509797cf956190948a7dd7afe076e74ab6e6e Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 00:01:32 -0400 Subject: [PATCH 02/17] Add number of nodes and update APIs --- include/HYPREDRV.h | 12 +- include/info.h | 7 +- src/HYPREDRV.c | 12 +- src/info.c | 382 +++++++++++++++++++++++++++------------------ src/main.c | 10 +- 5 files changed, 254 insertions(+), 169 deletions(-) diff --git a/include/HYPREDRV.h b/include/HYPREDRV.h index 3f30686..15b1fb4 100644 --- a/include/HYPREDRV.h +++ b/include/HYPREDRV.h @@ -177,7 +177,7 @@ HYPREDRV_Destroy(HYPREDRV_t*); * * Example Usage: * @code - * uint32_t errorCode = HYPREDRV_PrintLibInfo(); + * uint32_t errorCode = HYPREDRV_PrintLibInfo(comm); * if (errorCode != 0) { * const char* errorDescription = HYPREDRV_ErrorCodeDescribe(errorCode); * printf("%s\n", errorDescription); @@ -187,14 +187,14 @@ HYPREDRV_Destroy(HYPREDRV_t*); */ HYPREDRV_EXPORT_SYMBOL uint32_t -HYPREDRV_PrintLibInfo(void); +HYPREDRV_PrintLibInfo(MPI_Comm comm); /** * @brief Print system information. * * Example Usage: * @code - * uint32_t errorCode = HYPREDRV_PrintSystemInfo(); + * uint32_t errorCode = HYPREDRV_PrintSystemInfo(comm); * if (errorCode != 0) { * const char* errorDescription = HYPREDRV_ErrorCodeDescribe(errorCode); * printf("%s\n", errorDescription); @@ -204,7 +204,7 @@ HYPREDRV_PrintLibInfo(void); */ HYPREDRV_EXPORT_SYMBOL uint32_t -HYPREDRV_PrintSystemInfo(void); +HYPREDRV_PrintSystemInfo(MPI_Comm comm); /** * @brief Print library information at exit. @@ -218,7 +218,7 @@ HYPREDRV_PrintSystemInfo(void); * * Example Usage: * @code - * uint32_t errorCode = HYPREDRV_PrintExitInfo(argv[0]); + * uint32_t errorCode = HYPREDRV_PrintExitInfo(comm, argv[0]); * if (errorCode != 0) { * const char* errorDescription = HYPREDRV_ErrorCodeDescribe(errorCode); * printf("%s\n", errorDescription); @@ -228,7 +228,7 @@ HYPREDRV_PrintSystemInfo(void); */ HYPREDRV_EXPORT_SYMBOL uint32_t -HYPREDRV_PrintExitInfo(const char*); +HYPREDRV_PrintExitInfo(MPI_Comm comm, const char*); /** * @brief Parse input arguments for a HYPREDRV object. diff --git a/include/info.h b/include/info.h index 58185d4..dd92667 100644 --- a/include/info.h +++ b/include/info.h @@ -8,6 +8,7 @@ #ifndef INFO_HEADER #define INFO_HEADER +#include #include #include #include "HYPRE.h" @@ -18,8 +19,8 @@ *--------------------------------------------------------------------------*/ void PrintUsage(const char*); -void PrintLibInfo(void); -void PrintSystemInfo(void); -void PrintExitInfo(const char*); +void PrintLibInfo(MPI_Comm); +void PrintSystemInfo(MPI_Comm); +void PrintExitInfo(MPI_Comm, const char*); #endif /* INFO_HEADER */ diff --git a/src/HYPREDRV.c b/src/HYPREDRV.c index 1e45abb..110e289 100644 --- a/src/HYPREDRV.c +++ b/src/HYPREDRV.c @@ -147,9 +147,9 @@ HYPREDRV_Destroy(HYPREDRV_t *obj_ptr) *-----------------------------------------------------------------------------*/ uint32_t -HYPREDRV_PrintLibInfo(void) +HYPREDRV_PrintLibInfo(MPI_Comm comm) { - PrintLibInfo(); + PrintLibInfo(comm); return ErrorCodeGet(); } @@ -159,9 +159,9 @@ HYPREDRV_PrintLibInfo(void) *-----------------------------------------------------------------------------*/ uint32_t -HYPREDRV_PrintSystemInfo(void) +HYPREDRV_PrintSystemInfo(MPI_Comm comm) { - PrintSystemInfo(); + PrintSystemInfo(comm); return ErrorCodeGet(); } @@ -171,9 +171,9 @@ HYPREDRV_PrintSystemInfo(void) *-----------------------------------------------------------------------------*/ uint32_t -HYPREDRV_PrintExitInfo(const char *argv0) +HYPREDRV_PrintExitInfo(MPI_Comm comm, const char *argv0) { - PrintExitInfo(argv0); + PrintExitInfo(comm, argv0); return ErrorCodeGet(); } diff --git a/src/info.c b/src/info.c index 4775b5d..9d64c6d 100644 --- a/src/info.c +++ b/src/info.c @@ -5,6 +5,7 @@ * SPDX-License-Identifier: MIT ******************************************************************************/ +#include #include #include #include @@ -47,191 +48,264 @@ dlpi_callback(struct dl_phdr_info *info, size_t size, void *data) *--------------------------------------------------------------------------*/ void -PrintSystemInfo(void) +PrintSystemInfo(MPI_Comm comm) { - double bytes_to_GB = (double) (1 << 30); + int myid, nprocs; + char hostname[256]; + double bytes_to_GB = (double) (1 << 30); - printf("================================ System Information ================================\n\n"); + MPI_Comm_rank(comm, &myid); + MPI_Comm_size(comm, &nprocs); - // 1. CPU cores and model - int numCPU; - char cpuModel[256]; - char gpuInfo[256] = "Unknown"; + /* Array to gather all hostnames */ + char allHostnames[nprocs * 256]; -#ifdef __APPLE__ - size_t size = sizeof(numCPU); - sysctlbyname("hw.ncpu", &numCPU, &size, NULL, 0); + /* Get the hostname for this process */ + gethostname(hostname, sizeof(hostname)); - size = sizeof(cpuModel); - sysctlbyname("machdep.cpu.brand_string", &cpuModel, &size, NULL, 0); -#else - numCPU = sysconf(_SC_NPROCESSORS_ONLN); + /* Gather all hostnames to all processes */ + MPI_Allgather(hostname, 256, MPI_CHAR, allHostnames, 256, MPI_CHAR, MPI_COMM_WORLD); - char buffer[256]; - FILE* fp = fopen("/proc/cpuinfo", "r"); - if (fp != NULL) + if (!myid) { - while (fgets(buffer, sizeof(buffer), fp)) + printf("================================ System Information ================================\n\n"); + + // 1. CPU cores and model + int numPhysicalCPUs = 0; + int numCPU; + int physicalCPUSeen; + char cpuModels[8][256]; + char gpuInfo[256] = "Unknown"; + + /* Count unique hostnames */ + int numNodes = 0; + for (int i = 0; i < nprocs; i++) { - if (strncmp(buffer, "model name", 10) == 0) + int isUnique = 1; + for (int j = 0; j < i; j++) + { + if (strncmp(&allHostnames[i * 256], &allHostnames[j * 256], 256) == 0) + { + isUnique = 0; + break; + } + } + if (isUnique) { - char* model = strchr(buffer, ':') + 2; - strncpy(cpuModel, model, sizeof(cpuModel) - 1); - cpuModel[strlen(cpuModel) - 1] = '\0'; // Ensure null-termination + numNodes++; } } - fclose(fp); - } -#endif - if (strlen(gpuInfo) == 0) - { - strncpy(gpuInfo, "Unknown", sizeof(buffer)); - } - printf("Number of CPU Cores : %d\n", numCPU); - printf("CPU Model : %s\n", cpuModel); +#ifdef __APPLE__ + size_t size = sizeof(numCPU); + sysctlbyname("hw.ncpu", &numCPU, &size, NULL, 0); -#ifndef __APPLE__ - fp = popen("lspci | grep -i 'vga'", "r"); - if (fp != NULL) - { - while (fgets(buffer, sizeof(buffer), fp) != NULL) - { - char *start = strstr(buffer, "VGA compatible controller"); - if (!start) start = strstr(buffer, "3D controller"); - if (!start) start = strstr(buffer, "2D controller"); + size_t size = sizeof(numPhysicalCPUs); + sysctlbyname("hw.packages", &numPhysicalCPUs, &size, NULL, 0); - if (start) + for (int i = 0; i < numPhysicalCPUs; i++) + { + size = sizeof(cpuModels[i]); + sysctlbyname("machdep.cpu.brand_string", &cpuModels[i], &size, NULL, 0); + } +#else + char buffer[256]; + FILE* fp = fopen("/proc/cpuinfo", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp)) { - strncpy(gpuInfo, start + strlen("VGA compatible controller: "), sizeof(buffer) - strlen("VGA compatible controller: ") - 1); - gpuInfo[strlen(gpuInfo) - 1] = '\0'; // Remove newline - printf("GPU Model : %s\n", gpuInfo); + if (strncmp(buffer, "physical id", 11) == 0) + { + int physicalID = atoi(strchr(buffer, ':') + 2); + if (physicalID >= 0 && physicalID < 8) + { + unsigned long long mask = 1ULL << physicalID; + if (!(physicalCPUSeen & mask)) + { + physicalCPUSeen |= mask; + numPhysicalCPUs++; + } + } + } + + if (strncmp(buffer, "model name", 10) == 0) + { + int physicalID = numPhysicalCPUs - 1; + if (physicalID >= 0 && physicalID < 8) + { + char* model = strchr(buffer, ':') + 2; + strncpy(cpuModels[physicalID], model, + sizeof(cpuModels[physicalID]) - 1); + cpuModels[physicalID][strlen(cpuModels[physicalID]) - 1] = '\0'; + } + } } - else + fclose(fp); + } + + numCPU = sysconf(_SC_NPROCESSORS_ONLN); +#endif + if (strlen(gpuInfo) == 0) + { + strncpy(gpuInfo, "Unknown", sizeof(buffer)); + } + + printf("Processing Units\n"); + printf("-----------------\n"); + printf("Number of Nodes : %d\n", numNodes); + printf("Number of Processors : %d\n", numPhysicalCPUs); + printf("Number of CPU Cores : %d\n", numCPU); + for (int i = 0; i < numPhysicalCPUs; i++) + { + printf("CPU Model #%d : %s\n", i, cpuModels[i]); + } + +#ifndef __APPLE__ + int gcount = 0; + fp = popen("lspci | grep -i 'vga'", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp) != NULL) { - strncpy(gpuInfo, buffer, sizeof(buffer) - 1); + char *start = strstr(buffer, "VGA compatible controller"); + if (!start) start = strstr(buffer, "3D controller"); + if (!start) start = strstr(buffer, "2D controller"); + + if (start) + { + strncpy(gpuInfo, start + strlen("VGA compatible controller: "), sizeof(buffer) - strlen("VGA compatible controller: ") - 1); + gpuInfo[strlen(gpuInfo) - 1] = '\0'; // Remove newline + printf("GPU Model #%d : %s\n", gcount++, gpuInfo); + } + else + { + strncpy(gpuInfo, buffer, sizeof(buffer) - 1); + } } + pclose(fp); } - pclose(fp); - } #endif - printf("\n"); + printf("\n"); - // 2. Memory available and used - printf("Memory Information\n"); - printf("-------------------\n"); + // 2. Memory available and used + printf("Memory Information\n"); + printf("-------------------\n"); #ifdef __APPLE__ - int64_t memSize; - size_t memSizeLen = sizeof(memSize); - sysctlbyname("hw.memsize", &memSize, &memSizeLen, NULL, 0); + int64_t memSize; + size_t memSizeLen = sizeof(memSize); + sysctlbyname("hw.memsize", &memSize, &memSizeLen, NULL, 0); - mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - vm_statistics_data_t vmstat; - if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) - { - int64_t freeMemory = (int64_t)vmstat.free_count * sysconf(_SC_PAGESIZE); - int64_t usedMemory = memSize - freeMemory; + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_statistics_data_t vmstat; + if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) + { + int64_t freeMemory = (int64_t)vmstat.free_count * sysconf(_SC_PAGESIZE); + int64_t usedMemory = memSize - freeMemory; - printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); - } + printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); + } #else - struct sysinfo info; - if (sysinfo(&info) == 0) - { - printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); - } + struct sysinfo info; + if (sysinfo(&info) == 0) + { + printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); + } #endif - // 3. OS system info, release, version, machine - printf("Operating System\n"); - printf("-----------------\n"); - struct utsname sysinfo; - if (uname(&sysinfo) == 0) - { - printf("System Name : %s\n", sysinfo.sysname); - printf("Node Name : %s\n", sysinfo.nodename); - printf("Release : %s\n", sysinfo.release); - printf("Version : %s\n", sysinfo.version); - printf("Machine Architecture : %s\n\n", sysinfo.machine); - } + // 3. OS system info, release, version, machine + printf("Operating System\n"); + printf("-----------------\n"); + struct utsname sysinfo; + if (uname(&sysinfo) == 0) + { + printf("System Name : %s\n", sysinfo.sysname); + printf("Node Name : %s\n", sysinfo.nodename); + printf("Release : %s\n", sysinfo.release); + printf("Version : %s\n", sysinfo.version); + printf("Machine Architecture : %s\n\n", sysinfo.machine); + } - // 4. Compilation Flags Information - printf("Compilation Information\n"); - printf("------------------------\n"); - printf("Date : %s at %s\n", __DATE__, __TIME__); + // 4. Compilation Flags Information + printf("Compilation Information\n"); + printf("------------------------\n"); + printf("Date : %s at %s\n", __DATE__, __TIME__); #ifdef __OPTIMIZE__ - printf("Optimization : Enabled\n"); + printf("Optimization : Enabled\n"); #else - printf("Optimization : Disabled\n"); + printf("Optimization : Disabled\n"); #endif #ifdef DEBUG - printf("Debugging : Enabled\n"); + printf("Debugging : Enabled\n"); #else - printf("Debugging : Disabled\n"); + printf("Debugging : Disabled\n"); #endif #ifdef __clang__ - printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); + printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); #elif defined(__GNUC__) - printf("Compiler : GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + printf("Compiler : GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #else - printf("Compiler : Unknown\n"); + printf("Compiler : Unknown\n"); #endif #if defined(_OPENMP) - printf("OpenMP : Supported (Version: %d)\n", _OPENMP); + printf("OpenMP : Supported (Version: %d)\n", _OPENMP); #endif #if defined(__x86_64__) - printf("Target architecture : x86_64\n"); + printf("Target architecture : x86_64\n"); #elif defined(__i386__) - printf("Target architecture : x86 (32-bit)\n"); + printf("Target architecture : x86 (32-bit)\n"); #elif defined(__aarch64__) - printf("Target architecture : ARM64\n"); + printf("Target architecture : ARM64\n"); #elif defined(__arm__) - printf("Target architecture : ARM\n"); + printf("Target architecture : ARM\n"); #else - printf("Target architecture : Unknown\n"); + printf("Target architecture : Unknown\n"); #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - printf("Endianness : Little-endian\n"); + printf("Endianness : Little-endian\n"); #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - printf("Endianness : Big-endian\n"); + printf("Endianness : Big-endian\n"); #else - printf("Endianness : Unknown\n"); + printf("Endianness : Unknown\n"); #endif - printf("\n"); + printf("\n"); - // 5. Current working directory - printf("Current Working Directory\n"); - printf("--------------------------\n"); - char cwd[1024]; - if (getcwd(cwd, sizeof(cwd)) != NULL) - { - printf("%s\n\n", cwd); - } + // 5. Current working directory + printf("Current Working Directory\n"); + printf("--------------------------\n"); + char cwd[4096]; + if (getcwd(cwd, sizeof(cwd)) != NULL) + { + printf("%s\n\n", cwd); + } - // 6. Dynamic libraries used - printf("Dynamic Libraries Loaded\n"); - printf("------------------------\n"); + // 6. Dynamic libraries used + printf("Dynamic Libraries Loaded\n"); + printf("------------------------\n"); #ifdef __APPLE__ - uint32_t dcount = _dyld_image_count(); - for (uint32_t i = 0; i < dcount; i++) - { - const char* name = _dyld_get_image_name(i); - const struct mach_header* header = _dyld_get_image_header(i); - const char* filename = strrchr(name, '/'); + uint32_t dcount = _dyld_image_count(); + for (uint32_t i = 0; i < dcount; i++) + { + const char* name = _dyld_get_image_name(i); + const struct mach_header* header = _dyld_get_image_header(i); + const char* filename = strrchr(name, '/'); - filename = filename ? filename + 1 : name; - printf(" %s => %s (0x%lx)\n", filename, name, (unsigned long)header); - } + filename = filename ? filename + 1 : name; + printf(" %s => %s (0x%lx)\n", filename, name, (unsigned long)header); + } #else - dl_iterate_phdr(dlpi_callback, NULL); + dl_iterate_phdr(dlpi_callback, NULL); #endif - printf("================================ System Information ================================\n\n"); + printf("\n================================ System Information ================================\n\n"); + } + + if (!myid) printf("Running on %d MPI rank%s\n", nprocs, nprocs > 1 ? "s" : ""); } /*-------------------------------------------------------------------------- @@ -239,33 +313,39 @@ PrintSystemInfo(void) *--------------------------------------------------------------------------*/ void -PrintLibInfo(void) +PrintLibInfo(MPI_Comm comm) { + int myid; time_t t; struct tm *tm_info; char buffer[100]; - /* Get current time */ - time(&t); - tm_info = localtime(&t); + MPI_Comm_rank(comm, &myid); + + if (!myid) + { + /* Get current time */ + time(&t); + tm_info = localtime(&t); - /* Format and print the date and time */ - strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info); - printf("Date and time: %s\n", buffer); + /* Format and print the date and time */ + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info); + printf("Date and time: %s\n", buffer); - /* Print hypre info */ + /* Print hypre info */ #if defined(HYPRE_DEVELOP_STRING) && defined(HYPRE_BRANCH_NAME) - printf("\nUsing HYPRE_DEVELOP_STRING: %s (%s)\n\n", - HYPRE_DEVELOP_STRING, HYPRE_BRANCH_NAME); + printf("\nUsing HYPRE_DEVELOP_STRING: %s (%s)\n\n", + HYPRE_DEVELOP_STRING, HYPRE_BRANCH_NAME); #elif defined(HYPRE_DEVELOP_STRING) && !defined(HYPRE_BRANCH_NAME) - printf("\nUsing HYPRE_DEVELOP_STRING: %s\n\n", - HYPRE_DEVELOP_STRING); + printf("\nUsing HYPRE_DEVELOP_STRING: %s\n\n", + HYPRE_DEVELOP_STRING); #elif defined(HYPRE_RELEASE_VERSION) - printf("\nUsing HYPRE_RELEASE_VERSION: %s\n\n", - HYPRE_RELEASE_VERSION); + printf("\nUsing HYPRE_RELEASE_VERSION: %s\n\n", + HYPRE_RELEASE_VERSION); #endif + } } /*-------------------------------------------------------------------------- @@ -273,17 +353,23 @@ PrintLibInfo(void) *--------------------------------------------------------------------------*/ void -PrintExitInfo(const char *argv0) +PrintExitInfo(MPI_Comm comm, const char *argv0) { + int myid; time_t t; struct tm *tm_info; char buffer[100]; - /* Get current time */ - time(&t); - tm_info = localtime(&t); + MPI_Comm_rank(comm, &myid); - /* Format and print the date and time */ - strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info); - printf("Date and time: %s\n\%s done!\n", buffer, argv0); + if (!myid) + { + /* Get current time */ + time(&t); + tm_info = localtime(&t); + + /* Format and print the date and time */ + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info); + printf("Date and time: %s\n\%s done!\n", buffer, argv0); + } } diff --git a/src/main.c b/src/main.c index 4d515dd..8f96851 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ PrintUsage(const char *argv0) int main(int argc, char **argv) { MPI_Comm comm = MPI_COMM_WORLD; - int myid, nprocs, i, k; + int myid, i, k; HYPREDRV_t obj; /*----------------------------------------------------------- @@ -28,7 +28,6 @@ int main(int argc, char **argv) MPI_Init(&argc, &argv); MPI_Comm_rank(comm, &myid); - MPI_Comm_size(comm, &nprocs); HYPREDRV_Initialize(); HYPREDRV_Create(comm, &obj); @@ -42,9 +41,8 @@ int main(int argc, char **argv) * Print libraries/driver info *-----------------------------------------------------------*/ - if (!myid) HYPREDRV_PrintLibInfo(); - if (!myid) HYPREDRV_PrintSystemInfo(); - if (!myid) printf("Running on %d MPI rank%s\n", nprocs, nprocs > 1 ? "s" : ""); + HYPREDRV_PrintLibInfo(comm); + HYPREDRV_PrintSystemInfo(comm); /*----------------------------------------------------------- * Parse input parameters @@ -102,7 +100,7 @@ int main(int argc, char **argv) *-----------------------------------------------------------*/ if (!myid) HYPREDRV_StatsPrint(obj); - if (!myid) HYPREDRV_PrintExitInfo(argv[0]); + HYPREDRV_PrintExitInfo(comm, argv[0]); HYPREDRV_Destroy(&obj); HYPREDRV_Finalize(); From b664766621618717da8180188d9be3c5f8ddc957 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Thu, 22 Aug 2024 21:07:15 -0700 Subject: [PATCH 03/17] Minor fix --- src/info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/info.c b/src/info.c index 9d64c6d..7e1baa5 100644 --- a/src/info.c +++ b/src/info.c @@ -370,6 +370,6 @@ PrintExitInfo(MPI_Comm comm, const char *argv0) /* Format and print the date and time */ strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", tm_info); - printf("Date and time: %s\n\%s done!\n", buffer, argv0); + printf("Date and time: %s\n%s done!\n", buffer, argv0); } } From 8bd0dd74714f90ad6d751a0f65d04c10b8874f10 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Thu, 22 Aug 2024 21:16:58 -0700 Subject: [PATCH 04/17] Minor fixes --- src/info.c | 61 +++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/info.c b/src/info.c index 7e1baa5..bb894f9 100644 --- a/src/info.c +++ b/src/info.c @@ -168,6 +168,9 @@ PrintSystemInfo(MPI_Comm comm) { while (fgets(buffer, sizeof(buffer), fp) != NULL) { + // Skip entries containing "Matrox" + if (strstr(buffer, "Matrox") != NULL) { continue; } + char *start = strstr(buffer, "VGA compatible controller"); if (!start) start = strstr(buffer, "3D controller"); if (!start) start = strstr(buffer, "2D controller"); @@ -203,17 +206,17 @@ PrintSystemInfo(MPI_Comm comm) int64_t freeMemory = (int64_t)vmstat.free_count * sysconf(_SC_PAGESIZE); int64_t usedMemory = memSize - freeMemory; - printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); + printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); } #else struct sysinfo info; if (sysinfo(&info) == 0) { - printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); + printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); + printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); + printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); } #endif @@ -223,55 +226,57 @@ PrintSystemInfo(MPI_Comm comm) struct utsname sysinfo; if (uname(&sysinfo) == 0) { - printf("System Name : %s\n", sysinfo.sysname); - printf("Node Name : %s\n", sysinfo.nodename); - printf("Release : %s\n", sysinfo.release); - printf("Version : %s\n", sysinfo.version); - printf("Machine Architecture : %s\n\n", sysinfo.machine); + printf("System Name : %s\n", sysinfo.sysname); + printf("Node Name : %s\n", sysinfo.nodename); + printf("Release : %s\n", sysinfo.release); + printf("Version : %s\n", sysinfo.version); + printf("Machine Architecture : %s\n\n", sysinfo.machine); } // 4. Compilation Flags Information printf("Compilation Information\n"); printf("------------------------\n"); - printf("Date : %s at %s\n", __DATE__, __TIME__); + printf("Date : %s at %s\n", __DATE__, __TIME__); #ifdef __OPTIMIZE__ - printf("Optimization : Enabled\n"); + printf("Optimization : Enabled\n"); #else - printf("Optimization : Disabled\n"); + printf("Optimization : Disabled\n"); #endif #ifdef DEBUG - printf("Debugging : Enabled\n"); + printf("Debugging : Enabled\n"); #else - printf("Debugging : Disabled\n"); + printf("Debugging : Disabled\n"); #endif #ifdef __clang__ - printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); + printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); +#elif defined(__INTEL_COMPILER) + printf("Compiler : Intel %d.%d\n", __INTEL_COMPILER / 100, (__INTEL_COMPILER % 100) / 10); #elif defined(__GNUC__) - printf("Compiler : GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + printf("Compiler : GCC %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #else - printf("Compiler : Unknown\n"); + printf("Compiler : Unknown\n"); #endif #if defined(_OPENMP) - printf("OpenMP : Supported (Version: %d)\n", _OPENMP); + printf("OpenMP : Supported (Version: %d)\n", _OPENMP); #endif #if defined(__x86_64__) - printf("Target architecture : x86_64\n"); + printf("Target architecture : x86_64\n"); #elif defined(__i386__) - printf("Target architecture : x86 (32-bit)\n"); + printf("Target architecture : x86 (32-bit)\n"); #elif defined(__aarch64__) - printf("Target architecture : ARM64\n"); + printf("Target architecture : ARM64\n"); #elif defined(__arm__) - printf("Target architecture : ARM\n"); + printf("Target architecture : ARM\n"); #else - printf("Target architecture : Unknown\n"); + printf("Target architecture : Unknown\n"); #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - printf("Endianness : Little-endian\n"); + printf("Endianness : Little-endian\n"); #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - printf("Endianness : Big-endian\n"); + printf("Endianness : Big-endian\n"); #else - printf("Endianness : Unknown\n"); + printf("Endianness : Unknown\n"); #endif printf("\n"); From 49fe6421189673a7f8783705979174550287ad4f Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Thu, 22 Aug 2024 21:42:21 -0700 Subject: [PATCH 05/17] Fixes for GPU counting --- src/info.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/info.c b/src/info.c index bb894f9..fd7eb87 100644 --- a/src/info.c +++ b/src/info.c @@ -72,8 +72,8 @@ PrintSystemInfo(MPI_Comm comm) // 1. CPU cores and model int numPhysicalCPUs = 0; + int physicalCPUSeen = 0; int numCPU; - int physicalCPUSeen; char cpuModels[8][256]; char gpuInfo[256] = "Unknown"; @@ -163,27 +163,52 @@ PrintSystemInfo(MPI_Comm comm) #ifndef __APPLE__ int gcount = 0; - fp = popen("lspci | grep -i 'vga'", "r"); + fp = popen("lspci | grep -Ei 'vga|3d|2d|display'", "r"); if (fp != NULL) { while (fgets(buffer, sizeof(buffer), fp) != NULL) { - // Skip entries containing "Matrox" + /* Skip entries containing "Matrox" */ if (strstr(buffer, "Matrox") != NULL) { continue; } char *start = strstr(buffer, "VGA compatible controller"); if (!start) start = strstr(buffer, "3D controller"); if (!start) start = strstr(buffer, "2D controller"); + if (!start) start = strstr(buffer, "Display controller"); if (start) { - strncpy(gpuInfo, start + strlen("VGA compatible controller: "), sizeof(buffer) - strlen("VGA compatible controller: ") - 1); - gpuInfo[strlen(gpuInfo) - 1] = '\0'; // Remove newline + /* Adjust the strncpy depending on which controller type was found */ + const char *controller_type = "VGA compatible controller: "; + if (strstr(buffer, "3D controller") != NULL) + { + controller_type = "3D controller: "; + } + else if (strstr(buffer, "2D controller") != NULL) + { + controller_type = "2D controller: "; + } + else if (strstr(buffer, "Display controller") != NULL) + { + controller_type = "Display controller: "; + } + + strncpy(gpuInfo, start + strlen(controller_type), sizeof(gpuInfo) - 1); + gpuInfo[sizeof(gpuInfo) - 1] = '\0'; + + /* Remove newline if present */ + size_t len = strlen(gpuInfo); + if (len > 0 && gpuInfo[len - 1] == '\n') + { + gpuInfo[len - 1] = '\0'; + } + printf("GPU Model #%d : %s\n", gcount++, gpuInfo); } else { - strncpy(gpuInfo, buffer, sizeof(buffer) - 1); + strncpy(gpuInfo, buffer, sizeof(gpuInfo) - 1); + gpuInfo[sizeof(gpuInfo) - 1] = '\0'; } } pclose(fp); From 51b4c61f513067c98ebec9f4ccc4b32d13bfa113 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 06:35:04 -0700 Subject: [PATCH 06/17] Add accelerators support and skip onboard graphics --- src/info.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/info.c b/src/info.c index fd7eb87..f04c3bb 100644 --- a/src/info.c +++ b/src/info.c @@ -163,18 +163,21 @@ PrintSystemInfo(MPI_Comm comm) #ifndef __APPLE__ int gcount = 0; - fp = popen("lspci | grep -Ei 'vga|3d|2d|display'", "r"); + fp = popen("lspci | grep -Ei 'vga|3d|2d|display|accel'", "r"); if (fp != NULL) { while (fgets(buffer, sizeof(buffer), fp) != NULL) { - /* Skip entries containing "Matrox" */ - if (strstr(buffer, "Matrox") != NULL) { continue; } + /* Skip onboard server graphics */ + if (strstr(buffer, "Matrox") != NULL) { continue; } + if (strstr(buffer, "ASPEED") != NULL) { continue; } + if (strstr(buffer, "Nuvoton") != NULL) { continue; } char *start = strstr(buffer, "VGA compatible controller"); if (!start) start = strstr(buffer, "3D controller"); if (!start) start = strstr(buffer, "2D controller"); if (!start) start = strstr(buffer, "Display controller"); + if (!start) start = strstr(buffer, "Processing accelerators"); if (start) { @@ -192,6 +195,10 @@ PrintSystemInfo(MPI_Comm comm) { controller_type = "Display controller: "; } + else if (strstr(buffer, "Processing accelerators") != NULL) + { + controller_type = "Processing accelerators: "; + } strncpy(gpuInfo, start + strlen(controller_type), sizeof(gpuInfo) - 1); gpuInfo[sizeof(gpuInfo) - 1] = '\0'; From e3de637e1fe7858b42b9b42c05ae3c0148fcd26e Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 06:39:48 -0700 Subject: [PATCH 07/17] Fix -Wtype-safety --- src/containers.c | 2 +- src/matrix.c | 2 +- src/vector.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/containers.c b/src/containers.c index ff1cc5b..fedc4e5 100644 --- a/src/containers.c +++ b/src/containers.c @@ -262,7 +262,7 @@ IntArrayUnique(MPI_Comm comm, IntArray *int_array) } } } - MPI_Bcast(&int_array->g_unique_size, 1, MPI_INT, 0, comm); + MPI_Bcast(&int_array->g_unique_size, 1, MPI_UNSIGNED_LONG, 0, comm); int_array->g_unique_data = (int*) calloc(int_array->g_unique_size, sizeof(int)); /* Compute global unique data */ diff --git a/src/matrix.c b/src/matrix.c index 37125e7..c3ad20a 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -84,7 +84,7 @@ IJMatrixReadMultipartBinary(const char *prefixname, } /* 3) Build IJMatrix */ - MPI_Scan(&nrows_sum, &nrows_offset, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, comm); + MPI_Scan(&nrows_sum, &nrows_offset, 1, MPI_UNSIGNED_LONG, MPI_SUM, comm); ilower = (HYPRE_BigInt) (nrows_offset - nrows_sum); iupper = (HYPRE_BigInt) (ilower + nrows_sum - 1); diff --git a/src/vector.c b/src/vector.c index 1ff571c..719ec62 100644 --- a/src/vector.c +++ b/src/vector.c @@ -82,7 +82,7 @@ IJVectorReadMultipartBinary(const char *prefixname, } /* 3) Build IJVector */ - MPI_Scan(&nrows_sum, &nrows_offset, 1, MPI_UNSIGNED_LONG_LONG, MPI_SUM, comm); + MPI_Scan(&nrows_sum, &nrows_offset, 1, MPI_UNSIGNED_LONG, MPI_SUM, comm); ilower = (HYPRE_BigInt) (nrows_offset - nrows_sum); iupper = (HYPRE_BigInt) (ilower + nrows_sum - 1); From 9d04b060c0194ffea1df4f03148a7321cc73a87a Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 09:40:47 -0400 Subject: [PATCH 08/17] Add MPI and OpenMP info --- src/info.c | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/info.c b/src/info.c index f04c3bb..941ff7a 100644 --- a/src/info.c +++ b/src/info.c @@ -9,7 +9,7 @@ #include #include #include -#ifdef __APPLE__ +#if defined(__APPLE__) #include #include #include @@ -20,6 +20,9 @@ #endif #include "info.h" #include "HYPRE_config.h" +#if defined(HYPRE_USING_OPENMP) +#include +#endif #ifndef __APPLE__ @@ -96,7 +99,7 @@ PrintSystemInfo(MPI_Comm comm) } } -#ifdef __APPLE__ +#if defined(__APPLE__) size_t size = sizeof(numCPU); sysctlbyname("hw.ncpu", &numCPU, &size, NULL, 0); @@ -226,7 +229,7 @@ PrintSystemInfo(MPI_Comm comm) // 2. Memory available and used printf("Memory Information\n"); printf("-------------------\n"); -#ifdef __APPLE__ +#if defined(__APPLE__) int64_t memSize; size_t memSizeLen = sizeof(memSize); sysctlbyname("hw.memsize", &memSize, &memSizeLen, NULL, 0); @@ -270,17 +273,17 @@ PrintSystemInfo(MPI_Comm comm) printf("------------------------\n"); printf("Date : %s at %s\n", __DATE__, __TIME__); -#ifdef __OPTIMIZE__ +#if defined(__OPTIMIZE__) printf("Optimization : Enabled\n"); #else printf("Optimization : Disabled\n"); #endif -#ifdef DEBUG +#if defined(DEBUG) printf("Debugging : Enabled\n"); #else printf("Debugging : Disabled\n"); #endif -#ifdef __clang__ +#if defined(__clang__) printf("Compiler : Clang %d.%d.%d\n", __clang_major__, __clang_minor__, __clang_patchlevel__); #elif defined(__INTEL_COMPILER) printf("Compiler : Intel %d.%d\n", __INTEL_COMPILER / 100, (__INTEL_COMPILER % 100) / 10); @@ -289,8 +292,26 @@ PrintSystemInfo(MPI_Comm comm) #else printf("Compiler : Unknown\n"); #endif -#if defined(_OPENMP) +#if defined(HYPRE_USING_OPENMP) && defined(_OPENMP) printf("OpenMP : Supported (Version: %d)\n", _OPENMP); +#else + printf("OpenMP : Not used\n"); +#endif + printf("MPI Implementation : "); +#if defined(CRAY_MPICH_VERSION) + printf("Cray MPI (Version: %s)\n", CRAY_MPICH_VERSION); +#elif defined(INTEL_MPI_VERSION) + printf("Intel MPI (Version: %s)\n", INTEL_MPI_VERSION); +#elif defined(MPICH_NAME) + printf("MPICH (Version: %s)\n", MPICH_VERSION); +#elif defined(OMPI_MAJOR_VERSION) + printf("OpenMPI (Version: %d.%d.%d)\n", OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION); +#elif defined(MVAPICH2_VERSION) + printf("MVAPICH2 (Version: %s)\n", MVAPICH2_VERSION); +#elif defined(SGI_MPI) + printf("SGI MPI\n"); +#else + printf("N/A\n"); #endif #if defined(__x86_64__) printf("Target architecture : x86_64\n"); @@ -324,7 +345,7 @@ PrintSystemInfo(MPI_Comm comm) // 6. Dynamic libraries used printf("Dynamic Libraries Loaded\n"); printf("------------------------\n"); -#ifdef __APPLE__ +#if defined(__APPLE__) uint32_t dcount = _dyld_image_count(); for (uint32_t i = 0; i < dcount; i++) { @@ -340,9 +361,16 @@ PrintSystemInfo(MPI_Comm comm) #endif printf("\n================================ System Information ================================\n\n"); - } + printf("Running on %d MPI rank%s\n", nprocs, nprocs > 1 ? "s" : ""); - if (!myid) printf("Running on %d MPI rank%s\n", nprocs, nprocs > 1 ? "s" : ""); + /* Number of OpenMP threads per rank used in hypre */ +#if defined(HYPRE_USING_OPENMP) && defined(_OPENMP) + int num_threads = omp_get_max_threads(); + printf("Running on %d OpenMP thread%s per MPI rank\n", num_threads, num_threads > 1 ? "s" : ""); +#else + printf("HYPRE not using OpenMP\n"); +#endif + } } /*-------------------------------------------------------------------------- From 2842e3d826e0f81597ecf8e3f6d69c7c7f2eb9e2 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 06:50:45 -0700 Subject: [PATCH 09/17] Add total numbers + tweaks --- src/info.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/info.c b/src/info.c index 941ff7a..2ef9cc5 100644 --- a/src/info.c +++ b/src/info.c @@ -76,7 +76,7 @@ PrintSystemInfo(MPI_Comm comm) // 1. CPU cores and model int numPhysicalCPUs = 0; int physicalCPUSeen = 0; - int numCPU; + int numCPUs; char cpuModels[8][256]; char gpuInfo[256] = "Unknown"; @@ -100,8 +100,8 @@ PrintSystemInfo(MPI_Comm comm) } #if defined(__APPLE__) - size_t size = sizeof(numCPU); - sysctlbyname("hw.ncpu", &numCPU, &size, NULL, 0); + size_t size = sizeof(numCPUs); + sysctlbyname("hw.ncpu", &numCPUs, &size, NULL, 0); size_t size = sizeof(numPhysicalCPUs); sysctlbyname("hw.packages", &numPhysicalCPUs, &size, NULL, 0); @@ -147,7 +147,7 @@ PrintSystemInfo(MPI_Comm comm) fclose(fp); } - numCPU = sysconf(_SC_NPROCESSORS_ONLN); + numCPUs = sysconf(_SC_NPROCESSORS_ONLN); #endif if (strlen(gpuInfo) == 0) { @@ -158,7 +158,9 @@ PrintSystemInfo(MPI_Comm comm) printf("-----------------\n"); printf("Number of Nodes : %d\n", numNodes); printf("Number of Processors : %d\n", numPhysicalCPUs); - printf("Number of CPU Cores : %d\n", numCPU); + printf("Number of CPU Cores : %d\n", numCPUs); + printf("Total # of Processors : %lld\n", (long long) numNodes * (long long) numPhysicalCPUs); + printf("Total # of CPU cores : %lld\n", (long long) numNodes * (long long) numCPUs); for (int i = 0; i < numPhysicalCPUs; i++) { printf("CPU Model #%d : %s\n", i, cpuModels[i]); @@ -302,12 +304,12 @@ PrintSystemInfo(MPI_Comm comm) printf("Cray MPI (Version: %s)\n", CRAY_MPICH_VERSION); #elif defined(INTEL_MPI_VERSION) printf("Intel MPI (Version: %s)\n", INTEL_MPI_VERSION); +#elif defined(MVAPICH2_VERSION) + printf("MVAPICH2 (Version: %s)\n", MVAPICH2_VERSION); #elif defined(MPICH_NAME) printf("MPICH (Version: %s)\n", MPICH_VERSION); #elif defined(OMPI_MAJOR_VERSION) printf("OpenMPI (Version: %d.%d.%d)\n", OMPI_MAJOR_VERSION, OMPI_MINOR_VERSION, OMPI_RELEASE_VERSION); -#elif defined(MVAPICH2_VERSION) - printf("MVAPICH2 (Version: %s)\n", MVAPICH2_VERSION); #elif defined(SGI_MPI) printf("SGI MPI\n"); #else From 4078893a2666d74fdbfe84c8f94ecdd3e15b5f92 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 10:10:12 -0400 Subject: [PATCH 10/17] Fix compiler warnings with hypre's bigint build --- src/linsys.c | 24 ++++++++++++------------ src/mgr.c | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/linsys.c b/src/linsys.c index dcdd16d..8587660 100644 --- a/src/linsys.c +++ b/src/linsys.c @@ -201,8 +201,8 @@ LinearSystemReadMatrix(MPI_Comm comm, LS_args *args, HYPRE_IJMatrix *matrix_ptr) "%.*s_%0*d/%.*s", (int) strlen(args->dirname), args->dirname, - args->digits_suffix, - args->init_suffix + ls_id, + (int) args->digits_suffix, + (int) args->init_suffix + ls_id, (int) strlen(args->matrix_filename), args->matrix_filename); } @@ -217,8 +217,8 @@ LinearSystemReadMatrix(MPI_Comm comm, LS_args *args, HYPRE_IJMatrix *matrix_ptr) "%.*s_%0*d", (int) strlen(args->matrix_basename), args->matrix_basename, - args->digits_suffix, - args->init_suffix + ls_id); + (int) args->digits_suffix, + (int) args->init_suffix + ls_id); } else { @@ -397,8 +397,8 @@ LinearSystemSetRHS(MPI_Comm comm, LS_args *args, HYPRE_IJMatrix mat, HYPRE_IJVec "%.*s_%0*d/%.*s", (int) strlen(args->dirname), args->dirname, - args->digits_suffix, - args->init_suffix + ls_id, + (int) args->digits_suffix, + (int) args->init_suffix + ls_id, (int) strlen(args->rhs_filename), args->rhs_filename); } @@ -413,8 +413,8 @@ LinearSystemSetRHS(MPI_Comm comm, LS_args *args, HYPRE_IJMatrix mat, HYPRE_IJVec "%.*s_%0*d", (int) strlen(args->rhs_basename), args->rhs_basename, - args->digits_suffix, - args->init_suffix + ls_id); + (int) args->digits_suffix, + (int) args->init_suffix + ls_id); } /* Read vector from file (Binary or ASCII) */ @@ -631,8 +631,8 @@ LinearSystemReadDofmap(MPI_Comm comm, LS_args *args, IntArray **dofmap_ptr) "%.*s_%0*d/%.*s", (int) strlen(args->dirname), args->dirname, - args->digits_suffix, - args->init_suffix + ls_id, + (int) args->digits_suffix, + (int) args->init_suffix + ls_id, (int) strlen(args->dofmap_filename), args->dofmap_filename); } @@ -647,8 +647,8 @@ LinearSystemReadDofmap(MPI_Comm comm, LS_args *args, IntArray **dofmap_ptr) "%.*s_%0*d", (int) strlen(args->dofmap_basename), args->dofmap_basename, - args->digits_suffix, - args->init_suffix + ls_id); + (int) args->digits_suffix, + (int) args->init_suffix + ls_id); } /* Destroy previous dofmap array */ diff --git a/src/mgr.c b/src/mgr.c index e8cfb60..74a8108 100644 --- a/src/mgr.c +++ b/src/mgr.c @@ -416,6 +416,7 @@ MGRCreate(MGR_args *args, HYPRE_Solver *precon_ptr, HYPRE_Solver *csolver_ptr) HYPRE_Solver csolver; HYPRE_Solver frelax; HYPRE_Solver grelax; + HYPRE_Int *dofmap_data; IntArray *dofmap; HYPRE_Int num_dofs; HYPRE_Int num_dofs_last; @@ -460,10 +461,24 @@ MGRCreate(MGR_args *args, HYPRE_Solver *precon_ptr, HYPRE_Solver *csolver_ptr) } } + /* Set dofmap_data */ + if (sizeof(HYPRE_Int) == sizeof(int)) + { + dofmap_data = (HYPRE_Int*) dofmap->data; + } + else + { + dofmap_data = (HYPRE_Int*) malloc(dofmap->size * sizeof(HYPRE_Int)); + for (i = 0; i < dofmap->size; i++) + { + dofmap_data[i] = (HYPRE_Int) dofmap->data[i]; + } + } + /* Config preconditioner */ HYPRE_MGRCreate(&precon); HYPRE_MGRSetCpointsByPointMarkerArray(precon, num_dofs, num_levels - 1, - num_c_dofs, c_dofs, dofmap->data); + num_c_dofs, c_dofs, dofmap_data); HYPRE_MGRSetNonCpointsToFpoints(precon, args->non_c_to_f); HYPRE_MGRSetMaxIter(precon, args->max_iter); HYPRE_MGRSetTol(precon, args->tolerance); @@ -530,4 +545,8 @@ MGRCreate(MGR_args *args, HYPRE_Solver *precon_ptr, HYPRE_Solver *csolver_ptr) { free(c_dofs[lvl]); } + if ((void *) dofmap_data != (void *) dofmap->data) + { + free(dofmap_data); + } } From 3df08c518f83719dbd2f1e97f775b2fc395f9611 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 20:23:15 -0400 Subject: [PATCH 11/17] Add GPU RAM support --- src/info.c | 91 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 21 deletions(-) diff --git a/src/info.c b/src/info.c index 2ef9cc5..ed692ec 100644 --- a/src/info.c +++ b/src/info.c @@ -53,9 +53,11 @@ dlpi_callback(struct dl_phdr_info *info, size_t size, void *data) void PrintSystemInfo(MPI_Comm comm) { - int myid, nprocs; - char hostname[256]; - double bytes_to_GB = (double) (1 << 30); + int myid, nprocs; + char hostname[256]; + double bytes_to_GB = (double) (1 << 30); + double MB_to_GB = (double) (1 << 10); + int64_t total, used, free; MPI_Comm_rank(comm, &myid); MPI_Comm_size(comm, &nprocs); @@ -112,7 +114,7 @@ PrintSystemInfo(MPI_Comm comm) sysctlbyname("machdep.cpu.brand_string", &cpuModels[i], &size, NULL, 0); } #else - char buffer[256]; + char buffer[32768]; FILE* fp = fopen("/proc/cpuinfo", "r"); if (fp != NULL) { @@ -151,7 +153,7 @@ PrintSystemInfo(MPI_Comm comm) #endif if (strlen(gpuInfo) == 0) { - strncpy(gpuInfo, "Unknown", sizeof(buffer)); + strncpy(gpuInfo, "Unknown", 8 * sizeof(char)); } printf("Processing Units\n"); @@ -225,40 +227,87 @@ PrintSystemInfo(MPI_Comm comm) } pclose(fp); } + gcount = 0; #endif printf("\n"); // 2. Memory available and used - printf("Memory Information\n"); - printf("-------------------\n"); + printf("Memory Information (Used/Total)\n"); + printf("--------------------------------\n"); #if defined(__APPLE__) - int64_t memSize; - size_t memSizeLen = sizeof(memSize); - sysctlbyname("hw.memsize", &memSize, &memSizeLen, NULL, 0); + size_t memSizeLen = sizeof(total); + sysctlbyname("hw.memsize", &total, &memSizeLen, NULL, 0); mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - vm_statistics_data_t vmstat; + vm_statistics_data_t vmstat; if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { - int64_t freeMemory = (int64_t)vmstat.free_count * sysconf(_SC_PAGESIZE); - int64_t usedMemory = memSize - freeMemory; + free = (int64_t) vmstat.free_count * sysconf(_SC_PAGESIZE); + used = total - free; - printf("Total Memory : %.3f GB\n", (double) memSize / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (double) usedMemory / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", (double) freeMemory / bytes_to_GB); + printf("CPU RAM : %5.2f / %5.2f (%5.2f %%) GB\n", + (double) used / bytes_to_GB, + (double) total / bytes_to_GB, + 100.0 * (total - used) / (double) total); } #else struct sysinfo info; if (sysinfo(&info) == 0) { - printf("Total Memory : %.3f GB\n", info.totalram * info.mem_unit / bytes_to_GB); - printf("Used Memory : %.3f GB\n", (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB); - printf("Free Memory : %.3f GB\n\n", info.freeram * info.mem_unit / bytes_to_GB); + printf("CPU RAM : %5.2f / %5.2f (%5.2f %%) GB\n", + (double) (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB, + (double) info.totalram * info.mem_unit / bytes_to_GB, + 100.0 * (info.totalram - info.freeram) / (double) info.totalram); } #endif + /* NVIDIA GPU Memory Information */ + fp = popen("nvidia-smi --query-gpu=memory.total,memory.used --format=csv,noheader,nounits", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp) != NULL) + { + sscanf(buffer, "%ld, %ld", &total, &used); + printf("GPU RAM #%d : %5.2f / %5.2f (%5.2f %%) GB\n", + gcount++, + used / MB_to_GB, + total / MB_to_GB, + 100.0 * used / (double) total); + } + pclose(fp); + } + + /* AMD GPU Memory Information */ + fp = popen("rocm-smi --showmeminfo vram --json", "r"); + if (fp != NULL) + { + fread(buffer, sizeof(char), sizeof(buffer) - 1, fp); + buffer[sizeof(buffer) - 1] = '\0'; + pclose(fp); + + const char *vram_total_str = "\"VRAM Total Memory (B)\": \""; + const char *vram_used_str = "\"VRAM Total Used Memory (B)\": \""; + const char *ptr = buffer; + + while ((ptr = strstr(ptr, vram_total_str)) != NULL) + { + ptr += strlen(vram_total_str); + total = strtoll(ptr, NULL, 10); + + ptr = strstr(ptr, vram_used_str); + ptr += strlen(vram_used_str); + used = strtoll(ptr, NULL, 10); + + printf("GPU RAM #%d : %5.2f / %5.2f (%5.2f %%) GB\n", + gcount++, + used / bytes_to_GB, + total / bytes_to_GB, + 100.0 * used / (double) total); + } + } + // 3. OS system info, release, version, machine - printf("Operating System\n"); + printf("\nOperating System\n"); printf("-----------------\n"); struct utsname sysinfo; if (uname(&sysinfo) == 0) @@ -299,7 +348,7 @@ PrintSystemInfo(MPI_Comm comm) #else printf("OpenMP : Not used\n"); #endif - printf("MPI Implementation : "); + printf("MPI library : "); #if defined(CRAY_MPICH_VERSION) printf("Cray MPI (Version: %s)\n", CRAY_MPICH_VERSION); #elif defined(INTEL_MPI_VERSION) From 59236877ae57488a64969471c29564f55e2dcb31 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 20:53:04 -0400 Subject: [PATCH 12/17] Tweaks --- src/info.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/info.c b/src/info.c index ed692ec..10d3fc9 100644 --- a/src/info.c +++ b/src/info.c @@ -261,12 +261,16 @@ PrintSystemInfo(MPI_Comm comm) } #endif - /* NVIDIA GPU Memory Information */ - fp = popen("nvidia-smi --query-gpu=memory.total,memory.used --format=csv,noheader,nounits", "r"); - if (fp != NULL) - { - while (fgets(buffer, sizeof(buffer), fp) != NULL) - { + /* NVIDIA GPU Memory Information */ + fp = NULL; + if (system("command -v nvidia-smi > /dev/null 2>&1") == 0) + { + fp = popen("nvidia-smi --query-gpu=memory.total,memory.used --format=csv,noheader,nounits", "r"); + } + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp) != NULL) + { sscanf(buffer, "%ld, %ld", &total, &used); printf("GPU RAM #%d : %5.2f / %5.2f (%5.2f %%) GB\n", gcount++, @@ -278,7 +282,11 @@ PrintSystemInfo(MPI_Comm comm) } /* AMD GPU Memory Information */ - fp = popen("rocm-smi --showmeminfo vram --json", "r"); + fp = NULL; + if (system("command -v rocm-smi > /dev/null 2>&1") == 0) + { + fp = popen("rocm-smi --showmeminfo vram --json", "r"); + } if (fp != NULL) { fread(buffer, sizeof(char), sizeof(buffer) - 1, fp); @@ -353,6 +361,11 @@ PrintSystemInfo(MPI_Comm comm) printf("Cray MPI (Version: %s)\n", CRAY_MPICH_VERSION); #elif defined(INTEL_MPI_VERSION) printf("Intel MPI (Version: %s)\n", INTEL_MPI_VERSION); +#elif defined(__IBM_MPI__) + printf("IBM Spectrum MPI (Version: %d.%d.%d)\n", + __IBM_MPI_MAJOR_VERSION, + __IBM_MPI_MINOR_VERSION, + __IBM_MPI_RELEASE_VERSION); #elif defined(MVAPICH2_VERSION) printf("MVAPICH2 (Version: %s)\n", MVAPICH2_VERSION); #elif defined(MPICH_NAME) From 2fc1434288f5a851c2bf54221303680d9008ab6c Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Fri, 23 Aug 2024 18:36:58 -0700 Subject: [PATCH 13/17] Tweaks for ppc64le --- src/info.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/src/info.c b/src/info.c index 10d3fc9..47a887c 100644 --- a/src/info.c +++ b/src/info.c @@ -9,20 +9,21 @@ #include #include #include +#include "info.h" +#include "HYPRE_config.h" +#if defined(HYPRE_USING_OPENMP) +#include +#endif + #if defined(__APPLE__) #include #include #include #else -#define __USE_GNU #include +#define __USE_GNU #include #endif -#include "info.h" -#include "HYPRE_config.h" -#if defined(HYPRE_USING_OPENMP) -#include -#endif #ifndef __APPLE__ @@ -147,6 +148,34 @@ PrintSystemInfo(MPI_Comm comm) } } fclose(fp); + + if (numPhysicalCPUs == 0) + { + fp = popen("lscpu | grep 'Socket(s)' | awk '{print $2}'", "r"); + if (fp != NULL) + { + if (fgets(buffer, sizeof(buffer), fp) != NULL) + { + numPhysicalCPUs = atoi(buffer); + } + pclose(fp); + } + + fp = popen("lscpu | grep 'Model name:' | sed 's/Model name:\\s*//'", "r"); + if (fp != NULL) + { + if (fgets(buffer, sizeof(buffer), fp) != NULL) + { + buffer[strcspn(buffer, "\n")] = '\0'; + for (int i = 0; i < numPhysicalCPUs; i++) + { + strncpy(cpuModels[i], buffer, sizeof(cpuModels[i]) - 1); + cpuModels[i][sizeof(cpuModels[i]) - 1] = '\0'; + } + } + pclose(fp); + } + } } numCPUs = sysconf(_SC_NPROCESSORS_ONLN); @@ -245,7 +274,7 @@ PrintSystemInfo(MPI_Comm comm) free = (int64_t) vmstat.free_count * sysconf(_SC_PAGESIZE); used = total - free; - printf("CPU RAM : %5.2f / %5.2f (%5.2f %%) GB\n", + printf("CPU RAM : %6.2f / %6.2f (%5.2f %%) GB\n", (double) used / bytes_to_GB, (double) total / bytes_to_GB, 100.0 * (total - used) / (double) total); @@ -254,7 +283,7 @@ PrintSystemInfo(MPI_Comm comm) struct sysinfo info; if (sysinfo(&info) == 0) { - printf("CPU RAM : %5.2f / %5.2f (%5.2f %%) GB\n", + printf("CPU RAM : %6.2f / %6.2f (%5.2f %%) GB\n", (double) (info.totalram - info.freeram) * info.mem_unit / bytes_to_GB, (double) info.totalram * info.mem_unit / bytes_to_GB, 100.0 * (info.totalram - info.freeram) / (double) info.totalram); @@ -272,7 +301,7 @@ PrintSystemInfo(MPI_Comm comm) while (fgets(buffer, sizeof(buffer), fp) != NULL) { sscanf(buffer, "%ld, %ld", &total, &used); - printf("GPU RAM #%d : %5.2f / %5.2f (%5.2f %%) GB\n", + printf("GPU RAM #%d : %6.2f / %6.2f (%5.2f %%) GB\n", gcount++, used / MB_to_GB, total / MB_to_GB, @@ -306,7 +335,7 @@ PrintSystemInfo(MPI_Comm comm) ptr += strlen(vram_used_str); used = strtoll(ptr, NULL, 10); - printf("GPU RAM #%d : %5.2f / %5.2f (%5.2f %%) GB\n", + printf("GPU RAM #%d : %6.2f / %6.2f (%5.2f %%) GB\n", gcount++, used / bytes_to_GB, total / bytes_to_GB, @@ -431,8 +460,6 @@ PrintSystemInfo(MPI_Comm comm) #if defined(HYPRE_USING_OPENMP) && defined(_OPENMP) int num_threads = omp_get_max_threads(); printf("Running on %d OpenMP thread%s per MPI rank\n", num_threads, num_threads > 1 ? "s" : ""); -#else - printf("HYPRE not using OpenMP\n"); #endif } } From 14e7f80fef749b1870c1c8ee30ec2852f13d6125 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Sat, 24 Aug 2024 22:06:26 -0700 Subject: [PATCH 14/17] Improve GPU and MPICH info --- src/info.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/info.c b/src/info.c index 47a887c..71b2644 100644 --- a/src/info.c +++ b/src/info.c @@ -25,6 +25,13 @@ #include #endif +#ifndef STRINGIFY +#define STRINGIFY(x) #x +#endif +#ifndef TOSTRING +#define TOSTRING(x) STRINGIFY(x) +#endif + #ifndef __APPLE__ /*-------------------------------------------------------------------------- @@ -199,7 +206,11 @@ PrintSystemInfo(MPI_Comm comm) #ifndef __APPLE__ int gcount = 0; - fp = popen("lspci | grep -Ei 'vga|3d|2d|display|accel'", "r"); + fp = NULL; + if (system("command -v lscpi > /dev/null 2>&1") == 0) + { + fp = popen("lspci | grep -Ei 'vga|3d|2d|display|accel'", "r"); + } if (fp != NULL) { while (fgets(buffer, sizeof(buffer), fp) != NULL) @@ -256,6 +267,18 @@ PrintSystemInfo(MPI_Comm comm) } pclose(fp); } + else if (system("command -v nvidia-smi > /dev/null 2>&1") == 0) + { + fp = popen("nvidia-smi --query-gpu=name --format=csv,noheader", "r"); + if (fp != NULL) + { + while (fgets(buffer, sizeof(buffer), fp) != NULL) + { + printf("GPU Model #%d : %s", gcount++, buffer); + } + pclose(fp); + } + } gcount = 0; #endif printf("\n"); @@ -387,7 +410,7 @@ PrintSystemInfo(MPI_Comm comm) #endif printf("MPI library : "); #if defined(CRAY_MPICH_VERSION) - printf("Cray MPI (Version: %s)\n", CRAY_MPICH_VERSION); + printf("Cray MPI (Version: %s)\n", TOSTRING(CRAY_MPICH_VERSION)); #elif defined(INTEL_MPI_VERSION) printf("Intel MPI (Version: %s)\n", INTEL_MPI_VERSION); #elif defined(__IBM_MPI__) From e422035c0156225827ca7d4dd756b018f307ee34 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Mon, 26 Aug 2024 10:30:57 -0400 Subject: [PATCH 15/17] Cores -> threads | lscpi -> lspci --- src/info.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/info.c b/src/info.c index 71b2644..cc0e965 100644 --- a/src/info.c +++ b/src/info.c @@ -196,9 +196,9 @@ PrintSystemInfo(MPI_Comm comm) printf("-----------------\n"); printf("Number of Nodes : %d\n", numNodes); printf("Number of Processors : %d\n", numPhysicalCPUs); - printf("Number of CPU Cores : %d\n", numCPUs); - printf("Total # of Processors : %lld\n", (long long) numNodes * (long long) numPhysicalCPUs); - printf("Total # of CPU cores : %lld\n", (long long) numNodes * (long long) numCPUs); + printf("Number of CPU threads : %d\n", numCPUs); + printf("Tot. # of Processors : %lld\n", (long long) numNodes * (long long) numPhysicalCPUs); + printf("Tot. # of CPU threads : %lld\n", (long long) numNodes * (long long) numCPUs); for (int i = 0; i < numPhysicalCPUs; i++) { printf("CPU Model #%d : %s\n", i, cpuModels[i]); @@ -207,7 +207,7 @@ PrintSystemInfo(MPI_Comm comm) #ifndef __APPLE__ int gcount = 0; fp = NULL; - if (system("command -v lscpi > /dev/null 2>&1") == 0) + if (system("command -v lspci > /dev/null 2>&1") == 0) { fp = popen("lspci | grep -Ei 'vga|3d|2d|display|accel'", "r"); } From 5bfac6dfc4086d8d8b44fa95131ec1c9d52b8548 Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Mon, 26 Aug 2024 12:12:42 -0400 Subject: [PATCH 16/17] MacOS fixes --- src/info.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/info.c b/src/info.c index cc0e965..7f98755 100644 --- a/src/info.c +++ b/src/info.c @@ -66,6 +66,9 @@ PrintSystemInfo(MPI_Comm comm) double bytes_to_GB = (double) (1 << 30); double MB_to_GB = (double) (1 << 10); int64_t total, used, free; + int gcount; + FILE *fp = NULL; + char buffer[32768]; MPI_Comm_rank(comm, &myid); MPI_Comm_size(comm, &nprocs); @@ -110,20 +113,19 @@ PrintSystemInfo(MPI_Comm comm) } #if defined(__APPLE__) - size_t size = sizeof(numCPUs); - sysctlbyname("hw.ncpu", &numCPUs, &size, NULL, 0); + size_t msize = sizeof(numCPUs); + sysctlbyname("hw.ncpu", &numCPUs, &msize, NULL, 0); - size_t size = sizeof(numPhysicalCPUs); - sysctlbyname("hw.packages", &numPhysicalCPUs, &size, NULL, 0); + msize = sizeof(numPhysicalCPUs); + sysctlbyname("hw.packages", &numPhysicalCPUs, &msize, NULL, 0); for (int i = 0; i < numPhysicalCPUs; i++) { - size = sizeof(cpuModels[i]); - sysctlbyname("machdep.cpu.brand_string", &cpuModels[i], &size, NULL, 0); + msize = sizeof(cpuModels[i]); + sysctlbyname("machdep.cpu.brand_string", &cpuModels[i], &msize, NULL, 0); } #else - char buffer[32768]; - FILE* fp = fopen("/proc/cpuinfo", "r"); + fp = fopen("/proc/cpuinfo", "r"); if (fp != NULL) { while (fgets(buffer, sizeof(buffer), fp)) @@ -205,7 +207,7 @@ PrintSystemInfo(MPI_Comm comm) } #ifndef __APPLE__ - int gcount = 0; + gcount = 0; fp = NULL; if (system("command -v lspci > /dev/null 2>&1") == 0) { @@ -323,7 +325,7 @@ PrintSystemInfo(MPI_Comm comm) { while (fgets(buffer, sizeof(buffer), fp) != NULL) { - sscanf(buffer, "%ld, %ld", &total, &used); + sscanf(buffer, "%lld, %lld", &total, &used); printf("GPU RAM #%d : %6.2f / %6.2f (%5.2f %%) GB\n", gcount++, used / MB_to_GB, From aabb98ab0757750117750243a7c28ee84d54ffad Mon Sep 17 00:00:00 2001 From: "Victor A. P. Magri" Date: Mon, 26 Aug 2024 12:17:53 -0400 Subject: [PATCH 17/17] int64_t -> size_t --- src/info.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/info.c b/src/info.c index 7f98755..b011475 100644 --- a/src/info.c +++ b/src/info.c @@ -65,7 +65,7 @@ PrintSystemInfo(MPI_Comm comm) char hostname[256]; double bytes_to_GB = (double) (1 << 30); double MB_to_GB = (double) (1 << 10); - int64_t total, used, free; + size_t total, used, free; int gcount; FILE *fp = NULL; char buffer[32768]; @@ -296,7 +296,7 @@ PrintSystemInfo(MPI_Comm comm) vm_statistics_data_t vmstat; if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS) { - free = (int64_t) vmstat.free_count * sysconf(_SC_PAGESIZE); + free = (size_t) vmstat.free_count * sysconf(_SC_PAGESIZE); used = total - free; printf("CPU RAM : %6.2f / %6.2f (%5.2f %%) GB\n", @@ -325,7 +325,7 @@ PrintSystemInfo(MPI_Comm comm) { while (fgets(buffer, sizeof(buffer), fp) != NULL) { - sscanf(buffer, "%lld, %lld", &total, &used); + sscanf(buffer, "%ld, %ld", &total, &used); printf("GPU RAM #%d : %6.2f / %6.2f (%5.2f %%) GB\n", gcount++, used / MB_to_GB,