Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
documentation:build:lammps [2018/02/14 19:27] frey |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Build from source: LAMMPS ====== | ||
- | |||
- | Start by setting-up a properly-versioned directory hierarchy for LAMMPS builds. For example: | ||
- | |||
- | <code bash> | ||
- | $ mkdir -p ~/sw/lammps | ||
- | $ cd ~/sw/lammps | ||
- | $ mkdir attic | ||
- | </code> | ||
- | |||
- | The ''attic'' directory is used to hold downloaded source packages, etc. I can download the latest LAMMPS stable source by visiting the [[http://lammps.sandia.gov/download.html|official downloads page]] and getting a "tarball" of the latest stable release. This usually downloads as ''lammps-stable.tar.gz'' which is slightly annoying because it doesn't cite the release date (so every release you download uses the same filename). When I upload the source to ''~/sw/lammps/attic'' I rename it: at the time of writing, the stable release is 11 August 2017, so I rename the file ''lammps-20170811.tar.gz'' to make that clear: | ||
- | |||
- | <code bash> | ||
- | $ cd ~/sw/lammps | ||
- | $ ls -l attic | ||
- | total 117944 | ||
- | -rw-r--r-- 1 frey cadmin 120774006 2018-02-14 13:42 lammps-20170811.tar.gz | ||
- | </code> | ||
- | |||
- | Create a directory to hold the new version you are building. The name should include the release (version or date, etc.) and any special features worth mentioning. In this case, we'll be building the 11 August 2017 release without any special features: | ||
- | |||
- | <code bash> | ||
- | $ cd ~/sw/lammps | ||
- | $ mkdir 20170811 | ||
- | $ ls -l | ||
- | total 0 | ||
- | drwxr-xr-x 2 frey cadmin 6 2018-02-14 13:45 20170811 | ||
- | drwxr-xr-x 2 frey cadmin 35 2018-02-14 13:42 attic | ||
- | </code> | ||
- | |||
- | Next, unpack the source code inside the version directory just created: | ||
- | |||
- | <code bash> | ||
- | $ cd 20170811 | ||
- | $ tar -zxf ../attic/lammps-20170811.tar.gz | ||
- | $ ls -l | ||
- | total 0 | ||
- | drwxr-xr-x 10 frey cadmin 132 2017-08-11 14:19 lammps-11Aug17 | ||
- | </code> | ||
- | |||
- | The directory structure we promote will have all the executables, libraries, etc. installed in the ''20170811'' directory; I typically rename the source code directory ''src'' rather than whatever name the program author(s) used: | ||
- | |||
- | <code bash> | ||
- | $ mv lammps-11Aug17 src | ||
- | $ cd src | ||
- | $ ls -l | ||
- | total 100 | ||
- | drwxr-xr-x 5 frey cadmin 4096 2017-08-11 14:18 bench | ||
- | drwxr-xr-x 5 frey cadmin 104 2017-08-11 14:23 doc | ||
- | drwxr-xr-x 60 frey cadmin 4096 2017-08-11 14:18 examples | ||
- | drwxr-xr-x 23 frey cadmin 4096 2017-08-11 14:18 lib | ||
- | -rw-r--r-- 1 frey cadmin 17775 2017-07-24 10:58 LICENSE | ||
- | drwxr-xr-x 2 frey cadmin 4096 2017-08-11 14:18 potentials | ||
- | drwxr-xr-x 3 frey cadmin 84 2017-08-11 14:18 python | ||
- | -rw-r--r-- 1 frey cadmin 1690 2011-09-23 19:48 README | ||
- | drwxr-xr-x 66 frey cadmin 32768 2017-08-11 14:23 src | ||
- | drwxr-xr-x 28 frey cadmin 4096 2017-08-11 14:19 tools | ||
- | </code> | ||
- | |||
- | ===== Basic build configuration ===== | ||
- | |||
- | LAMMPS makes use of the Unix //make// command to manage the transformation of its source code into executables and libraries. There is no automated configuration or generation of a Makefile a'la GNU autoconf or CMake. Instead, a Makefile template is copied and edited by hand for each build variant: | ||
- | |||
- | <code bash> | ||
- | $ cd src | ||
- | $ ls -l MAKE | ||
- | total 24 | ||
- | drwxr-xr-x 2 frey cadmin 4096 2017-08-11 14:18 MACHINES | ||
- | -rw-r--r-- 1 frey cadmin 2972 2016-05-12 09:54 Makefile.mpi | ||
- | -rw-r--r-- 1 frey cadmin 2960 2016-05-12 09:54 Makefile.serial | ||
- | drwxr-xr-x 2 frey cadmin 6 2017-08-11 14:18 MINE | ||
- | drwxr-xr-x 2 frey cadmin 4096 2017-08-11 14:18 OPTIONS | ||
- | -rw-r--r-- 1 frey cadmin 4797 2016-04-26 15:38 README | ||
- | </code> | ||
- | |||
- | For a simple serial build using GNU compilers (''g++'') nothing needs to be done: the ''Makefile.serial'' can be used as-is. The suffix ''serial'' is a //machine// identifier in the LAMMPS build system. Assuming I have GNU compilers setup in my environment, the build is as simple as: | ||
- | |||
- | <code bash> | ||
- | $ which g++ | ||
- | /usr/bin/g++ | ||
- | $ make serial | ||
- | : | ||
- | </code> | ||
- | |||
- | Quite a bit of information is displayed as the build proceeds: compilation commands for each individual source file, navigation through the source directory, and warning/error messages the compiler(s) may generate. A successful build will end with a summary line: | ||
- | |||
- | <code bash> | ||
- | : | ||
- | text data bss dec hex filename | ||
- | 5722883 7744 968 5731595 57750b ../lmp_serial | ||
- | make[1]: Leaving directory `/data/home/frey/sw/lammps/20170811/src/src/Obj_serial' | ||
- | </code> | ||
- | |||
- | All of the intermediate object code files and the completed executable are found in the ''Obj_serial'' directory (if you're keeping track, that's ''~/sw/lammps/20170811/src/src/Obj_serial''). That directory name consists of the prefix ''Obj_'' and the LAMMPS //machine// name that was built. The executable itself is named ''lmp_«machine»'' and is in the ''src'' directory itself (where you issued the ''make'' command). | ||
- | |||
- | <WRAP center round tip 60%> | ||
- | Since each build saves intermediate files and products in a separate directory, it is possible to build multiple variants of LAMMPS from the same source directory. If you create your own ''Makefile.«machine»'' just be sure to use a different //machine// name for each variant. | ||
- | </WRAP> | ||
- | |||
- | The final task is to finish setting-up the ''20170811'' directory where we have the source code. At this point we've produced an executable, so it should be made available in a ''bin'' directory: | ||
- | |||
- | <code bash> | ||
- | $ cd ~/sw/lammps/20170811 | ||
- | $ mkdir -p bin | ||
- | $ cd bin | ||
- | $ cp ../src/src/lmp_serial lammps | ||
- | $ ls -l | ||
- | total 23956 | ||
- | -rwxr-xr-x 1 frey cadmin 24529796 2018-02-14 14:24 lammps | ||
- | $ ldd lammps | ||
- | linux-vdso.so.1 => (0x00007fffa38d6000) | ||
- | libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f8bf6eca000) | ||
- | libm.so.6 => /lib64/libm.so.6 (0x00007f8bf6c74000) | ||
- | libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f8bf6a5d000) | ||
- | libc.so.6 => /lib64/libc.so.6 (0x00007f8bf66ff000) | ||
- | /lib64/ld-linux-x86-64.so.2 (0x00007f8bf71d5000) | ||
- | </code> | ||
- | |||
- | In essence, you installed a copy of the finished executable in the ''bin'' directory; if you make changes to the build, they may affect the ''lmp_serial'' executable down in the ''src/src'' directory, but they won't affect your working executable until you do another such ''cp''. | ||
- | |||
- | <WRAP center round help 60%> | ||
- | The ''ldd'' command shows what shared libraries an executable requires in order to run. If the right-hand side says that the library is not found, then you probably forgot to load a VALET package into your environment (e.g. setup ''LD_LIBRARY_PATH''). | ||
- | </WRAP> | ||
- | |||