diff --git a/lib/colvars/Install.py b/lib/colvars/Install.py index 01e70543f..030644ceb 100644 --- a/lib/colvars/Install.py +++ b/lib/colvars/Install.py @@ -1,142 +1,142 @@ #!/usr/bin/env python # Install.py tool to do automate build of Colvars from __future__ import print_function import sys,os,subprocess # help message help = """ Syntax from src dir: make lib-colvars args="-m machine -e suffix" Syntax from lib/colvars dir: python Install.py -m machine -e suffix specify -m and optionally -e, order does not matter -m = delete all existing objects, followed by "make -f Makefile.machine" machine = suffix of a lib/colvars/Makefile.* or of a src/MAKE/MACHINES/Makefile.* file -e = set EXTRAMAKE variable in Makefile.machine to Makefile.lammps.suffix does not alter existing Makefile.machine Examples: make lib-colvars args="-m mpi" # build COLVARS lib with default mpi compiler wrapper """ # print error message or help def error(str=None): if not str: print(help) else: print("ERROR",str) sys.exit() # parse args args = sys.argv[1:] nargs = len(args) if nargs == 0: error() machine = None extraflag = False iarg = 0 while iarg < nargs: if args[iarg] == "-m": if iarg+2 > len(args): error() machine = args[iarg+1] - iarg += 2 + iarg += 2 elif args[iarg] == "-e": if iarg+2 > len(args): error() extraflag = True suffix = args[iarg+1] - iarg += 2 + iarg += 2 else: error() # set lib from working dir cwd = os.getcwd() lib = os.path.basename(cwd) def get_lammps_machine_flags(machine): """Parse Makefile.machine from LAMMPS, return dictionary of compiler flags""" if not os.path.exists("../../src/MAKE/MACHINES/Makefile.%s" % machine): error("Cannot locate src/MAKE/MACHINES/Makefile.%s" % machine) lines = open("../../src/MAKE/MACHINES/Makefile.%s" % machine, 'r').readlines() machine_flags = {} for line in lines: line = line.partition('#')[0] line = line.rstrip() words = line.split() if (len(words) > 2): if ((words[0] == 'CC') or (words[0] == 'CCFLAGS') or (words[0] == 'SHFLAGS') or (words[0] == 'ARCHIVE') or (words[0] == 'ARFLAGS') or (words[0] == 'SHELL')): machine_flags[words[0]] = ' '.join(words[2:]) return machine_flags def gen_colvars_makefile_machine(machine, machine_flags): """Generate Makefile.machine for Colvars given the compiler flags""" machine_makefile = open("Makefile.%s" % machine, 'w') machine_makefile.write('''# -*- makefile -*- to build Colvars module with %s COLVARS_LIB = libcolvars.a COLVARS_OBJ_DIR = CXX = %s CXXFLAGS = %s %s AR = %s ARFLAGS = %s SHELL = %s include Makefile.common .PHONY: default clean default: $(COLVARS_LIB) Makefile.lammps clean: -rm -f $(COLVARS_OBJS) $(COLVARS_LIB) ''' % (machine, machine_flags['CC'], machine_flags['CCFLAGS'], machine_flags['SHFLAGS'] , machine_flags['ARCHIVE'], machine_flags['ARFLAGS'], machine_flags['SHELL'])) if not os.path.exists("Makefile.%s" % machine): machine_flags = get_lammps_machine_flags(machine) gen_colvars_makefile_machine(machine, machine_flags) if not os.path.exists("Makefile.%s" % machine): error("lib/%s/Makefile.%s does not exist" % (lib,machine)) # create Makefile.auto as copy of Makefile.machine # reset EXTRAMAKE if requested lines = open("Makefile.%s" % machine,'r').readlines() fp = open("Makefile.auto",'w') for line in lines: words = line.split() if len(words) == 3 and extraflag and \ words[0] == "EXTRAMAKE" and words[1] == '=': line = line.replace(words[2],"Makefile.lammps.%s" % suffix) fp.write(line) fp.close() # make the library via Makefile.auto optionally with parallel make try: import multiprocessing n_cpus = multiprocessing.cpu_count() except: n_cpus = 1 print("Building lib%s.a ..." % lib) cmd = ["make -f Makefile.auto clean"] print(subprocess.check_output(cmd, shell=True).decode('UTF-8')) cmd = ["make -f Makefile.auto -j%d" % n_cpus] print(subprocess.check_output(cmd, shell=True).decode('UTF-8')) if os.path.exists("lib%s.a" % lib): print("Build was successful") else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib)) if not os.path.exists("Makefile.lammps"): print("lib/%s/Makefile.lammps was NOT created" % lib) diff --git a/lib/gpu/Install.py b/lib/gpu/Install.py index 657f1c8fc..6ea2159de 100644 --- a/lib/gpu/Install.py +++ b/lib/gpu/Install.py @@ -1,159 +1,159 @@ #!/usr/bin/env python # Install.py tool to build the GPU library # used to automate the steps described in the README file in this dir from __future__ import print_function import sys,os,subprocess # help message help = """ Syntax from src dir: make lib-gpu args="-m machine -h hdir -a arch -p precision -e esuffix -m -o osuffix" Syntax from lib dir: python Install.py -m machine -h hdir -a arch -p precision -e esuffix -m -o osuffix specify one or more options, order does not matter -copies an existing Makefile.machine in lib/gpu to Makefile.auto +copies an existing Makefile.machine in lib/gpu to Makefile.auto optionally edits these variables in Makefile.auto: CUDA_HOME, CUDA_ARCH, CUDA_PRECISION, EXTRAMAKE optionally uses Makefile.auto to build the GPU library -> libgpu.a and to copy a Makefile.lammps.esuffix -> Makefile.lammps optionally copies Makefile.auto to a new Makefile.osuffix -m = use Makefile.machine as starting point, copy to Makefile.auto default machine = linux -h = set CUDA_HOME variable in Makefile.auto to hdir hdir = path to NVIDIA Cuda software, e.g. /usr/local/cuda -a = set CUDA_ARCH variable in Makefile.auto to arch - use arch = 20 for Tesla C2050/C2070 (Fermi) (deprecated as of CUDA 8.0) + use arch = 20 for Tesla C2050/C2070 (Fermi) (deprecated as of CUDA 8.0) or GeForce GTX 580 or similar use arch = 30 for Tesla K10 (Kepler) use arch = 35 for Tesla K40 (Kepler) or GeForce GTX Titan or similar use arch = 37 for Tesla dual K80 (Kepler) use arch = 60 for Tesla P100 (Pascal) -p = set CUDA_PRECISION variable in Makefile.auto to precision use precision = double or mixed or single -e = set EXTRAMAKE variable in Makefile.auto to Makefile.lammps.esuffix -b = make the GPU library using Makefile.auto first performs a "make clean" then produces libgpu.a if successful also copies EXTRAMAKE file -> Makefile.lammps -e can set which Makefile.lammps.esuffix file is copied -o = copy final Makefile.auto to Makefile.osuffix Examples: make lib-gpu args="-b" # build GPU lib with default Makefile.linux make lib-gpu args="-m xk7 -p single -o xk7.single" # create new Makefile.xk7.single, altered for single-precision make lib-gpu args="-m mpi -a 35 -p single -o mpi.mixed -b" # create new Makefile.mpi.mixed, also build GPU lib with these settings """ # print error message or help def error(str=None): if not str: print(help) else: print("ERROR",str) sys.exit() # parse args args = sys.argv[1:] nargs = len(args) if nargs == 0: error() isuffix = "linux" hflag = aflag = pflag = eflag = 0 makeflag = 0 outflag = 0 iarg = 0 while iarg < nargs: if args[iarg] == "-m": if iarg+2 > nargs: error() isuffix = args[iarg+1] iarg += 2 elif args[iarg] == "-h": if iarg+2 > nargs: error() hflag = 1 hdir = args[iarg+1] iarg += 2 elif args[iarg] == "-a": if iarg+2 > nargs: error() aflag = 1 arch = args[iarg+1] iarg += 2 elif args[iarg] == "-p": if iarg+2 > nargs: error() pflag = 1 precision = args[iarg+1] iarg += 2 elif args[iarg] == "-e": if iarg+2 > nargs: error() eflag = 1 lmpsuffix = args[iarg+1] iarg += 2 elif args[iarg] == "-b": makeflag = 1 iarg += 1 elif args[iarg] == "-o": if iarg+2 > nargs: error() outflag = 1 osuffix = args[iarg+1] iarg += 2 else: error() if pflag: if precision == "double": precstr = "-D_DOUBLE_DOUBLE" elif precision == "mixed": precstr = "-D_SINGLE_DOUBLE" elif precision == "single": precstr = "-D_SINGLE_SINGLE" else: error("Invalid precision setting") - + # create Makefile.auto # reset EXTRAMAKE, CUDA_HOME, CUDA_ARCH, CUDA_PRECISION if requested - + if not os.path.exists("Makefile.%s" % isuffix): error("lib/gpu/Makefile.%s does not exist" % isuffix) lines = open("Makefile.%s" % isuffix,'r').readlines() fp = open("Makefile.auto",'w') for line in lines: words = line.split() if len(words) != 3: fp.write(line) continue if hflag and words[0] == "CUDA_HOME" and words[1] == '=': line = line.replace(words[2],hdir) if aflag and words[0] == "CUDA_ARCH" and words[1] == '=': line = line.replace(words[2],"-arch=sm_%s" % arch) if pflag and words[0] == "CUDA_PRECISION" and words[1] == '=': line = line.replace(words[2],precstr) if eflag and words[0] == "EXTRAMAKE" and words[1] == '=': line = line.replace(words[2],"Makefile.lammps.%s" % lmpsuffix) fp.write(line) fp.close() # perform make # make operations copies EXTRAMAKE file to Makefile.lammps if makeflag: print("Building libgpu.a ...") cmd = "rm -f libgpu.a" subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) cmd = "make -f Makefile.auto clean; make -f Makefile.auto" txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print(txt.decode('UTF-8')) if not os.path.exists("libgpu.a"): error("Build of lib/gpu/libgpu.a was NOT successful") if not os.path.exists("Makefile.lammps"): error("lib/gpu/Makefile.lammps was NOT created") # copy new Makefile.auto to Makefile.osuffix if outflag: print("Creating new Makefile.%s" % osuffix) cmd = "cp Makefile.auto Makefile.%s" % osuffix subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)