From d75bf01b2d599c489a7640706b04369c5510c05b Mon Sep 17 00:00:00 2001 From: exapde Date: Sun, 20 Nov 2022 14:13:51 -0500 Subject: [PATCH] create Makefile for ML-POD --- cmake/CMakeLists.txt | 4 -- lib/mlpod/Install.py | 97 +++++++++++++++++++++++++++++ lib/mlpod/Makefile.lammps.empty | 5 ++ lib/mlpod/Makefile.lammps.installed | 5 ++ lib/mlpod/Makefile.lammps.linalg | 5 ++ lib/mlpod/Makefile.mpi | 48 ++++++++++++++ lib/mlpod/Makefile.serial | 48 ++++++++++++++ 7 files changed, 208 insertions(+), 4 deletions(-) create mode 100644 lib/mlpod/Install.py create mode 100644 lib/mlpod/Makefile.lammps.empty create mode 100644 lib/mlpod/Makefile.lammps.installed create mode 100644 lib/mlpod/Makefile.lammps.linalg create mode 100644 lib/mlpod/Makefile.mpi create mode 100644 lib/mlpod/Makefile.serial diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d5ce4c5895..c831b46120 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -630,10 +630,6 @@ foreach(PKG_LIB POEMS ATC AWPMD H5MD MESONT) endif() endforeach() -if(PKG_ELECTRODE) - target_link_libraries(lammps PRIVATE ${LAPACK_LIBRARIES}) -endif() - if(PKG_ELECTRODE OR PKG_ML-POD) target_link_libraries(lammps PRIVATE ${LAPACK_LIBRARIES}) endif() diff --git a/lib/mlpod/Install.py b/lib/mlpod/Install.py new file mode 100644 index 0000000000..0a0979c2ee --- /dev/null +++ b/lib/mlpod/Install.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python + +""" +Install.py tool to do a generic build of a library +soft linked to by many of the lib/Install.py files +used to automate the steps described in the corresponding lib/README +""" + +from __future__ import print_function +import sys, os, subprocess +from argparse import ArgumentParser + +sys.path.append('..') +from install_helpers import get_cpus, fullpath + +parser = ArgumentParser(prog='Install.py', + description="LAMMPS library build wrapper script") + +HELP = """ +Syntax from src dir: make lib-libname args="-m machine -e suffix" +Syntax from lib dir: python Install.py -m machine -e suffix + +libname = name of lib dir (e.g. atc, h5md, meam, poems, etc) +specify -m and optionally -e, order does not matter + +Examples: + +make lib-poems args="-m serial" # build POEMS lib with same settings as in the serial Makefile in src +make lib-colvars args="-m mpi" # build COLVARS lib with same settings as in the mpi Makefile in src +make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (using Intel Fortran) +""" + +# parse and process arguments + +parser.add_argument("-m", "--machine", + help="suffix of a /Makefile.* file used for compiling this library") +parser.add_argument("-e", "--extramake", + help="set EXTRAMAKE variable in /Makefile. to Makefile.lammps.") + +args = parser.parse_args() + +# print help message and exit, if neither build nor path options are given +if not args.machine and not args.extramake: + parser.print_help() + sys.exit(HELP) + +machine = args.machine +extraflag = args.extramake +if extraflag: + suffix = args.extramake +else: + suffix = 'empty' + +# set lib from working dir + +cwd = fullpath('.') +lib = os.path.basename(cwd) + +# create Makefile.auto as copy of Makefile.machine +# reset EXTRAMAKE if requested + +if not os.path.exists("Makefile.%s" % machine): + sys.exit("lib/%s/Makefile.%s does not exist" % (lib, machine)) + +lines = open("Makefile.%s" % machine, 'r').readlines() +fp = open("Makefile.auto", 'w') + +has_extramake = False +for line in lines: + words = line.split() + if len(words) == 3 and words[0] == "EXTRAMAKE" and words[1] == '=': + has_extramake = True + if extraflag: + line = line.replace(words[2], "Makefile.lammps.%s" % suffix) + fp.write(line) + +fp.close() + +# make the library via Makefile.auto optionally with parallel make +n_cpus = get_cpus() + +print("Building lib%s.a ..." % lib) +cmd = "make -f Makefile.auto clean; make -f Makefile.auto -j%d" % n_cpus +try: + txt = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) + print(txt.decode('UTF-8')) +except subprocess.CalledProcessError as e: + print("Make failed with:\n %s" % e.output.decode('UTF-8')) + sys.exit(1) + +if os.path.exists("lib%s.a" % lib): + print("Build was successful") +else: + sys.exit("Build of lib/%s/lib%s.a was NOT successful" % (lib, lib)) + +if has_extramake and not os.path.exists("Makefile.lammps"): + print("WARNING: lib/%s/Makefile.lammps was NOT created" % lib) diff --git a/lib/mlpod/Makefile.lammps.empty b/lib/mlpod/Makefile.lammps.empty new file mode 100644 index 0000000000..bf467a20c3 --- /dev/null +++ b/lib/mlpod/Makefile.lammps.empty @@ -0,0 +1,5 @@ +# Settings that the LAMMPS build will import when this package library is used + +mlpod_SYSINC = +mlpod_SYSLIB = +mlpod_SYSPATH = diff --git a/lib/mlpod/Makefile.lammps.installed b/lib/mlpod/Makefile.lammps.installed new file mode 100644 index 0000000000..d8b0d41225 --- /dev/null +++ b/lib/mlpod/Makefile.lammps.installed @@ -0,0 +1,5 @@ +# Settings that the LAMMPS build will import when this package library is used + +mlpod_SYSINC = +mlpod_SYSLIB = -lblas -llapack +mlpod_SYSPATH = diff --git a/lib/mlpod/Makefile.lammps.linalg b/lib/mlpod/Makefile.lammps.linalg new file mode 100644 index 0000000000..cb4d78df99 --- /dev/null +++ b/lib/mlpod/Makefile.lammps.linalg @@ -0,0 +1,5 @@ +# Settings that the LAMMPS build will import when this package library is used + +mlpod_SYSINC = +mlpod_SYSLIB = -llinalg -lgfortran +mlpod_SYSPATH = -L../../lib/linalg$(LIBOBJDIR) diff --git a/lib/mlpod/Makefile.mpi b/lib/mlpod/Makefile.mpi new file mode 100644 index 0000000000..05b6ee642a --- /dev/null +++ b/lib/mlpod/Makefile.mpi @@ -0,0 +1,48 @@ +SHELL = /bin/sh + +# which file will be copied to Makefile.lammps + +EXTRAMAKE = Makefile.lammps.linalg + +# ------ DEFINITIONS ------ + +LIB = libmlpod.a +OBJ = $(SRC:.cpp=.o) + +# ------ SETTINGS ------ + +# include any MPI settings needed for the ELECTRODE library to build with +# the same MPI library that LAMMPS is built with + +CC = mpicxx +CCFLAGS = -O3 -fPIC -DMPICH_IGNORE_CXX_SEEK -DOMPI_SKIP_MPICXX=1 + +ARCHIVE = ar +ARCHFLAG = -rc +DEPFLAGS = -M +#LINK = +#LINKFLAGS = +USRLIB = +SYSLIB = + +# ------ MAKE PROCEDURE ------ + +lib: $(OBJ) + $(ARCHIVE) $(ARFLAGS) $(LIB) $(OBJ) + @cp $(EXTRAMAKE) Makefile.lammps + +# ------ COMPILE RULES ------ + +%.o:%.cpp + $(CC) $(CCFLAGS) -c $< -o $@ +%.d:%.cpp + $(CC) $(CCFLAGS) $(DEPFLAGS) $< > $@ + +# ------ DEPENDENCIES ------ + +DEPENDS = $(OBJ:.o=.d) + +# ------ CLEAN ------ + +clean: + -rm -f *.d *~ $(OBJ) $(LIB) diff --git a/lib/mlpod/Makefile.serial b/lib/mlpod/Makefile.serial new file mode 100644 index 0000000000..54e819ee38 --- /dev/null +++ b/lib/mlpod/Makefile.serial @@ -0,0 +1,48 @@ +SHELL = /bin/sh + +# which file will be copied to Makefile.lammps + +EXTRAMAKE = Makefile.lammps.linalg + +# ------ DEFINITIONS ------ + +LIB = libmlpod.a +OBJ = $(SRC:.cpp=.o) + +# ------ SETTINGS ------ + +# include any MPI settings needed for the mlpod library to build with +# the same MPI library that LAMMPS is built with + +CC = g++ +CCFLAGS = -O3 -fPIC -I../../src/STUBS + +ARCHIVE = ar +ARCHFLAG = -rc +DEPFLAGS = -M +#LINK = +#LINKFLAGS = +USRLIB = +SYSLIB = + +# ------ MAKE PROCEDURE ------ + +lib: $(OBJ) + $(ARCHIVE) $(ARFLAGS) $(LIB) $(OBJ) + @cp $(EXTRAMAKE) Makefile.lammps + +# ------ COMPILE RULES ------ + +%.o:%.cpp + $(CC) $(CCFLAGS) -c $< -o $@ +%.d:%.cpp + $(CC) $(CCFLAGS) $(DEPFLAGS) $< > $@ + +# ------ DEPENDENCIES ------ + +DEPENDS = $(OBJ:.o=.d) + +# ------ CLEAN ------ + +clean: + -rm -f *.d *~ $(OBJ) $(LIB)