diff options
Diffstat (limited to 'lib/sunhpc/commands/soft/gromacs/__init__.py')
-rw-r--r-- | lib/sunhpc/commands/soft/gromacs/__init__.py | 259 |
1 files changed, 142 insertions, 117 deletions
diff --git a/lib/sunhpc/commands/soft/gromacs/__init__.py b/lib/sunhpc/commands/soft/gromacs/__init__.py index 0a02525..1029ef1 100644 --- a/lib/sunhpc/commands/soft/gromacs/__init__.py +++ b/lib/sunhpc/commands/soft/gromacs/__init__.py @@ -7,6 +7,7 @@ #WebSite : https://www.sunhpc.com import os +import re import sys import sunhpc import shutil @@ -16,170 +17,194 @@ class command(sunhpc.commands.soft.command): class Command(command): """ - Build the Gromacs software. + Compilation and installation of the parallel computing software. <arg type="string" name="version"> - Specifies the software version. e.g,, version=2022.6 + Specifies the software version. e.g,, version=x.x.x </arg> + <param type="path" name="source"> + Specifies the software source path. Default: /mnt/usb + </param> + <param type="path" name="prefix"> - Specifies the software install path. - Default: /share/apps/soft/gromacs + Specifies the software install path. Default: /share/apps/soft </param> <param type="path" name="envs"> - Specifies the software env path. - Default: /share/apps/envs + Specifies the environment variable storage path. Default: /share/apps/envs </param> - <param type="path" name="source"> - Specifies the software source path. e.g,, /mnt/usb - Default: /mnt/usb + <param type="Bool" name="serial"> + Enable serial. Default: yes </param> - <param type="Bool" name="mpi"> - Enable mpi. Default: No + Enable MPI. Default: yes </param> - - <param type="Bool" name="cuda"> - Enable cuda. Default: No + <param type="Bool" name="gpu"> + Enable GPU. Default: yes </param> - <example cmd='soft gromacs prefix=/share/apps/soft/gromacs version=2022.6'> - install the gromacs software. + <example cmd='soft mpi prefix=/share/apps/soft/xxx version=x.x.x'> + Build the command line and associated parameters for this software. </example> """ def run(self, params, args): - (prefix, version, source, envs, mpistatus, cudastatus) = self.fillParams([ - ('prefix', '/share/apps/soft/gromacs'), - ('version', None), - ('source', '/mnt/usb'), + (prefix, cudapath, envs, source, version, serial, mpi, gpu) = self.fillParams([ + ('prefix', '/share/apps/soft'), + ('cudapath', '/usr/local/cuda'), ('envs', '/share/apps/envs'), - ('mpi', None), - ('cuda', None), + ('source', '/mnt/usb'), + ('version', None), + ('serial', False), + ('mpi', False), + ('gpu', False), ]) + softname = 'gromacs' + suffname = 'tar.gz' + dirsname = os.path.join(source, 'hpcsoft', 'Gromacs') + verslist = self.getVersions(key=softname, suffix=suffname, dirs=dirsname) + if len(args): version = args[0] if not version: - self.msg('must supply an "Gromacs version" e.g,, version=2022.6, 2023, 2023.2', 'a') + self.msg('must supply an "Version Number", e.g,, version=%s' % '/'.join(verslist), 'a') + + self.create_dirs(prefix, source, envs, version, softname, suffname, dirsname) + + self.build(serial, mpi, gpu, cudapath, envs) + #self.clean() + + def build(self, serial, mpi, gpu, cudapath, envs): + """Start build the software.""" + self.cwd = os.getcwd() + + names = os.listdir(self.tmpdirs) + if self.basename not in names: + self.msg('Unpack the file from the %s to the %s directory.' % (self.filename, self.tmpdirs)) + os.system('tar -xf %s -C %s' % (self.source, self.tmpdirs)) + + build_dirs = os.path.join(self.tmpdirs, self.basename) + os.chdir(build_dirs) + + if serial: + self.build_serial() + + if mpi: + self.build_mpi(envs) + + + # configure envs + self.writeEnvs() + + def build_mpi(self, envs): + self.msg('Starting compile MPI version gromacs...') + + ask_yn = '' + while not ask_yn: + txt = 'The MPI must be loaded before installing the Groamcs mpi version?\n' + txt += '\te.g,, source %s/mpich-xxx, openmpi-xxx' % envs + ask_yn = input('%s: ' % self.message(txt, tag='[+]', end='[n/y]')) + if ask_yn in ['n', 'no']: + sys.exit(0) + + self.preceding() - try: - os.makedirs(prefix) - self.msg("The %s directory does not exist,and it will be created." % prefix, 'w') - except FileExistsError: - pass + cmd = 'cmake .. -DCMAKE_INSTALL_PREFIX=%s ' % self.prefix + cmd += '-DGMX_BUILD_OWN_FFTW=ON ' + cmd += '-DGMX_MPI=ON ' + cmd += '-DREGRESSIONTEST_PATH=%s' % self.regress + os.system(cmd) + os.system('make && make check && make install') + self.clean() + + def build_serial(self): + self.msg('Starting compile serial version gromacs...') + self.preceding() + + cmd = 'cmake .. -DCMAKE_INSTALL_PREFIX=%s ' % self.prefix + cmd += '-DGMX_BUILD_OWN_FFTW=ON ' + cmd += '-DREGRESSIONTEST_PATH=%s' % self.regress + os.system(cmd) + os.system('make && make check && make install') + + def preceding(self): + + # /share/apps/soft/tmpdirs/gromacs/gromacs-2022.6/build + if os.path.exists(self.builder): + shutil.rmtree(self.builder) + + # mkdir build/src/external/build-fftw/fftwBuild-prefix/src + os.makedirs(self.fftwdir) + + # Copy FFTW to src dirs + shutil.copyfile(self.fftwsrc, self.fftwdst) + + # Decompress regressiontests + os.system('tar -xf %s -C %s' % (self.regrsrc, self.builder)) + + os.chdir(self.builder) + + def create_dirs(self, prefix, source, envs, version, softname, suffname, dirsname): + """Create base build directory.""" + + self.basename = '%s-%s' % (softname, version) + self.filename = '%s.%s' % (self.basename, suffname) + + self.prefix = os.path.join(prefix, softname, version) + if not os.path.exists(self.prefix): + os.makedirs(self.prefix) + + self.source = os.path.join(dirsname, self.filename) + if not os.path.exists(self.source): + self.msg('The %s does not exist,please check it.' % self.source, 'a') if not os.path.exists(envs): os.makedirs(envs) + self.envfile = os.path.join(envs, '%s-%s' % (softname, version)) - basename = 'gromacs-%s' % version - filename = '%s.tar.gz' % basename + self.tmpdirs = os.path.join(prefix, 'tmpdirs', softname) + if not os.path.exists(self.tmpdirs): + os.makedirs(self.tmpdirs) - softname = os.path.join(source, 'hpcsoft/Gromacs', filename) - if not os.path.exists(softname): - self.msg('The "%s" not found.' % softname, 'a') + self.builder = os.path.join(self.tmpdirs, self.basename, 'build') - destname = os.path.join(prefix, version) - self.msg('Start decompress the %s software to the /tmp directory...' % basename) - - tmpdir = os.path.join(os.sep, 'tmp', basename) - #if os.path.exists(tmpdir): - # os.system('rm -rf /tmp/%s' % basename) - #os.system('tar -xf %s -C /tmp' % softname) - - # chdir to /tmp/gromacs-version - os.chdir(tmpdir) - cwd = os.getcwd() - - cmake = shutil.which('cmake') - try: - os.makedirs('build/src/external/build-fftw/fftwBuild-prefix/src') - except FileExistsError: - pass - - # copy fftw to src dirs - srcfile = os.path.join(source, 'hpcsoft', 'fftw', 'fftw-3.3.8.tar.gz') - dstfile = 'build/src/external/build-fftw/fftwBuild-prefix/src/fftw-3.3.8.tar.gz' - shutil.copyfile(srcfile, dstfile) - - - regname = 'regressiontests-%s' % version - regfile = os.path.join(source, 'hpcsoft', 'Gromacs', '%s.tar.gz' % regname) - regpath = os.path.join(tmpdir, 'build', regname) - if os.path.exists(regpath): - shutil.rmtree(regpath) - - os.system('tar -xf %s -C build/' % regfile) - os.chdir('build') - - self.build_serial(destname, regname) - if mpistatus: - mpirun = shutil.which('mpirun') - if not mpirun: - self.msg('mpirun command not found.please install an mpirun software.', 'a') - self.build_mpirun(destname, regname) - - if cudastatus: - if not cudapath: - self.msg('must supply an CUDA Path. e.g,, cuda=/usr/local/cuda', 'a') - self.build_nvidia(destname, regname, cudapath) - - - gsenv = os.path.join(envs, '%s-env.sh' % basename) - with open(gsenv, 'w') as f: + self.fftwdir = os.path.join(self.builder, 'src/external/build-fftw/fftwBuild-prefix/src') + self.fftwsrc = os.path.join(source, 'hpcsoft', 'fftw', 'fftw-3.3.8.tar.gz') + self.fftwdst = os.path.join(self.fftwdir, 'fftw-3.3.8.tar.gz') + + self.regrsrc = os.path.join(source, 'hpcsoft', 'Gromacs', 'regressiontests-%s.%s' % (version, suffname)) + self.regress = os.path.join(self.builder, 'regressiontests-%s' % (version)) + + def writeEnvs(self): + with open(self.envfile, 'w') as f: f.write('#!/bin/sh\n') - f.write('#\n# %s env config\n#\n\n' % basename) - f.write('source %s/bin/GMXRC\n' % destname) + f.write('#\n# %s env config\n#\n\n' % self.basename) + f.write('source %s/bin/GMXRC\n' % (self.prefix)) # create shared user and group. self.msg('') self.msg('--------------------------------------------------------') - self.msg('Create a shared group to run the %s software.' % basename) + self.msg('Create a shared group to run the %s software.' % self.basename) self.msg(' 1, groupadd -g 888 public ') self.msg(' 2, usermod -G public dell ') - self.msg(' 3, chown -R root:public %s' % destname)) + self.msg(' 3, chown -R root:public %s' % self.prefix) self.msg('--------------------------------------------------------') self.msg('') - self.msg(' source %s' % gsenv) + self.msg(' source %s' % self.envfile) self.msg('--------------------------------------------------------') - os.system('source %s' % gsenv) - os.system('gmx -version') + def clean(self): + """Clean the install tmp directory.""" + if os.path.exists(self.tmpdirs): + shutil.rmtree(self.tmpdirs) - def build_serial(self, destname, regname): - query = 'cmake .. -DCMAKE_INSTALL_PREFIX=%s ' % destname - query += '-DGMX_BUILD_OWN_FFTW=ON ' - query += '-DREGRESSIONTEST_PATH=%s' % regname - os.system(query) - os.system('make && make check && make install') - - def build_mpirun(self, destname, regname): - query = 'cmake .. -DCMAKE_INSTALL_PREFIX=%s ' % destname - query += '-DGMX_BUILD_OWN_FFTW=ON ' - query += '-DGMX_MPI=ON ' - query += '-DREGRESSIONTEST_PATH=%s' % regname - os.system(query) - os.system('make && make check && make install') - - def build_nvidia(self, destname, regname, cudapath): - query = 'cmake .. -DCMAKE_INSTALL_PREFIX=%s ' % destname - query += '-DGMX_BUILD_OWN_FFTW=ON ' - query += '-DGMX_GPU=CUDA ' # NVIDIA CUDA support enabled - query += '-DCUDA_TOOLKIT_ROOT_DIR=%s' % cudapath - #query += '-DGMX_GPU=OpenCL ' # OpenCL support enabled - #query += '-DGMX_GPU=SYCL ' # using Intel oneAPI DPC++ by default. - #query += '-DGMX_SYCL_HIPSYCL=ON ' - #query += '-DGMX_DOUBLE=on ' - #query += '-DGMX_SIMD=xxx ' # specify the level of SIMD support - #query += '-DBUILD_SHARED_LIBS=off ' - query += '-DREGRESSIONTEST_PATH=%s' % regname - os.system(query) - os.system('make && make check && make install') + |