From 876032b76243b69c28c7c607589298d82558174c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 11 Dec 2019 05:33:16 -0500 Subject: [PATCH 1/2] refactor MPI library info query so it can be added to -help flag output --- src/info.cpp | 33 ++++++++++++++++++++------------- src/info.h | 1 + src/lammps.cpp | 8 ++++++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 4b4c9a6a75..1e66c6644b 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -355,19 +355,7 @@ void Info::command(int narg, char **arg) if (flags & COMM) { int major,minor,len; -#if (defined(MPI_VERSION) && (MPI_VERSION > 2)) || defined(MPI_STUBS) - char version[MPI_MAX_LIBRARY_VERSION_STRING]; - MPI_Get_library_version(version,&len); -#else - char version[] = "Undetected MPI implementation"; - len = strlen(version); -#endif - - MPI_Get_version(&major,&minor); - if (len > 80) { - char *ptr = strchr(version+80,'\n'); - if (ptr) *ptr = '\0'; - } + const char *version = get_mpi_info(major,minor); fprintf(out,"\nCommunication information:\n"); fprintf(out,"MPI library level: MPI v%d.%d\n",major,minor); @@ -1209,6 +1197,25 @@ const char *Info::get_openmp_info() #endif } +const char *Info::get_mpi_info(int &major, int &minor) +{ + int len; + #if (defined(MPI_VERSION) && (MPI_VERSION > 2)) || defined(MPI_STUBS) + static char version[MPI_MAX_LIBRARY_VERSION_STRING]; + MPI_Get_library_version(version,&len); +#else + static char version[] = "Undetected MPI implementation"; + len = strlen(version); +#endif + + MPI_Get_version(&major,&minor); + if (len > 80) { + char *ptr = strchr(version+80,'\n'); + if (ptr) *ptr = '\0'; + } + return version; +} + const char *Info::get_cxx_info() { #if __cplusplus > 201703L diff --git a/src/info.h b/src/info.h index 8ac931aa68..01d6105ff2 100644 --- a/src/info.h +++ b/src/info.h @@ -43,6 +43,7 @@ class Info : protected Pointers { static char *get_os_info(); static char *get_compiler_info(); static const char *get_openmp_info(); + static const char *get_mpi_info(int &, int &); static const char *get_cxx_info(); char **get_variable_names(int &num); diff --git a/src/lammps.cpp b/src/lammps.cpp index a2d405855d..4b09429b52 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -1271,14 +1271,18 @@ void LAMMPS::print_config(FILE *fp) const char *pkg; int ncword, ncline = 0; - char *infobuf = Info::get_os_info(); + const char *infobuf = Info::get_os_info(); fprintf(fp,"OS: %s\n\n",infobuf); delete[] infobuf; infobuf = Info::get_compiler_info(); fprintf(fp,"Compiler: %s with %s\n",infobuf,Info::get_openmp_info()); delete[] infobuf; - fprintf(fp,"C++ standard: %s\n\n",Info::get_cxx_info()); + fprintf(fp,"C++ standard: %s\n",Info::get_cxx_info()); + + int major,minor; + infobuf = Info::get_mpi_info(major,minor); + fprintf(fp,"MPI v%d.%d: %s\n\n",major,minor,infobuf); fputs("Active compile time flags:\n\n",fp); if (Info::has_gzip_support()) fputs("-DLAMMPS_GZIP\n",fp); From 5e983b899a6649ad84dfec33dc3bc8175d22f833 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 11 Dec 2019 08:34:56 -0500 Subject: [PATCH 2/2] remove unused variable --- src/info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/info.cpp b/src/info.cpp index 1e66c6644b..ca90a6cc2f 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -354,7 +354,7 @@ void Info::command(int narg, char **arg) } if (flags & COMM) { - int major,minor,len; + int major,minor; const char *version = get_mpi_info(major,minor); fprintf(out,"\nCommunication information:\n");