Merge branch 'record-compile-flags' of https://github.com/akohlmey/lammps into collected-cmake-changes

This commit is contained in:
Axel Kohlmeyer
2018-06-29 00:09:51 -04:00
11 changed files with 207 additions and 20 deletions

View File

@ -797,6 +797,21 @@ GenerateStyleHeaders(${LAMMPS_STYLE_HEADERS_DIR})
include_directories(${LAMMPS_SOURCE_DIR})
include_directories(${LAMMPS_STYLE_HEADERS_DIR})
######################################
# Generate lmpinstalledpkgs.h
######################################
set(temp "#ifndef LMP_INSTALLED_PKGS_H\n#define LMP_INSTALLED_PKGS_H\n")
set(temp "${temp}const char * LAMMPS_NS::LAMMPS::installed_packages[] = {\n")
foreach(PKG ${DEFAULT_PACKAGES} ${ACCEL_PACKAGES} ${OTHER_PACKAGES})
if(PKG_${PKG})
set(temp "${temp} \"${PKG}\",\n")
endif()
endforeach()
set(temp "${temp} NULL\n};\n#endif\n\n")
message(STATUS "Generating lmpinstalledpkgs.h...")
file(WRITE "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h.tmp" "${temp}" )
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h.tmp" "${LAMMPS_STYLE_HEADERS_DIR}/lmpinstalledpkgs.h")
###########################################
# Actually add executable and lib to build
############################################

View File

@ -209,6 +209,7 @@ class lammps(object):
self.c_bigint = get_ctypes_int(self.extract_setting("bigint"))
self.c_tagint = get_ctypes_int(self.extract_setting("tagint"))
self.c_imageint = get_ctypes_int(self.extract_setting("imageint"))
self._installed_packages = None
# shut-down LAMMPS instance
@ -562,13 +563,36 @@ class lammps(object):
shrinkexceed)
@property
def uses_exceptions(self):
def has_exceptions(self):
""" Return whether the LAMMPS shared library was compiled with C++ exceptions handling enabled """
try:
if self.lib.lammps_has_error:
return True
except(AttributeError):
return False
return self.lib.lammps_config_has_exceptions() != 0
@property
def has_gzip_support(self):
return self.lib.lammps_config_has_gzip_support() != 0
@property
def has_png_support(self):
return self.lib.lammps_config_has_png_support() != 0
@property
def has_jpeg_support(self):
return self.lib.lammps_config_has_jpeg_support() != 0
@property
def has_ffmpeg_support(self):
return self.lib.lammps_config_has_ffmpeg_support() != 0
@property
def installed_packages(self):
if self._installed_packages is None:
self._installed_packages = []
npackages = self.lib.lammps_config_package_count()
sb = create_string_buffer(100)
for idx in range(npackages):
self.lib.lammps_config_package_name(idx, sb, 100)
self._installed_packages.append(sb.value.decode())
return self._installed_packages
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------

1
src/.gitignore vendored
View File

@ -5,6 +5,7 @@
/lmp_*
/style_*.h
/lmpinstalledpkgs.h
/*_gpu.h
/*_gpu.cpp

View File

@ -18,7 +18,7 @@ OBJDIR = Obj_$@
OBJSHDIR = Obj_shared_$@
SRC = $(wildcard *.cpp)
INC = $(wildcard *.h)
INC = $(filter-out lmpinstalledpkgs.h,$(wildcard *.h))
OBJ = $(SRC:.cpp=.o)
SRCLIB = $(filter-out main.cpp,$(SRC))
@ -150,6 +150,21 @@ help:
for file in $$files; do head -1 $$file; done
@echo ''
lmpinstalledpkgs.h: $(SRC) $(INC)
@echo 'Gathering installed package information (may take a little while)'
@echo '#ifndef LMP_INSTALLED_PKGS_H' > lmpinstalledpkgs.tmp
@echo '#define LMP_INSTALLED_PKGS_H' >> lmpinstalledpkgs.tmp
@echo 'const char * LAMMPS_NS::LAMMPS::installed_packages[] = {' >> lmpinstalledpkgs.tmp
@for p in $(PACKAGEUC) $(PACKUSERUC); do info=$$($(SHELL) Package.sh $$p installed); \
[ -n "$$info" ] && echo "\"$$info\"" | sed -e 's/".*package \(.*\)"/"\1",/' >> lmpinstalledpkgs.tmp || :; done
@echo ' NULL };' >> lmpinstalledpkgs.tmp
@echo '#endif' >> lmpinstalledpkgs.tmp
@if [ -f lmpinstalledpkgs.h ]; \
then test "`diff --brief lmpinstalledpkgs.tmp lmpinstalledpkgs.h`" != "" && \
mv lmpinstalledpkgs.tmp lmpinstalledpkgs.h || rm lmpinstalledpkgs.tmp ; \
else mv lmpinstalledpkgs.tmp lmpinstalledpkgs.h ; fi
# Build LAMMPS in one of 4 modes
# exe = exe with static compile in Obj_machine (default)
# shexe = exe with shared compile in Obj_shared_machine
@ -163,6 +178,8 @@ help:
-f MAKE/MACHINES/Makefile.$@ -o -f MAKE/MINE/Makefile.$@
@if [ ! -d $(objdir) ]; then mkdir $(objdir); fi
@$(SHELL) Make.sh style
@$(MAKE) $(MFLAGS) lmpinstalledpkgs.h
@echo 'Compiling LAMMPS for machine $@'
@if [ -f MAKE/MACHINES/Makefile.$@ ]; \
then cp MAKE/MACHINES/Makefile.$@ $(objdir)/Makefile; fi
@if [ -f MAKE/OPTIONS/Makefile.$@ ]; \

View File

@ -16,6 +16,12 @@ style_region.h
style_neigh_bin.h
style_neigh_pair.h
style_neigh_stencil.h
style_nbin.h
style_npair.h
style_nstencil.h
style_ntopo.h
# other auto-generated files
lmpinstalledpkgs.h
# deleted on 4 April 2018
pair_kim_version.h
# deleted on 15 December 2017

View File

@ -259,14 +259,35 @@ void Info::command(int narg, char **arg)
fprintf(out,"Printed on %s\n",ctime(&now));
if (flags & CONFIG) {
fprintf(out,"\nLAMMPS version: %s / %s\n",
fprintf(out,"\nLAMMPS version: %s / %s\n\n",
universe->version, universe->num_ver);
fprintf(out,"sizeof(smallint): %3d-bit\n",(int)sizeof(smallint)*8);
fprintf(out,"sizeof(imageint): %3d-bit\n",(int)sizeof(imageint)*8);
fprintf(out,"sizeof(tagint): %3d-bit\n",(int)sizeof(tagint)*8);
fprintf(out,"sizeof(bigint): %3d-bit\n",(int)sizeof(bigint)*8);
fputs("\nActive compile time flags:\n\n",out);
if (has_gzip_support()) fputs("-DLAMMPS_GZIP\n",out);
if (has_png_support()) fputs("-DLAMMPS_PNG\n",out);
if (has_jpeg_support()) fputs("-DLAMMPS_JPEG\n",out);
if (has_ffmpeg_support()) fputs("-DLAMMPS_FFMPEG\n",out);
if (has_exceptions()) fputs("-DLAMMPS_EXCEPTIONS\n",out);
const char *pkg;
int ncword, ncline = 0;
fputs("\nInstalled packages:\n\n",out);
for (int i = 0; NULL != (pkg = lmp->installed_packages[i]); ++i) {
ncword = strlen(pkg);
if (ncline + ncword > 78) {
ncline = 0;
fputs("\n",out);
}
fprintf(out,"%s ",pkg);
ncline += ncword + 1;
}
fputs("\n",out);
#if defined(_WIN32)
DWORD fullversion,majorv,minorv,buildv=0;
@ -1129,7 +1150,7 @@ static void print_columns(FILE* fp, vector<string> & styles)
}
}
bool Info::has_gzip_support() const {
bool Info::has_gzip_support() {
#ifdef LAMMPS_GZIP
return true;
#else
@ -1137,7 +1158,7 @@ bool Info::has_gzip_support() const {
#endif
}
bool Info::has_png_support() const {
bool Info::has_png_support() {
#ifdef LAMMPS_PNG
return true;
#else
@ -1145,7 +1166,7 @@ bool Info::has_png_support() const {
#endif
}
bool Info::has_jpeg_support() const {
bool Info::has_jpeg_support() {
#ifdef LAMMPS_JPEG
return true;
#else
@ -1153,7 +1174,7 @@ bool Info::has_jpeg_support() const {
#endif
}
bool Info::has_ffmpeg_support() const {
bool Info::has_ffmpeg_support() {
#ifdef LAMMPS_FFMPEG
return true;
#else
@ -1161,7 +1182,7 @@ bool Info::has_ffmpeg_support() const {
#endif
}
bool Info::has_exceptions() const {
bool Info::has_exceptions() {
#ifdef LAMMPS_EXCEPTIONS
return true;
#else
@ -1169,6 +1190,15 @@ bool Info::has_exceptions() const {
#endif
}
bool Info::has_package(const char * package_name) {
for(int i = 0; LAMMPS::installed_packages[i] != NULL; ++i) {
if(strcmp(package_name, LAMMPS::installed_packages[i]) == 0) {
return true;
}
}
return false;
}
/* ---------------------------------------------------------------------- */
char **Info::get_variable_names(int &num) {

View File

@ -33,11 +33,12 @@ class Info : protected Pointers {
bool is_defined(const char *, const char *);
bool is_available(const char *, const char *);
bool has_gzip_support() const;
bool has_png_support() const;
bool has_jpeg_support() const;
bool has_ffmpeg_support() const;
bool has_exceptions() const;
static bool has_gzip_support();
static bool has_png_support();
static bool has_jpeg_support();
static bool has_ffmpeg_support();
static bool has_exceptions();
static bool has_package(const char * package_name);
char **get_variable_names(int &num);

View File

@ -31,6 +31,7 @@
#include "style_region.h"
#include "universe.h"
#include "input.h"
#include "info.h"
#include "atom.h"
#include "update.h"
#include "neighbor.h"
@ -50,6 +51,8 @@
#include "version.h"
#include "error.h"
#include "lmpinstalledpkgs.h"
using namespace LAMMPS_NS;
static void print_style(FILE *fp, const char *str, int &pos);
@ -823,7 +826,9 @@ void LAMMPS::help()
"-var varname value : set index style variable (-v)\n\n",
exename);
fprintf(fp,"List of style options included in this LAMMPS executable\n\n");
print_config(fp);
fprintf(fp,"List of individual style options included in this LAMMPS executable\n\n");
int pos = 80;
fprintf(fp,"* Atom styles:\n");
@ -974,3 +979,28 @@ void print_style(FILE *fp, const char *str, int &pos)
pos += 80;
}
}
void LAMMPS::print_config(FILE *fp)
{
const char *pkg;
int ncword, ncline = 0;
fputs("Active compile time flags:\n\n",fp);
if (Info::has_gzip_support()) fputs("-DLAMMPS_GZIP\n",fp);
if (Info::has_png_support()) fputs("-DLAMMPS_PNG\n",fp);
if (Info::has_jpeg_support()) fputs("-DLAMMPS_JPEG\n",fp);
if (Info::has_ffmpeg_support()) fputs("-DLAMMPS_FFMPEG\n",fp);
if (Info::has_exceptions()) fputs("-DLAMMPS_EXCEPTIONS\n",fp);
fputs("\nInstalled packages:\n\n",fp);
for (int i = 0; NULL != (pkg = installed_packages[i]); ++i) {
ncword = strlen(pkg);
if (ncline + ncword > 78) {
ncline = 0;
fputs("\n",fp);
}
fprintf(fp,"%s ",pkg);
ncline += ncword + 1;
}
fputs("\n\n",fp);
}

View File

@ -59,12 +59,15 @@ class LAMMPS {
class CiteMe *citeme; // citation info
static const char * installed_packages[];
LAMMPS(int, char **, MPI_Comm);
~LAMMPS();
void create();
void post_create();
void init();
void destroy();
void print_config(FILE *); // print compile time settings
private:
void help();

View File

@ -38,6 +38,7 @@
#include "memory.h"
#include "error.h"
#include "force.h"
#include "info.h"
using namespace LAMMPS_NS;
@ -1522,6 +1523,56 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
END_CAPTURE
}
// ----------------------------------------------------------------------
// library API functions for accessing LAMMPS configuration
// ----------------------------------------------------------------------
int lammps_config_has_package(char * package_name) {
return Info::has_package(package_name);
}
int lammps_config_package_count() {
int i = 0;
while(LAMMPS::installed_packages[i] != NULL) {
++i;
}
return i;
}
int lammps_config_package_name(int index, char * buffer, int max_size) {
int i = 0;
while(LAMMPS::installed_packages[i] != NULL && i < index) {
++i;
}
if(LAMMPS::installed_packages[i] != NULL) {
strncpy(buffer, LAMMPS::installed_packages[i], max_size);
return true;
}
return false;
}
int lammps_config_has_gzip_support() {
return Info::has_gzip_support();
}
int lammps_config_has_png_support() {
return Info::has_png_support();
}
int lammps_config_has_jpeg_support() {
return Info::has_jpeg_support();
}
int lammps_config_has_ffmpeg_support() {
return Info::has_ffmpeg_support();
}
int lammps_config_has_exceptions() {
return Info::has_exceptions();
}
// ----------------------------------------------------------------------
// library API functions for error handling
// ----------------------------------------------------------------------

View File

@ -55,6 +55,15 @@ void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
void lammps_scatter_atoms(void *, char *, int, int, void *);
void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
int lammps_config_has_package(char * package_name);
int lammps_config_package_count();
int lammps_config_package_name(int index, char * buffer, int max_size);
int lammps_config_has_gzip_support();
int lammps_config_has_png_support();
int lammps_config_has_jpeg_support();
int lammps_config_has_ffmpeg_support();
int lammps_config_has_exceptions();
// lammps_create_atoms() takes tagint and imageint as args
// ifdef insures they are compatible with rest of LAMMPS
// caller must match to how LAMMPS library is built