convert code in Info to use {fmt} and string
This commit is contained in:
135
src/info.cpp
135
src/info.cpp
@ -49,6 +49,7 @@
|
|||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "fmt/format.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define PSAPI_VERSION 1
|
#define PSAPI_VERSION 1
|
||||||
@ -267,27 +268,24 @@ void Info::command(int narg, char **arg)
|
|||||||
fprintf(out,"Printed on %s\n",ctime(&now));
|
fprintf(out,"Printed on %s\n",ctime(&now));
|
||||||
|
|
||||||
if (flags & CONFIG) {
|
if (flags & CONFIG) {
|
||||||
if (lmp->has_git_info) {
|
fmt::print(out,"\nLAMMPS version: {} / {}\n",
|
||||||
fprintf(out,"\nLAMMPS version: %s / %s\nGit info: %s / %s / %s\n\n",
|
|
||||||
universe->version, universe->num_ver,lmp->git_branch,
|
|
||||||
lmp->git_descriptor,lmp->git_commit);
|
|
||||||
} else {
|
|
||||||
fprintf(out,"\nLAMMPS version: %s / %s\n\n",
|
|
||||||
universe->version, universe->num_ver);
|
universe->version, universe->num_ver);
|
||||||
}
|
|
||||||
const char *infobuf = get_os_info();
|
|
||||||
fprintf(out,"OS information: %s\n\n",infobuf);
|
|
||||||
delete[] infobuf;
|
|
||||||
|
|
||||||
fprintf(out,"sizeof(smallint): %3d-bit\n",(int)sizeof(smallint)*8);
|
if (lmp->has_git_info)
|
||||||
fprintf(out,"sizeof(imageint): %3d-bit\n",(int)sizeof(imageint)*8);
|
fmt::print(out,"Git info: {} / {} / {}\n",
|
||||||
fprintf(out,"sizeof(tagint): %3d-bit\n",(int)sizeof(tagint)*8);
|
lmp->git_branch, lmp->git_descriptor,lmp->git_commit);
|
||||||
fprintf(out,"sizeof(bigint): %3d-bit\n",(int)sizeof(bigint)*8);
|
|
||||||
|
|
||||||
infobuf = get_compiler_info();
|
fmt::print(out,"\nOS information: {}\n\n",get_os_info());
|
||||||
fprintf(out,"\nCompiler: %s with %s\n",infobuf,get_openmp_info());
|
|
||||||
delete[] infobuf;
|
fmt::print(out,"sizeof(smallint): {}-bit\n"
|
||||||
fprintf(out,"C++ standard: %s\n",get_cxx_info());
|
"sizeof(imageint): {}-bit\n"
|
||||||
|
"sizeof(tagint): {}-bit\n"
|
||||||
|
"sizeof(bigint): {}-bit\n",
|
||||||
|
sizeof(smallint)*8, sizeof(imageint)*8,
|
||||||
|
sizeof(tagint)*8, sizeof(bigint)*8);
|
||||||
|
|
||||||
|
fmt::print(out,"\nCompiler: {} with {}\nC++ standard: {}\n",
|
||||||
|
get_compiler_info(),get_openmp_info(),get_cxx_info());
|
||||||
|
|
||||||
fputs("\nActive compile time flags:\n\n",out);
|
fputs("\nActive compile time flags:\n\n",out);
|
||||||
if (has_gzip_support()) fputs("-DLAMMPS_GZIP\n",out);
|
if (has_gzip_support()) fputs("-DLAMMPS_GZIP\n",out);
|
||||||
@ -361,21 +359,21 @@ void Info::command(int narg, char **arg)
|
|||||||
|
|
||||||
if (flags & COMM) {
|
if (flags & COMM) {
|
||||||
int major,minor;
|
int major,minor;
|
||||||
const char *version = get_mpi_info(major,minor);
|
string version = get_mpi_info(major,minor);
|
||||||
|
|
||||||
fprintf(out,"\nCommunication information:\n");
|
fmt::print(out,"\nCommunication information:\n"
|
||||||
fprintf(out,"MPI library level: MPI v%d.%d\n",major,minor);
|
"MPI library level: MPI v{}.{}\n"
|
||||||
fprintf(out,"MPI version: %s\n",version);
|
"MPI version: {}\n",major,minor,version);
|
||||||
fprintf(out,"Comm style = %s, Comm layout = %s\n",
|
|
||||||
commstyles[comm->style], commlayout[comm->layout]);
|
fmt::print(out,"Comm style = {}, Comm layout = {}\n"
|
||||||
fprintf(out,"Communicate velocities for ghost atoms = %s\n",
|
"Communicate velocities for ghost atoms = {}\n",
|
||||||
|
commstyles[comm->style], commlayout[comm->layout],
|
||||||
comm->ghost_velocity ? "yes" : "no");
|
comm->ghost_velocity ? "yes" : "no");
|
||||||
|
|
||||||
if (comm->mode == 0) {
|
if (comm->mode == 0)
|
||||||
fprintf(out,"Communication mode = single\n");
|
fmt::print(out,"Communication mode = single\n"
|
||||||
fprintf(out,"Communication cutoff = %g\n",
|
"Communication cutoff = {}\n",
|
||||||
comm->get_comm_cutoff());
|
comm->get_comm_cutoff());
|
||||||
}
|
|
||||||
|
|
||||||
if (comm->mode == 1) {
|
if (comm->mode == 1) {
|
||||||
fprintf(out,"Communication mode = multi\n");
|
fprintf(out,"Communication mode = multi\n");
|
||||||
@ -987,7 +985,7 @@ bool Info::has_style(const string & category, const string & name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<std::string> Info::get_available_styles(const string & category)
|
vector<string> Info::get_available_styles(const string & category)
|
||||||
{
|
{
|
||||||
if ( category == "atom" ) {
|
if ( category == "atom" ) {
|
||||||
return get_style_names(atom->avec_map);
|
return get_style_names(atom->avec_map);
|
||||||
@ -1153,9 +1151,9 @@ bool Info::has_package(const char * package_name) {
|
|||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
#define _INFOBUF_SIZE 256
|
#define _INFOBUF_SIZE 256
|
||||||
|
|
||||||
char *Info::get_os_info()
|
string Info::get_os_info()
|
||||||
{
|
{
|
||||||
char *buf = new char[_INFOBUF_SIZE];
|
string buf;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
DWORD fullversion,majorv,minorv,buildv=0;
|
DWORD fullversion,majorv,minorv,buildv=0;
|
||||||
@ -1166,89 +1164,88 @@ char *Info::get_os_info()
|
|||||||
if (fullversion < 0x80000000)
|
if (fullversion < 0x80000000)
|
||||||
buildv = (DWORD) (HIWORD(fullversion));
|
buildv = (DWORD) (HIWORD(fullversion));
|
||||||
|
|
||||||
|
buf = fmt::format("Windows {}.{} ({}) on ",majorv,minorv,buildv);
|
||||||
|
|
||||||
SYSTEM_INFO si;
|
SYSTEM_INFO si;
|
||||||
GetSystemInfo(&si);
|
GetSystemInfo(&si);
|
||||||
|
|
||||||
const char *machine;
|
|
||||||
switch (si.wProcessorArchitecture) {
|
switch (si.wProcessorArchitecture) {
|
||||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||||
machine = (const char *) "x86_64";
|
buf += "x86_64";
|
||||||
break;
|
break;
|
||||||
case PROCESSOR_ARCHITECTURE_ARM:
|
case PROCESSOR_ARCHITECTURE_ARM:
|
||||||
machine = (const char *) "arm";
|
buf += "arm";
|
||||||
break;
|
break;
|
||||||
case PROCESSOR_ARCHITECTURE_IA64:
|
case PROCESSOR_ARCHITECTURE_IA64:
|
||||||
machine = (const char *) "ia64";
|
buf += "ia64";
|
||||||
break;
|
break;
|
||||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||||
machine = (const char *) "i386";
|
buf += "i386";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
machine = (const char *) "(unknown)";
|
buf += "(unknown)";
|
||||||
}
|
}
|
||||||
snprintf(buf,_INFOBUF_SIZE,"Windows %d.%d (%d) on %s",
|
|
||||||
majorv,minorv,buildv,machine);
|
|
||||||
#else
|
#else
|
||||||
struct utsname ut;
|
struct utsname ut;
|
||||||
uname(&ut);
|
uname(&ut);
|
||||||
snprintf(buf,_INFOBUF_SIZE,"%s %s on %s",
|
buf = fmt::format("{} {} on {}", ut.sysname, ut.release, ut.machine);
|
||||||
ut.sysname, ut.release, ut.machine);
|
|
||||||
#endif
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Info::get_compiler_info()
|
string Info::get_compiler_info()
|
||||||
{
|
{
|
||||||
char *buf = new char[_INFOBUF_SIZE];
|
string buf;
|
||||||
#if __clang__
|
#if __clang__
|
||||||
snprintf(buf,_INFOBUF_SIZE,"Clang C++ %s", __VERSION__);
|
buf = fmt::format("Clang C++ {}", __VERSION__);
|
||||||
#elif __INTEL_COMPILER
|
#elif __INTEL_COMPILER
|
||||||
double version = static_cast<double>(__INTEL_COMPILER)*0.01;
|
double version = static_cast<double>(__INTEL_COMPILER)*0.01;
|
||||||
snprintf(buf,_INFOBUF_SIZE,"Intel C++ %5.2f.%d / %s", version, __INTEL_COMPILER_UPDATE, __VERSION__);
|
buf = fmt::format("Intel C++ {:.2f}.{} / {}", version,
|
||||||
|
__INTEL_COMPILER_UPDATE, __VERSION__);
|
||||||
#elif __GNUC__
|
#elif __GNUC__
|
||||||
snprintf(buf,_INFOBUF_SIZE,"GNU C++ %s", __VERSION__);
|
buf = fmt::format("GNU C++ {}", __VERSION__);
|
||||||
#else
|
#else
|
||||||
snprintf(buf,_INFOBUF_SIZE,"(Unknown)");
|
buf = "(Unknown)";
|
||||||
#endif
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Info::get_openmp_info()
|
string Info::get_openmp_info()
|
||||||
{
|
{
|
||||||
|
|
||||||
#if !defined(_OPENMP)
|
#if !defined(_OPENMP)
|
||||||
return (const char *)"OpenMP not enabled";
|
return "OpenMP not enabled";
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Supported OpenMP version corresponds to the release date of the
|
// Supported OpenMP version corresponds to the release date of the
|
||||||
// specifications as posted at https://www.openmp.org/specifications/
|
// specifications as posted at https://www.openmp.org/specifications/
|
||||||
|
|
||||||
#if _OPENMP > 201811
|
#if _OPENMP > 201811
|
||||||
return (const char *)"OpenMP newer than version 5.0";
|
return "OpenMP newer than version 5.0";
|
||||||
#elif _OPENMP == 201811
|
#elif _OPENMP == 201811
|
||||||
return (const char *)"OpenMP 5.0";
|
return "OpenMP 5.0";
|
||||||
#elif _OPENMP == 201611
|
#elif _OPENMP == 201611
|
||||||
return (const char *)"OpenMP 5.0 preview 1";
|
return "OpenMP 5.0 preview 1";
|
||||||
#elif _OPENMP == 201511
|
#elif _OPENMP == 201511
|
||||||
return (const char *)"OpenMP 4.5";
|
return "OpenMP 4.5";
|
||||||
#elif _OPENMP == 201307
|
#elif _OPENMP == 201307
|
||||||
return (const char *)"OpenMP 4.0";
|
return "OpenMP 4.0";
|
||||||
#elif _OPENMP == 201107
|
#elif _OPENMP == 201107
|
||||||
return (const char *)"OpenMP 3.1";
|
return "OpenMP 3.1";
|
||||||
#elif _OPENMP == 200805
|
#elif _OPENMP == 200805
|
||||||
return (const char *)"OpenMP 3.0";
|
return "OpenMP 3.0";
|
||||||
#elif _OPENMP == 200505
|
#elif _OPENMP == 200505
|
||||||
return (const char *)"OpenMP 2.5";
|
return "OpenMP 2.5";
|
||||||
#elif _OPENMP == 200203
|
#elif _OPENMP == 200203
|
||||||
return (const char *)"OpenMP 2.0";
|
return "OpenMP 2.0";
|
||||||
#else
|
#else
|
||||||
return (const char *)"unknown OpenMP version";
|
return "unknown OpenMP version";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Info::get_mpi_info(int &major, int &minor)
|
string Info::get_mpi_info(int &major, int &minor)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
#if (defined(MPI_VERSION) && (MPI_VERSION > 2)) || defined(MPI_STUBS)
|
#if (defined(MPI_VERSION) && (MPI_VERSION > 2)) || defined(MPI_STUBS)
|
||||||
@ -1264,23 +1261,23 @@ const char *Info::get_mpi_info(int &major, int &minor)
|
|||||||
char *ptr = strchr(version+80,'\n');
|
char *ptr = strchr(version+80,'\n');
|
||||||
if (ptr) *ptr = '\0';
|
if (ptr) *ptr = '\0';
|
||||||
}
|
}
|
||||||
return version;
|
return string(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Info::get_cxx_info()
|
string Info::get_cxx_info()
|
||||||
{
|
{
|
||||||
#if __cplusplus > 201703L
|
#if __cplusplus > 201703L
|
||||||
return (const char *)"newer than C++17";
|
return "newer than C++17";
|
||||||
#elif __cplusplus == 201703L
|
#elif __cplusplus == 201703L
|
||||||
return (const char *)"C++17";
|
return "C++17";
|
||||||
#elif __cplusplus == 201402L
|
#elif __cplusplus == 201402L
|
||||||
return (const char *)"C++14";
|
return "C++14";
|
||||||
#elif __cplusplus == 201103L
|
#elif __cplusplus == 201103L
|
||||||
return (const char *)"C++11";
|
return "C++11";
|
||||||
#elif __cplusplus == 199711L
|
#elif __cplusplus == 199711L
|
||||||
return (const char *)"C++98";
|
return "C++98";
|
||||||
#else
|
#else
|
||||||
return (const char *)"unknown";
|
return "unknown";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
10
src/info.h
10
src/info.h
@ -45,11 +45,11 @@ class Info : protected Pointers {
|
|||||||
static bool has_exceptions();
|
static bool has_exceptions();
|
||||||
static bool has_package(const char * package_name);
|
static bool has_package(const char * package_name);
|
||||||
|
|
||||||
static char *get_os_info();
|
static std::string get_os_info();
|
||||||
static char *get_compiler_info();
|
static std::string get_compiler_info();
|
||||||
static const char *get_openmp_info();
|
static std::string get_openmp_info();
|
||||||
static const char *get_mpi_info(int &, int &);
|
static std::string get_mpi_info(int &, int &);
|
||||||
static const char *get_cxx_info();
|
static std::string get_cxx_info();
|
||||||
|
|
||||||
char **get_variable_names(int &num);
|
char **get_variable_names(int &num);
|
||||||
|
|
||||||
|
|||||||
@ -1238,18 +1238,15 @@ void LAMMPS::print_config(FILE *fp)
|
|||||||
const char *pkg;
|
const char *pkg;
|
||||||
int ncword, ncline = 0;
|
int ncword, ncline = 0;
|
||||||
|
|
||||||
const char *infobuf = Info::get_os_info();
|
fmt::print(fp,"OS: {}\n\n",Info::get_os_info());
|
||||||
fprintf(fp,"OS: %s\n\n",infobuf);
|
|
||||||
delete[] infobuf;
|
|
||||||
|
|
||||||
infobuf = Info::get_compiler_info();
|
fmt::print(fp,"Compiler: {} with {}\nC++ standard: {}\n",
|
||||||
fprintf(fp,"Compiler: %s with %s\n",infobuf,Info::get_openmp_info());
|
Info::get_compiler_info(),Info::get_openmp_info(),
|
||||||
delete[] infobuf;
|
Info::get_cxx_info());
|
||||||
fprintf(fp,"C++ standard: %s\n",Info::get_cxx_info());
|
|
||||||
|
|
||||||
int major,minor;
|
int major,minor;
|
||||||
infobuf = Info::get_mpi_info(major,minor);
|
std::string infobuf = Info::get_mpi_info(major,minor);
|
||||||
fprintf(fp,"MPI v%d.%d: %s\n\n",major,minor,infobuf);
|
fmt::print(fp,"MPI v{}.{}: {}\n\n",major,minor,infobuf);
|
||||||
|
|
||||||
fputs("Active compile time flags:\n\n",fp);
|
fputs("Active compile time flags:\n\n",fp);
|
||||||
if (Info::has_gzip_support()) fputs("-DLAMMPS_GZIP\n",fp);
|
if (Info::has_gzip_support()) fputs("-DLAMMPS_GZIP\n",fp);
|
||||||
@ -1264,11 +1261,13 @@ void LAMMPS::print_config(FILE *fp)
|
|||||||
#else // defined(LAMMPS_SMALLSMALL)
|
#else // defined(LAMMPS_SMALLSMALL)
|
||||||
fputs("-DLAMMPS_SMALLSMALL\n",fp);
|
fputs("-DLAMMPS_SMALLSMALL\n",fp);
|
||||||
#endif
|
#endif
|
||||||
fprintf(fp,"\nsizeof(smallint): %3d-bit\n",(int)sizeof(smallint)*8);
|
|
||||||
fprintf(fp,"sizeof(imageint): %3d-bit\n",(int)sizeof(imageint)*8);
|
|
||||||
fprintf(fp,"sizeof(tagint): %3d-bit\n",(int)sizeof(tagint)*8);
|
|
||||||
fprintf(fp,"sizeof(bigint): %3d-bit\n",(int)sizeof(bigint)*8);
|
|
||||||
|
|
||||||
|
fmt::print(fp,"sizeof(smallint): {}-bit\n"
|
||||||
|
"sizeof(imageint): {}-bit\n"
|
||||||
|
"sizeof(tagint): {}-bit\n"
|
||||||
|
"sizeof(bigint): {}-bit\n",
|
||||||
|
sizeof(smallint)*8, sizeof(imageint)*8,
|
||||||
|
sizeof(tagint)*8, sizeof(bigint)*8);
|
||||||
|
|
||||||
fputs("\nInstalled packages:\n\n",fp);
|
fputs("\nInstalled packages:\n\n",fp);
|
||||||
for (int i = 0; NULL != (pkg = installed_packages[i]); ++i) {
|
for (int i = 0; NULL != (pkg = installed_packages[i]); ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user